From c93d7a1b35c56712c3cff797e2fd7b7b9eefecf7 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sat, 15 Jun 2019 16:13:04 -0400 Subject: [PATCH] Add hidehelp support --- internal/action/command.go | 8 ++------ internal/buffer/buffer.go | 17 +++++++++++++++++ internal/buffer/settings.go | 2 ++ internal/display/statusline.go | 15 +++++---------- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/internal/action/command.go b/internal/action/command.go index 4db56207..9b96de09 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -365,13 +365,9 @@ func SetGlobalOption(option, value string) error { for _, b := range buffer.OpenBuffers { b.UpdateRules() } - } - - if option == "infobar" || option == "keymenu" { + } else if option == "infobar" || option == "keymenu" { Tabs.Resize() - } - - if option == "mouse" { + } else if option == "mouse" { if !nativeValue.(bool) { screen.Screen.DisableMouse() } else { diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index 543c5109..36bb6cff 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -107,6 +107,9 @@ type Buffer struct { CurSuggestion int Messages []*Message + + StatusFormatLeft string + StatusFormatRight string } // NewBufferFromFile opens a new buffer using the given path @@ -236,11 +239,25 @@ func NewBuffer(r io.Reader, size int64, path string, cursorPosition []string, bt screen.TermMessage(err) } + b.SetStatusFormat() + OpenBuffers = append(OpenBuffers, b) return b } +// SetStatusFormat will correctly set the format string for the +// status line +func (b *Buffer) SetStatusFormat() { + if b.Settings["hidehelp"].(bool) { + b.StatusFormatLeft = "$(filename) $(modified)($(line),$(col)) $(opt:filetype) $(opt:fileformat) $(opt:encoding)" + b.StatusFormatRight = "" + } else { + b.StatusFormatLeft = "$(filename) $(modified)($(line),$(col)) $(opt:filetype) $(opt:fileformat) $(opt:encoding)" + b.StatusFormatRight = "$(bind:ToggleKeyMenu): show bindings, $(bind:ToggleHelp): toggle help" + } +} + // Close removes this buffer from the list of open buffers func (b *Buffer) Close() { for i, buf := range OpenBuffers { diff --git a/internal/buffer/settings.go b/internal/buffer/settings.go index b56608be..e85672a6 100644 --- a/internal/buffer/settings.go +++ b/internal/buffer/settings.go @@ -45,6 +45,8 @@ func (b *Buffer) SetOption(option, value string) error { } } else if option == "encoding" { b.isModified = true + } else if option == "hidehelp" { + b.SetStatusFormat() } return nil diff --git a/internal/display/statusline.go b/internal/display/statusline.go index ec7d382a..b48406cd 100644 --- a/internal/display/statusline.go +++ b/internal/display/statusline.go @@ -18,9 +18,7 @@ import ( // It gives information such as filename, whether the file has been // modified, filetype, cursor location type StatusLine struct { - FormatLeft string - FormatRight string - Info map[string]func(*buffer.Buffer) string + Info map[string]func(*buffer.Buffer) string win *BufWindow } @@ -30,9 +28,6 @@ type StatusLine struct { // NewStatusLine returns a statusline bound to a window func NewStatusLine(win *BufWindow) *StatusLine { s := new(StatusLine) - s.FormatLeft = "$(filename) $(modified)($(line),$(col)) $(opt:filetype) $(opt:fileformat) $(opt:encoding)" - // s.FormatLeft = "$(filename) $(modified)(line,col) $(opt:filetype) $(opt:fileformat)" - s.FormatRight = "$(bind:ToggleKeyMenu): show bindings, $(bind:ToggleHelp): toggle help" s.Info = map[string]func(*buffer.Buffer) string{ "filename": func(b *buffer.Buffer) string { if b.Settings["basename"].(bool) { @@ -90,10 +85,10 @@ func (s *StatusLine) Display() { } } - leftText := []byte(s.FormatLeft) - leftText = formatParser.ReplaceAllFunc([]byte(s.FormatLeft), formatter) - rightText := []byte(s.FormatRight) - rightText = formatParser.ReplaceAllFunc([]byte(s.FormatRight), formatter) + leftText := []byte(s.win.Buf.StatusFormatLeft) + leftText = formatParser.ReplaceAllFunc(leftText, formatter) + rightText := []byte(s.win.Buf.StatusFormatRight) + rightText = formatParser.ReplaceAllFunc(rightText, formatter) statusLineStyle := config.DefStyle.Reverse(true) if style, ok := config.Colorscheme["statusline"]; ok {