mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-05 22:50:21 +09:00
Correct infobar and statusline options
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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{} {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user