From cbdee0116ae2ebd4674c932498e6bf3381491e5c Mon Sep 17 00:00:00 2001 From: resolritter <17429390+resolritter@users.noreply.github.com> Date: Wed, 31 May 2023 21:21:40 -0300 Subject: [PATCH 1/2] introduce HidePromptFilename and InvertPromptColor options --- ov.yaml | 2 ++ oviewer/config.go | 1 + oviewer/draw.go | 21 ++++++++++++++------- oviewer/oviewer.go | 2 ++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ov.yaml b/ov.yaml index 5246b7b4..0cffe06a 100644 --- a/ov.yaml +++ b/ov.yaml @@ -7,6 +7,8 @@ # BeforeWriteOriginal: 1000 # AfterWriteOriginal: 0 # MemoryLimit: 10000 +# HidePromptFilename: false +# InvertPromptColor: true General: TabWidth: 8 diff --git a/oviewer/config.go b/oviewer/config.go index 1280a29c..da4028ab 100644 --- a/oviewer/config.go +++ b/oviewer/config.go @@ -59,5 +59,6 @@ func NewConfig() Config { SectionStartPosition: 0, JumpTarget: 0, }, + InvertPromptColor: true, } } diff --git a/oviewer/draw.go b/oviewer/draw.go index 7aa4bc0d..5c782594 100644 --- a/oviewer/draw.go +++ b/oviewer/draw.go @@ -483,20 +483,27 @@ func (root *Root) normalLeftStatus() (contents, int) { } else if root.Doc.FollowSection { modeStatus = "(Follow Section)" } - caption := root.Doc.FileName + + caption := "" if root.Doc.Caption != "" { caption = root.Doc.Caption + } else if !root.Config.HidePromptFilename { + caption = root.Doc.FileName } leftStatus := fmt.Sprintf("%s%s%s:%s", number, modeStatus, caption, root.message) leftContents := StrToContents(leftStatus, -1) - color := tcell.ColorWhite - if root.CurrentDoc != 0 { - color = tcell.Color((root.CurrentDoc + 8) % 16) - } - for i := 0; i < len(leftContents); i++ { - leftContents[i].style = leftContents[i].style.Foreground(tcell.ColorValid + color).Reverse(true) + + if root.Config.InvertPromptColor { + color := tcell.ColorWhite + if root.CurrentDoc != 0 { + color = tcell.Color((root.CurrentDoc + 8) % 16) + } + for i := 0; i < len(leftContents); i++ { + leftContents[i].style = leftContents[i].style.Foreground(tcell.ColorValid + color).Reverse(true) + } } + return leftContents, len(leftContents) } diff --git a/oviewer/oviewer.go b/oviewer/oviewer.go index 6cacf149..8b1cc2d1 100644 --- a/oviewer/oviewer.go +++ b/oviewer/oviewer.go @@ -192,6 +192,8 @@ type Config struct { RegexpSearch bool Incsearch bool Debug bool + HidePromptFilename bool + InvertPromptColor bool } // OVStyle represents a style in addition to the original style. From fe2b11848fb14d279f8d7bf6c3555a7406b4900a Mon Sep 17 00:00:00 2001 From: resolritter <17429390+resolritter@users.noreply.github.com> Date: Thu, 1 Jun 2023 01:07:03 -0300 Subject: [PATCH 2/2] better organization for prompt-related configs --- main.go | 8 +++++++- ov.yaml | 6 ++++-- oviewer/config.go | 7 ++++++- oviewer/draw.go | 4 ++-- oviewer/oviewer.go | 12 ++++++++++-- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 5b3e5741..d021487c 100644 --- a/main.go +++ b/main.go @@ -361,7 +361,13 @@ func initConfig() { viper.AutomaticEnv() // read in environment variables that match // If a config file is found, read it in. - _ = viper.ReadInConfig() + if err := viper.ReadInConfig(); err != nil { + if _, ok := err.(viper.ConfigFileNotFoundError); !ok { + fmt.Fprintln(os.Stderr, err) + return + } + } + if err := viper.Unmarshal(&config); err != nil { fmt.Fprintln(os.Stderr, err) return diff --git a/ov.yaml b/ov.yaml index 0cffe06a..91a45c86 100644 --- a/ov.yaml +++ b/ov.yaml @@ -7,8 +7,10 @@ # BeforeWriteOriginal: 1000 # AfterWriteOriginal: 0 # MemoryLimit: 10000 -# HidePromptFilename: false -# InvertPromptColor: true +# Prompt: +# Normal: +# ShowFilename: true +# InvertColor: true General: TabWidth: 8 diff --git a/oviewer/config.go b/oviewer/config.go index da4028ab..0ad40786 100644 --- a/oviewer/config.go +++ b/oviewer/config.go @@ -59,6 +59,11 @@ func NewConfig() Config { SectionStartPosition: 0, JumpTarget: 0, }, - InvertPromptColor: true, + Prompt: OVPromptConfig{ + Normal: OVPromptConfigNormal{ + ShowFilename: true, + InvertColor: true, + }, + }, } } diff --git a/oviewer/draw.go b/oviewer/draw.go index 5c782594..a074d8b5 100644 --- a/oviewer/draw.go +++ b/oviewer/draw.go @@ -487,14 +487,14 @@ func (root *Root) normalLeftStatus() (contents, int) { caption := "" if root.Doc.Caption != "" { caption = root.Doc.Caption - } else if !root.Config.HidePromptFilename { + } else if root.Config.Prompt.Normal.ShowFilename { caption = root.Doc.FileName } leftStatus := fmt.Sprintf("%s%s%s:%s", number, modeStatus, caption, root.message) leftContents := StrToContents(leftStatus, -1) - if root.Config.InvertPromptColor { + if root.Config.Prompt.Normal.InvertColor { color := tcell.ColorWhite if root.CurrentDoc != 0 { color = tcell.Color((root.CurrentDoc + 8) % 16) diff --git a/oviewer/oviewer.go b/oviewer/oviewer.go index 8b1cc2d1..5d43342b 100644 --- a/oviewer/oviewer.go +++ b/oviewer/oviewer.go @@ -161,6 +161,15 @@ type general struct { PlainMode bool } +type OVPromptConfigNormal struct { + ShowFilename bool + InvertColor bool +} + +type OVPromptConfig struct { + Normal OVPromptConfigNormal +} + // Config represents the settings of ov. type Config struct { Keybind map[string][]string @@ -192,8 +201,7 @@ type Config struct { RegexpSearch bool Incsearch bool Debug bool - HidePromptFilename bool - InvertPromptColor bool + Prompt OVPromptConfig } // OVStyle represents a style in addition to the original style.