Correct infobar and statusline options

This commit is contained in:
Zachary Yedidia
2019-01-14 22:16:44 -05:00
parent ebba9fb8ce
commit dcd5f4e6e1
8 changed files with 55 additions and 54 deletions

View File

@@ -1046,8 +1046,9 @@ func (h *BufHandler) QuitAll() bool {
// AddTab adds a new tab with an empty buffer // AddTab adds a new tab with an empty buffer
func (h *BufHandler) AddTab() bool { func (h *BufHandler) AddTab() bool {
width, height := screen.Screen.Size() width, height := screen.Screen.Size()
iOffset := config.GetInfoBarOffset()
b := buffer.NewBufferFromString("", "", buffer.BTDefault) 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.AddTab(tp)
Tabs.SetActive(len(Tabs.List) - 1) Tabs.SetActive(len(Tabs.List) - 1)

View File

@@ -352,6 +352,7 @@ func (h *BufHandler) EvalCmd(args []string) {
// NewTabCmd opens the given file in a new tab // NewTabCmd opens the given file in a new tab
func (h *BufHandler) NewTabCmd(args []string) { func (h *BufHandler) NewTabCmd(args []string) {
width, height := screen.Screen.Size() width, height := screen.Screen.Size()
iOffset := config.GetInfoBarOffset()
if len(args) > 0 { if len(args) > 0 {
for _, a := range args { for _, a := range args {
b, err := buffer.NewBufferFromFile(a, buffer.BTDefault) b, err := buffer.NewBufferFromFile(a, buffer.BTDefault)
@@ -359,13 +360,13 @@ func (h *BufHandler) NewTabCmd(args []string) {
InfoBar.Error(err) InfoBar.Error(err)
return return
} }
tp := NewTabFromBuffer(0, 0, width, height-1, b) tp := NewTabFromBuffer(0, 0, width, height-1-iOffset, b)
Tabs.AddTab(tp) Tabs.AddTab(tp)
Tabs.SetActive(len(Tabs.List) - 1) Tabs.SetActive(len(Tabs.List) - 1)
} }
} else { } else {
b := buffer.NewBufferFromString("", "", buffer.BTDefault) 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.AddTab(tp)
Tabs.SetActive(len(Tabs.List) - 1) Tabs.SetActive(len(Tabs.List) - 1)
} }
@@ -392,11 +393,9 @@ func SetGlobalOption(option, value string) error {
} }
// TODO: info and keymenu option change // TODO: info and keymenu option change
// if option == "infobar" || option == "keymenu" { if option == "infobar" || option == "keymenu" {
// for _, tab := range tabs { Tabs.Resize()
// tab.Resize() }
// }
// }
if option == "mouse" { if option == "mouse" {
if !nativeValue.(bool) { if !nativeValue.(bool) {

View File

@@ -2,6 +2,7 @@ package action
import ( import (
"github.com/zyedidia/micro/cmd/micro/buffer" "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/display"
"github.com/zyedidia/micro/cmd/micro/screen" "github.com/zyedidia/micro/cmd/micro/screen"
"github.com/zyedidia/micro/cmd/micro/views" "github.com/zyedidia/micro/cmd/micro/views"
@@ -19,14 +20,15 @@ type TabList struct {
// for each buffer // for each buffer
func NewTabList(bufs []*buffer.Buffer) *TabList { func NewTabList(bufs []*buffer.Buffer) *TabList {
w, h := screen.Screen.Size() w, h := screen.Screen.Size()
iOffset := config.GetInfoBarOffset()
tl := new(TabList) tl := new(TabList)
tl.List = make([]*Tab, len(bufs)) tl.List = make([]*Tab, len(bufs))
if len(bufs) > 1 { if len(bufs) > 1 {
for i, b := range bufs { 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 { } 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.TabWindow = display.NewTabWindow(w, 0)
tl.Names = make([]string, len(bufs)) tl.Names = make([]string, len(bufs))
@@ -76,16 +78,17 @@ func (t *TabList) RemoveTab(id uint64) {
// that into account // that into account
func (t *TabList) Resize() { func (t *TabList) Resize() {
w, h := screen.Screen.Size() w, h := screen.Screen.Size()
iOffset := config.GetInfoBarOffset()
InfoBar.Resize(w, h-1) InfoBar.Resize(w, h-1)
if len(t.List) > 1 { if len(t.List) > 1 {
for _, p := range t.List { for _, p := range t.List {
p.Y = 1 p.Y = 1
p.Node.Resize(w, h-2) p.Node.Resize(w, h-1-iOffset)
p.Resize() p.Resize()
} }
} else if len(t.List) == 1 { } else if len(t.List) == 1 {
t.List[0].Y = 0 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() t.List[0].Resize()
} }
} }

View File

@@ -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 // DefaultGlobalSettings returns the default global settings for micro
// Note that colorscheme is a global only option // Note that colorscheme is a global only option
func DefaultGlobalSettings() map[string]interface{} { func DefaultGlobalSettings() map[string]interface{} {

View File

@@ -26,6 +26,7 @@ type BufWindow struct {
lineHeight []int lineHeight []int
gutterOffset int gutterOffset int
drawStatus bool
} }
// NewBufWindow creates a new window at a location in the screen with a width and height // 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 { func (w *BufWindow) Relocate() bool {
b := w.Buf b := w.Buf
height := w.Bottomline() + 1 - w.StartLine height := w.Bottomline() + 1 - w.StartLine
if b.LinesNum() < w.Height { h := w.Height
height = w.Height - 1 if w.drawStatus {
h--
}
if b.LinesNum() <= h {
height = w.Height
} }
ret := false ret := false
activeC := w.Buf.GetActiveCursor() activeC := w.Buf.GetActiveCursor()
@@ -181,7 +186,7 @@ func (w *BufWindow) GetMouseLoc(svloc buffer.Loc) buffer.Loc {
hasMessage := len(b.Messages) > 0 hasMessage := len(b.Messages) > 0
bufHeight := w.Height bufHeight := w.Height
if b.Settings["statusline"].(bool) { if w.drawStatus {
bufHeight-- bufHeight--
} }
@@ -353,7 +358,7 @@ func (w *BufWindow) displayBuffer() {
hasMessage := len(b.Messages) > 0 hasMessage := len(b.Messages) > 0
bufHeight := w.Height bufHeight := w.Height
if b.Settings["statusline"].(bool) { if w.drawStatus {
bufHeight-- bufHeight--
} }
@@ -537,11 +542,27 @@ func (w *BufWindow) displayBuffer() {
} }
func (w *BufWindow) displayStatusLine() { 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 // Display displays the buffer and the statusline
func (w *BufWindow) Display() { func (w *BufWindow) Display() {
w.displayBuffer()
w.displayStatusLine() w.displayStatusLine()
w.displayBuffer()
} }

View File

@@ -57,35 +57,6 @@ func (i *InfoWindow) SetBuffer(b *buffer.Buffer) {
i.InfoBuf.Buffer = b 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) Relocate() bool { return false }
func (i *InfoWindow) GetView() *View { return i.View } func (i *InfoWindow) GetView() *View { return i.View }
func (i *InfoWindow) SetView(v *View) {} func (i *InfoWindow) SetView(v *View) {}
@@ -184,6 +155,7 @@ func (i *InfoWindow) Display() {
if !i.HasPrompt && !i.HasMessage && !i.HasError { if !i.HasPrompt && !i.HasMessage && !i.HasError {
return return
} }
i.Clear()
style := i.defStyle style := i.defStyle
if i.HasError { if i.HasError {

View File

@@ -69,11 +69,6 @@ var formatParser = regexp.MustCompile(`\$\(.+?\)`)
// Display draws the statusline to the screen // Display draws the statusline to the screen
func (s *StatusLine) Display() { 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 // We'll draw the line at the lowest line in the window
y := s.win.Height + s.win.Y - 1 y := s.win.Height + s.win.Y - 1

View File

@@ -23,14 +23,17 @@ func NewTermWindow(x, y, w, h int, term *shell.Terminal) *TermWindow {
tw.View = new(View) tw.View = new(View)
tw.Terminal = term tw.Terminal = term
tw.X, tw.Y = x, y tw.X, tw.Y = x, y
tw.Width, tw.Height = w, h-1 tw.Resize(w, h)
tw.Resize(tw.Width, tw.Height)
return tw return tw
} }
// Resize informs the terminal of a resize event // Resize informs the terminal of a resize event
func (w *TermWindow) Resize(width, height int) { func (w *TermWindow) Resize(width, height int) {
if config.GetGlobalOption("statusline").(bool) {
height--
}
w.Term.Resize(width, height) w.Term.Resize(width, height)
w.Width, w.Height = width, height
} }
func (w *TermWindow) SetActive(b bool) { func (w *TermWindow) SetActive(b bool) {