diff --git a/docs/reference/config.md b/docs/reference/config.md index 25cd516f..bc1d02b4 100644 --- a/docs/reference/config.md +++ b/docs/reference/config.md @@ -53,6 +53,17 @@ ledger_cli: ledger # OPTIONAL, DEFAULT: INR default_currency: INR +# The precision to show in UI. NOTE: This applies only to the UI, not +# to the entries in journal. +# +# OPTIONAL, DEFAULT: 0 +display_precision: 0 + +# The column to align the amount in the editor. +# +# OPTIONAL, DEFAULT: 52 +amount_alignment_column: 52 + # The locale used to format numbers. The list of locales supported # depends on your browser. It's known to work well with en-US and en-IN. # diff --git a/internal/config/config.go b/internal/config/config.go index 10441e02..5f93ee8d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -122,6 +122,7 @@ type Config struct { LedgerCli string `json:"ledger_cli" yaml:"ledger_cli"` DefaultCurrency string `json:"default_currency" yaml:"default_currency"` DisplayPrecision int `json:"display_precision" yaml:"display_precision"` + AmountAlignmentColumn int `json:"amount_alignment_column" yaml:"amount_alignment_column"` Locale string `json:"locale" yaml:"locale"` FinancialYearStartingMonth time.Month `json:"financial_year_starting_month" yaml:"financial_year_starting_month"` WeekStartingDay time.Weekday `json:"week_starting_day" yaml:"week_starting_day"` @@ -152,6 +153,7 @@ var defaultConfig = Config{ LedgerCli: "ledger", DefaultCurrency: "INR", DisplayPrecision: 0, + AmountAlignmentColumn: 52, Locale: "en-IN", Budget: Budget{Rollover: Yes}, FinancialYearStartingMonth: 4, diff --git a/internal/config/schema.json b/internal/config/schema.json index b37cea06..8d988aa0 100644 --- a/internal/config/schema.json +++ b/internal/config/schema.json @@ -33,6 +33,12 @@ "maximum": 4, "description": "The precision to show in UI. NOTE: This applies only to the UI, not to the entries in journal." }, + "amount_alignment_column": { + "type": "integer", + "minimum": 40, + "maximum": 100, + "description": "The column to align the amount in the editor." + }, "locale": { "type": "string", "pattern": "^[a-z]{2}-[A-Z]{2}$", diff --git a/src/app.d.ts b/src/app.d.ts index 4a6289e1..9e04afda 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -33,6 +33,7 @@ interface UserConfig { display_precision: number; db_path: string; financial_year_starting_month: number; + amount_alignment_column: number; week_starting_day: number; goals: Record>; accounts: { diff --git a/src/lib/journal.ts b/src/lib/journal.ts index 165c60e2..fa7e2169 100644 --- a/src/lib/journal.ts +++ b/src/lib/journal.ts @@ -24,6 +24,10 @@ const DATE = /^\d{4}[/-]\d{2}[/-]\d{2}/; // https://ledger-cli.org/doc/ledger3.html#Journal-Format function formatLine(line: string, state: State) { + let amountAlignmentColumn = 52; + if (typeof USER_CONFIG !== "undefined") { + amountAlignmentColumn = USER_CONFIG.amount_alignment_column; + } if (line.match(DATE) || line.match(/^[~=]/)) { state.inTransaction = true; return line; @@ -42,11 +46,11 @@ function formatLine(line: string, state: State) { ); if (fullMatch) { const { account, prefix, amount, suffix } = fullMatch.groups; - if (account.length + prefix.length + amount.length <= 46) { + if (account.length + prefix.length + amount.length <= amountAlignmentColumn - 6) { return ( space(4) + account + - space(48 - account.length - prefix.length - amount.length) + + space(amountAlignmentColumn - 4 - account.length - prefix.length - amount.length) + prefix + amount + suffix diff --git a/tests/fixture/eur-hledger/config.json b/tests/fixture/eur-hledger/config.json index 9867b851..d5860bf3 100644 --- a/tests/fixture/eur-hledger/config.json +++ b/tests/fixture/eur-hledger/config.json @@ -11,6 +11,7 @@ "ledger_cli": "hledger", "default_currency": "EUR", "display_precision": 0, + "amount_alignment_column": 52, "locale": "es-EU", "financial_year_starting_month": 4, "week_starting_day": 0, @@ -115,6 +116,12 @@ ], "type": "array" }, + "amount_alignment_column": { + "description": "The column to align the amount in the editor.", + "maximum": 100, + "minimum": 40, + "type": "integer" + }, "budget": { "additionalProperties": false, "description": "Budget configuration", diff --git a/tests/fixture/eur/config.json b/tests/fixture/eur/config.json index e609fec0..71584d77 100644 --- a/tests/fixture/eur/config.json +++ b/tests/fixture/eur/config.json @@ -11,6 +11,7 @@ "ledger_cli": "ledger", "default_currency": "EUR", "display_precision": 0, + "amount_alignment_column": 52, "locale": "es-EU", "financial_year_starting_month": 4, "week_starting_day": 0, @@ -115,6 +116,12 @@ ], "type": "array" }, + "amount_alignment_column": { + "description": "The column to align the amount in the editor.", + "maximum": 100, + "minimum": 40, + "type": "integer" + }, "budget": { "additionalProperties": false, "description": "Budget configuration", diff --git a/tests/fixture/inr-beancount/config.json b/tests/fixture/inr-beancount/config.json index e8458f1b..b1cba277 100644 --- a/tests/fixture/inr-beancount/config.json +++ b/tests/fixture/inr-beancount/config.json @@ -19,6 +19,7 @@ "ledger_cli": "beancount", "default_currency": "INR", "display_precision": 0, + "amount_alignment_column": 52, "locale": "en-IN", "financial_year_starting_month": 4, "week_starting_day": 0, @@ -123,6 +124,12 @@ ], "type": "array" }, + "amount_alignment_column": { + "description": "The column to align the amount in the editor.", + "maximum": 100, + "minimum": 40, + "type": "integer" + }, "budget": { "additionalProperties": false, "description": "Budget configuration", diff --git a/tests/fixture/inr-hledger/config.json b/tests/fixture/inr-hledger/config.json index e1d89749..80d56e99 100644 --- a/tests/fixture/inr-hledger/config.json +++ b/tests/fixture/inr-hledger/config.json @@ -18,6 +18,7 @@ "ledger_cli": "hledger", "default_currency": "INR", "display_precision": 0, + "amount_alignment_column": 52, "locale": "en-IN", "financial_year_starting_month": 4, "week_starting_day": 0, @@ -122,6 +123,12 @@ ], "type": "array" }, + "amount_alignment_column": { + "description": "The column to align the amount in the editor.", + "maximum": 100, + "minimum": 40, + "type": "integer" + }, "budget": { "additionalProperties": false, "description": "Budget configuration", diff --git a/tests/fixture/inr/config.json b/tests/fixture/inr/config.json index fec4dab6..f92fa7d8 100644 --- a/tests/fixture/inr/config.json +++ b/tests/fixture/inr/config.json @@ -18,6 +18,7 @@ "ledger_cli": "ledger", "default_currency": "INR", "display_precision": 0, + "amount_alignment_column": 52, "locale": "en-IN", "financial_year_starting_month": 4, "week_starting_day": 0, @@ -122,6 +123,12 @@ ], "type": "array" }, + "amount_alignment_column": { + "description": "The column to align the amount in the editor.", + "maximum": 100, + "minimum": 40, + "type": "integer" + }, "budget": { "additionalProperties": false, "description": "Budget configuration",