From a178a82fef100290936ab497cde9a3f716aa99cd Mon Sep 17 00:00:00 2001 From: rkfg Date: Sun, 18 Sep 2022 15:47:46 +0300 Subject: [PATCH] Add color option --- README.md | 7 +++++++ config/config.go | 13 ++++++++++++- config/default.go | 7 +++++++ ui/views/channels.go | 7 ++++++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2666935..b2280de 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,13 @@ columns = [ # "NUPD", # number of channel updates ] +[views.channels.options] +# Currently only one option for the AGE column. If enabled, uses multiple colors +# from green to orange to indicate the channel age using 256 color scheme in +# supported terminals + +# AGE = { color = "color" } + [views.transactions] # It is possible to add, remove and order columns of the # table with the array columns. The available values are: diff --git a/config/config.go b/config/config.go index f87deec..3753009 100644 --- a/config/config.go +++ b/config/config.go @@ -42,8 +42,19 @@ type Views struct { Routing *View `toml:"routing"` } +type ColumnOptions map[string]map[string]string + type View struct { - Columns []string `toml:"columns"` + Columns []string `toml:"columns"` + Options ColumnOptions `toml:"options"` +} + +func (co ColumnOptions) GetOption(columnName, option string) string { + if o, ok := co[columnName]; !ok { + return "" + } else { + return o[option] + } } type Aliases map[string]string diff --git a/config/default.go b/config/default.go index 0fafa7f..f69c89e 100644 --- a/config/default.go +++ b/config/default.go @@ -50,6 +50,13 @@ columns = [ # "NUPD", # number of channel updates ] +[views.channels.options] +# Currently only one option for the AGE column. If enabled, uses multiple colors +# from green to orange to indicate the channel age using 256 color scheme in +# supported terminals + +# AGE = { color = "color" } + [views.transactions] # It is possible to add, remove and order columns of the # table with the array columns. The available values are: diff --git a/ui/views/channels.go b/ui/views/channels.go index 0c14805..cf6fc56 100644 --- a/ui/views/channels.go +++ b/ui/views/channels.go @@ -651,7 +651,12 @@ func NewChannels(cfg *config.View, chans *models.Channels) *Channels { if c.ID == 0 { return fmt.Sprintf("%10s", "") } - return ColorizeAge(c.Age, printer.Sprintf("%10s", FormatAge(c.Age)), opts...) + result := printer.Sprintf("%10s", FormatAge(c.Age)) + if cfg.Options.GetOption("AGE", "color") == "color" { + return ColorizeAge(c.Age, result, opts...) + } else { + return color.White(opts...)(result) + } }, }