Add status bar

This commit is contained in:
Luke I. Wilson 2021-03-19 21:57:49 -05:00
parent 70d734e8e2
commit 6e97e8345a
2 changed files with 36 additions and 8 deletions

34
main.go
View File

@ -10,7 +10,9 @@ import (
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
) )
var theme = ui.Theme{} var theme = ui.Theme{
"StatusBar": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
}
var focusedComponent ui.Component = nil var focusedComponent ui.Component = nil
@ -38,7 +40,7 @@ func main() {
tabContainer := ui.NewTabContainer(&theme) tabContainer := ui.NewTabContainer(&theme)
tabContainer.SetPos(0, 1) tabContainer.SetPos(0, 1)
tabContainer.SetSize(sizex, sizey-1) tabContainer.SetSize(sizex, sizey-2)
_, err := ClipInitialize(ClipExternal) _, err := ClipInitialize(ClipExternal)
if err != nil { if err != nil {
@ -215,6 +217,32 @@ main_loop:
fileSelector.Draw(s) fileSelector.Draw(s)
} }
// Draw statusbar
ui.DrawRect(s, 0, sizey-1, sizex, 1, ' ', theme["StatusBar"])
if tabContainer.GetTabCount() > 0 {
focusedTab := tabContainer.GetTab(tabContainer.GetSelectedTabIdx())
te := focusedTab.Child.(*ui.TextEdit)
var delim string
if te.IsCRLF {
delim = "CRLF"
} else {
delim = "LF"
}
line, col := te.GetLineCol()
var tabs string
if te.UseHardTabs {
tabs = "Tabs: Hard"
} else {
tabs = "Tabs: Spaces"
}
str := fmt.Sprintf(" Filetype: %s %d, %d %s %s", "None", line+1, col+1, delim, tabs)
ui.DrawStr(s, 0, sizey-1, str, theme["StatusBar"])
}
s.Show() s.Show()
switch ev := s.PollEvent().(type) { switch ev := s.PollEvent().(type) {
@ -222,7 +250,7 @@ main_loop:
sizex, sizey = s.Size() sizex, sizey = s.Size()
bar.SetSize(sizex, 1) bar.SetSize(sizex, 1)
tabContainer.SetSize(sizex, sizey-1) tabContainer.SetSize(sizex, sizey-2)
s.Sync() // Redraw everything s.Sync() // Redraw everything
case *tcell.EventKey: case *tcell.EventKey:

View File

@ -241,11 +241,6 @@ func (t *TextEdit) insertNewLine() {
t.prevCurCol = t.curx t.prevCurCol = t.curx
} }
// GetLineCol returns (line, col) of the cursor. Zero is origin for both.
func (t *TextEdit) GetLineCol() (int, int) {
return t.cury, t.curx
}
// getTabCountInLineAtCol returns tabs in the given line, at or before that column position, // getTabCountInLineAtCol returns tabs in the given line, at or before that column position,
// if hard tabs are enabled. If hard tabs are not enabled, the function returns zero. // if hard tabs are enabled. If hard tabs are not enabled, the function returns zero.
// Multiply returned tab count by TabSize to get the offset produced by tabs. // Multiply returned tab count by TabSize to get the offset produced by tabs.
@ -280,6 +275,11 @@ func (t *TextEdit) clampLineCol(line, col int) (int, int) {
return line, col return line, col
} }
// GetLineCol returns (line, col) of the cursor. Zero is origin for both.
func (t *TextEdit) GetLineCol() (int, int) {
return t.cury, t.curx
}
// SetLineCol sets the cursor line and column position. Zero is origin for both. // SetLineCol sets the cursor line and column position. Zero is origin for both.
// If `line` is out of bounds, `line` will be clamped to the closest available line. // If `line` is out of bounds, `line` will be clamped to the closest available line.
// If `col` is out of bounds, `col` will be clamped to the closest column available for the line. // If `col` is out of bounds, `col` will be clamped to the closest column available for the line.