From 6e97e8345a7c098514c1a832a1608877d227af17 Mon Sep 17 00:00:00 2001 From: "Luke I. Wilson" Date: Fri, 19 Mar 2021 21:57:49 -0500 Subject: [PATCH] Add status bar --- main.go | 34 +++++++++++++++++++++++++++++++--- ui/textedit.go | 10 +++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 872fa8c..391a248 100644 --- a/main.go +++ b/main.go @@ -10,7 +10,9 @@ import ( "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 @@ -38,7 +40,7 @@ func main() { tabContainer := ui.NewTabContainer(&theme) tabContainer.SetPos(0, 1) - tabContainer.SetSize(sizex, sizey-1) + tabContainer.SetSize(sizex, sizey-2) _, err := ClipInitialize(ClipExternal) if err != nil { @@ -215,6 +217,32 @@ main_loop: 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() switch ev := s.PollEvent().(type) { @@ -222,7 +250,7 @@ main_loop: sizex, sizey = s.Size() bar.SetSize(sizex, 1) - tabContainer.SetSize(sizex, sizey-1) + tabContainer.SetSize(sizex, sizey-2) s.Sync() // Redraw everything case *tcell.EventKey: diff --git a/ui/textedit.go b/ui/textedit.go index c23ec95..ca2f8da 100644 --- a/ui/textedit.go +++ b/ui/textedit.go @@ -241,11 +241,6 @@ func (t *TextEdit) insertNewLine() { 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, // 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. @@ -280,6 +275,11 @@ func (t *TextEdit) clampLineCol(line, col int) (int, int) { 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. // 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.