make amount_alignment_column configurable

This commit is contained in:
Anantha Kumaran 2024-01-23 19:08:20 +05:30
parent 8c6bdc9864
commit d6f9ec368f
10 changed files with 61 additions and 2 deletions

View File

@ -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.
#

View File

@ -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,

View File

@ -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}$",

1
src/app.d.ts vendored
View File

@ -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<string, Array<GoalSummary>>;
accounts: {

View File

@ -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

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",