From fd1ae8bac3d225da568c46ff4fe1b277cc73b8af Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Fri, 24 Nov 2023 16:07:24 +0300 Subject: [PATCH] [usage] Add color customization for example description --- CHANGELOG.md | 5 +++++ ek.go | 2 +- usage/usage.go | 26 +++++++++++++++----------- usage/usage_test.go | 4 +++- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dffed4c..b4ae6a62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Changelog +### 12.89.0 + +* `[usage]` Added color customization for example description +* `[usage]` Changed default color for example description + ### 12.88.1 * `[pager]` Improved pager search diff --git a/ek.go b/ek.go index f069d831..8777ca71 100644 --- a/ek.go +++ b/ek.go @@ -20,7 +20,7 @@ import ( // ////////////////////////////////////////////////////////////////////////////////// // // VERSION is current ek package version -const VERSION = "12.88.1" +const VERSION = "12.89.0" // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/usage/usage.go b/usage/usage.go index b6cf292c..a867dc27 100644 --- a/usage/usage.go +++ b/usage/usage.go @@ -34,12 +34,13 @@ const _BREADCRUMBS_MIN_SIZE = 8 // ////////////////////////////////////////////////////////////////////////////////// // const ( - DEFAULT_COMMANDS_COLOR_TAG = "{y}" - DEFAULT_OPTIONS_COLOR_TAG = "{g}" - DEFAULT_APP_NAME_COLOR_TAG = "{c*}" - DEFAULT_APP_VER_COLOR_TAG = "{c}" - DEFAULT_APP_REL_COLOR_TAG = "{s}" - DEFAULT_APP_BUILD_COLOR_TAG = "{s-}" + DEFAULT_COMMANDS_COLOR_TAG = "{y}" + DEFAULT_OPTIONS_COLOR_TAG = "{g}" + DEFAULT_EXAMPLE_DESC_COLOR_TAG = "{&}{s-}" + DEFAULT_APP_NAME_COLOR_TAG = "{c*}" + DEFAULT_APP_VER_COLOR_TAG = "{c}" + DEFAULT_APP_REL_COLOR_TAG = "{s}" + DEFAULT_APP_BUILD_COLOR_TAG = "{s-}" ) const ( @@ -89,10 +90,12 @@ type About struct { // Info contains info about commands, options, and examples type Info struct { - AppNameColorTag string // AppNameColorTag contains default app name color tag - CommandsColorTag string // CommandsColorTag contains default commands color tag - OptionsColorTag string // OptionsColorTag contains default options color tag - Breadcrumbs bool // Breadcrumbs is flag for using bread crumbs for commands and options output + AppNameColorTag string // AppNameColorTag contains default app name color tag + CommandsColorTag string // CommandsColorTag contains default commands color tag + OptionsColorTag string // OptionsColorTag contains default options color tag + ExampleDescColorTag string // ExampleDescColorTag contains default example description color tag + + Breadcrumbs bool // Breadcrumbs is flag for using bread crumbs for commands and options output Name string // Name is app name Args []string // Args is slice with app arguments @@ -482,7 +485,8 @@ func (e *Example) Print() { } if e.Desc != "" { - fmtc.Printf(" {s-}%s{!}\n", e.Desc) + descColor := strutil.Q(strutil.B(fmtc.IsTag(e.info.ExampleDescColorTag), e.info.ExampleDescColorTag, DEFAULT_EXAMPLE_DESC_COLOR_TAG), DEFAULT_EXAMPLE_DESC_COLOR_TAG) + fmtc.Printf(" "+descColor+"%s{!}\n", e.Desc) } } diff --git a/usage/usage_test.go b/usage/usage_test.go index 74a6633f..40f64891 100644 --- a/usage/usage_test.go +++ b/usage/usage_test.go @@ -100,7 +100,7 @@ func (s *UsageSuite) TestRawVersion(c *C) { func (s *UsageSuite) TestUsage(c *C) { info := NewInfo("", "file") - info.AddSpoiler("This is usage of spoiler with {g}c{c}o{r}l{m}o{b}r{g}s{!} support") + info.AddSpoiler("This is usage of spoiler with {#240}c{#241}o{#242}l{#243}o{#244}r{#245}s {#246}s{#247}u{#248}p{#249}p{#250}o{#251}r{#252}t{!}") info.AddCommand() // will be ignored info.AddCommand("print", "Print command") @@ -132,8 +132,10 @@ func (s *UsageSuite) TestUsage(c *C) { info.Render() info.Breadcrumbs = false + info.AppNameColorTag = "{#202}" info.CommandsColorTag = "{m}" info.OptionsColorTag = "{b}" + info.ExampleDescColorTag = "{&}{b}" info.Render()