From 812c7761dc58ebd34f024074decfd7bd49585518 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Mon, 14 Jan 2019 22:16:44 -0500 Subject: [PATCH] Correct infobar and statusline options --- cmd/micro/action/actions.go | 3 ++- cmd/micro/action/command.go | 13 ++++++------- cmd/micro/action/tab.go | 11 +++++++---- cmd/micro/config/settings.go | 7 +++++++ cmd/micro/display/bufwindow.go | 33 +++++++++++++++++++++++++++------ cmd/micro/display/infowindow.go | 30 +----------------------------- cmd/micro/display/statusline.go | 5 ----- cmd/micro/display/termwindow.go | 7 +++++-- 8 files changed, 55 insertions(+), 54 deletions(-) diff --git a/cmd/micro/action/actions.go b/cmd/micro/action/actions.go index e7278f8b..32a22288 100644 --- a/cmd/micro/action/actions.go +++ b/cmd/micro/action/actions.go @@ -1046,8 +1046,9 @@ func (h *BufHandler) QuitAll() bool { // AddTab adds a new tab with an empty buffer func (h *BufHandler) AddTab() bool { width, height := screen.Screen.Size() + iOffset := config.GetInfoBarOffset() b := buffer.NewBufferFromString("", "", buffer.BTDefault) - tp := NewTabFromBuffer(0, 0, width, height-1, b) + tp := NewTabFromBuffer(0, 0, width, height-iOffset, b) Tabs.AddTab(tp) Tabs.SetActive(len(Tabs.List) - 1) diff --git a/cmd/micro/action/command.go b/cmd/micro/action/command.go index 58170f72..7d40baec 100644 --- a/cmd/micro/action/command.go +++ b/cmd/micro/action/command.go @@ -352,6 +352,7 @@ func (h *BufHandler) EvalCmd(args []string) { // NewTabCmd opens the given file in a new tab func (h *BufHandler) NewTabCmd(args []string) { width, height := screen.Screen.Size() + iOffset := config.GetInfoBarOffset() if len(args) > 0 { for _, a := range args { b, err := buffer.NewBufferFromFile(a, buffer.BTDefault) @@ -359,13 +360,13 @@ func (h *BufHandler) NewTabCmd(args []string) { InfoBar.Error(err) return } - tp := NewTabFromBuffer(0, 0, width, height-1, b) + tp := NewTabFromBuffer(0, 0, width, height-1-iOffset, b) Tabs.AddTab(tp) Tabs.SetActive(len(Tabs.List) - 1) } } else { b := buffer.NewBufferFromString("", "", buffer.BTDefault) - tp := NewTabFromBuffer(0, 0, width, height-1, b) + tp := NewTabFromBuffer(0, 0, width, height-iOffset, b) Tabs.AddTab(tp) Tabs.SetActive(len(Tabs.List) - 1) } @@ -392,11 +393,9 @@ func SetGlobalOption(option, value string) error { } // TODO: info and keymenu option change - // if option == "infobar" || option == "keymenu" { - // for _, tab := range tabs { - // tab.Resize() - // } - // } + if option == "infobar" || option == "keymenu" { + Tabs.Resize() + } if option == "mouse" { if !nativeValue.(bool) { diff --git a/cmd/micro/action/tab.go b/cmd/micro/action/tab.go index 0dab39f6..6b8773e4 100644 --- a/cmd/micro/action/tab.go +++ b/cmd/micro/action/tab.go @@ -2,6 +2,7 @@ package action import ( "github.com/zyedidia/micro/cmd/micro/buffer" + "github.com/zyedidia/micro/cmd/micro/config" "github.com/zyedidia/micro/cmd/micro/display" "github.com/zyedidia/micro/cmd/micro/screen" "github.com/zyedidia/micro/cmd/micro/views" @@ -19,14 +20,15 @@ type TabList struct { // for each buffer func NewTabList(bufs []*buffer.Buffer) *TabList { w, h := screen.Screen.Size() + iOffset := config.GetInfoBarOffset() tl := new(TabList) tl.List = make([]*Tab, len(bufs)) if len(bufs) > 1 { for i, b := range bufs { - tl.List[i] = NewTabFromBuffer(0, 1, w, h-2, b) + tl.List[i] = NewTabFromBuffer(0, 1, w, h-1-iOffset, b) } } else { - tl.List[0] = NewTabFromBuffer(0, 0, w, h-1, bufs[0]) + tl.List[0] = NewTabFromBuffer(0, 0, w, h-iOffset, bufs[0]) } tl.TabWindow = display.NewTabWindow(w, 0) tl.Names = make([]string, len(bufs)) @@ -76,16 +78,17 @@ func (t *TabList) RemoveTab(id uint64) { // that into account func (t *TabList) Resize() { w, h := screen.Screen.Size() + iOffset := config.GetInfoBarOffset() InfoBar.Resize(w, h-1) if len(t.List) > 1 { for _, p := range t.List { p.Y = 1 - p.Node.Resize(w, h-2) + p.Node.Resize(w, h-1-iOffset) p.Resize() } } else if len(t.List) == 1 { t.List[0].Y = 0 - t.List[0].Node.Resize(w, h-1) + t.List[0].Node.Resize(w, h-iOffset) t.List[0].Resize() } } diff --git a/cmd/micro/config/settings.go b/cmd/micro/config/settings.go index b82bd78f..c9f7f215 100644 --- a/cmd/micro/config/settings.go +++ b/cmd/micro/config/settings.go @@ -163,6 +163,13 @@ func DefaultCommonSettings() map[string]interface{} { } } +func GetInfoBarOffset() int { + if GetGlobalOption("infobar").(bool) { + return 1 + } + return 0 +} + // DefaultGlobalSettings returns the default global settings for micro // Note that colorscheme is a global only option func DefaultGlobalSettings() map[string]interface{} { diff --git a/cmd/micro/display/bufwindow.go b/cmd/micro/display/bufwindow.go index cee7164d..a5a677db 100644 --- a/cmd/micro/display/bufwindow.go +++ b/cmd/micro/display/bufwindow.go @@ -26,6 +26,7 @@ type BufWindow struct { lineHeight []int gutterOffset int + drawStatus bool } // NewBufWindow creates a new window at a location in the screen with a width and height @@ -133,8 +134,12 @@ func (w *BufWindow) Bottomline() int { func (w *BufWindow) Relocate() bool { b := w.Buf height := w.Bottomline() + 1 - w.StartLine - if b.LinesNum() < w.Height { - height = w.Height - 1 + h := w.Height + if w.drawStatus { + h-- + } + if b.LinesNum() <= h { + height = w.Height } ret := false activeC := w.Buf.GetActiveCursor() @@ -181,7 +186,7 @@ func (w *BufWindow) GetMouseLoc(svloc buffer.Loc) buffer.Loc { hasMessage := len(b.Messages) > 0 bufHeight := w.Height - if b.Settings["statusline"].(bool) { + if w.drawStatus { bufHeight-- } @@ -353,7 +358,7 @@ func (w *BufWindow) displayBuffer() { hasMessage := len(b.Messages) > 0 bufHeight := w.Height - if b.Settings["statusline"].(bool) { + if w.drawStatus { bufHeight-- } @@ -537,11 +542,27 @@ func (w *BufWindow) displayBuffer() { } func (w *BufWindow) displayStatusLine() { - w.sline.Display() + _, h := screen.Screen.Size() + infoY := h + if config.GetGlobalOption("infobar").(bool) { + infoY-- + } + + if w.Buf.Settings["statusline"].(bool) { + w.drawStatus = true + w.sline.Display() + } else if w.Y+w.Height != infoY { + w.drawStatus = true + for x := w.X; x < w.X+w.Width; x++ { + screen.Screen.SetContent(x, w.Y+w.Height-1, '-', nil, config.DefStyle.Reverse(true)) + } + } else { + w.drawStatus = false + } } // Display displays the buffer and the statusline func (w *BufWindow) Display() { - w.displayBuffer() w.displayStatusLine() + w.displayBuffer() } diff --git a/cmd/micro/display/infowindow.go b/cmd/micro/display/infowindow.go index d559693c..fe7b1ea4 100644 --- a/cmd/micro/display/infowindow.go +++ b/cmd/micro/display/infowindow.go @@ -57,35 +57,6 @@ func (i *InfoWindow) SetBuffer(b *buffer.Buffer) { i.InfoBuf.Buffer = b } -// func (i *InfoWindow) YesNoPrompt() (bool, bool) { -// for { -// i.Clear() -// i.Display() -// screen.Screen.ShowCursor(utf8.RuneCountInString(i.Msg), i.y) -// screen.Show() -// event := <-events -// -// switch e := event.(type) { -// case *tcell.EventKey: -// switch e.Key() { -// case tcell.KeyRune: -// if e.Rune() == 'y' || e.Rune() == 'Y' { -// i.HasPrompt = false -// return true, false -// } else if e.Rune() == 'n' || e.Rune() == 'N' { -// i.HasPrompt = false -// return false, false -// } -// case tcell.KeyCtrlC, tcell.KeyCtrlQ, tcell.KeyEscape: -// i.Clear() -// i.Reset() -// i.HasPrompt = false -// return false, true -// } -// } -// } -// } - func (i *InfoWindow) Relocate() bool { return false } func (i *InfoWindow) GetView() *View { return i.View } func (i *InfoWindow) SetView(v *View) {} @@ -184,6 +155,7 @@ func (i *InfoWindow) Display() { if !i.HasPrompt && !i.HasMessage && !i.HasError { return } + i.Clear() style := i.defStyle if i.HasError { diff --git a/cmd/micro/display/statusline.go b/cmd/micro/display/statusline.go index c1e72a41..435b9968 100644 --- a/cmd/micro/display/statusline.go +++ b/cmd/micro/display/statusline.go @@ -69,11 +69,6 @@ var formatParser = regexp.MustCompile(`\$\(.+?\)`) // Display draws the statusline to the screen func (s *StatusLine) Display() { - // TODO: don't display if infobar off and has message - if !config.GetGlobalOption("infobar").(bool) { - return - } - // We'll draw the line at the lowest line in the window y := s.win.Height + s.win.Y - 1 diff --git a/cmd/micro/display/termwindow.go b/cmd/micro/display/termwindow.go index e5b72a22..a8c6bf01 100644 --- a/cmd/micro/display/termwindow.go +++ b/cmd/micro/display/termwindow.go @@ -23,14 +23,17 @@ func NewTermWindow(x, y, w, h int, term *shell.Terminal) *TermWindow { tw.View = new(View) tw.Terminal = term tw.X, tw.Y = x, y - tw.Width, tw.Height = w, h-1 - tw.Resize(tw.Width, tw.Height) + tw.Resize(w, h) return tw } // Resize informs the terminal of a resize event func (w *TermWindow) Resize(width, height int) { + if config.GetGlobalOption("statusline").(bool) { + height-- + } w.Term.Resize(width, height) + w.Width, w.Height = width, height } func (w *TermWindow) SetActive(b bool) {