Really figuring some things out

This commit is contained in:
2025-08-07 11:18:03 -05:00
parent 7c96fbb187
commit b476c74683
23 changed files with 737 additions and 249 deletions

31
cli.go
View File

@@ -26,10 +26,11 @@ import (
"sort"
"strings"
h "git.bullercodeworks.com/brian/tcell-widgets/helpers"
wh "git.bullercodeworks.com/brian/tcell-widgets/helpers"
"github.com/gdamore/tcell"
)
// Cli is a greedy widget and will consume all of the space you give it.
type Cli struct {
id string
style tcell.Style
@@ -58,6 +59,8 @@ type Cli struct {
keyMap KeyMap
}
var _ Widget = (*Cli)(nil)
func NewCli(id string, s tcell.Style) *Cli {
ret := &Cli{}
ret.Init(id, s)
@@ -77,11 +80,11 @@ func (w *Cli) HandleKey(ev *tcell.EventKey) bool {
if !w.active {
return false
}
if h.IsKey(*ev, tcell.KeyEsc) {
if wh.IsKey(*ev, tcell.KeyEsc) {
w.SetActive(false)
return true
}
if h.IsBS(*ev) {
if wh.IsBS(*ev) {
if w.cursor > 0 {
w.cursor--
}
@@ -94,7 +97,7 @@ func (w *Cli) HandleKey(ev *tcell.EventKey) bool {
}
var ch string
if h.KeyIsDisplayable(*ev) {
if wh.KeyIsDisplayable(*ev) {
ch = string(ev.Rune())
if w.cursor < len(w.value) {
strPt1 := w.value[:w.cursor]
@@ -119,9 +122,9 @@ func (w *Cli) Draw(screen tcell.Screen) {
dStyle = dStyle.Dim(true)
}
if w.title != "" {
h.TitledBorderFilled(w.x, w.y, w.x+w.w-1, w.y+w.h, w.title, h.BRD_SIMPLE, dStyle, screen)
wh.TitledBorderFilled(w.x, w.y, w.x+w.w-1, w.y+w.h, w.title, wh.BRD_SIMPLE, dStyle, screen)
} else {
h.BorderFilled(w.x, w.y, w.x+w.w-1, w.y+w.h, h.BRD_SIMPLE, dStyle, screen)
wh.BorderFilled(w.x, w.y, w.x+w.w-1, w.y+w.h, wh.BRD_SIMPLE, dStyle, screen)
}
x, y := w.x+1, w.y+1+w.h-3
@@ -131,7 +134,7 @@ func (w *Cli) Draw(screen tcell.Screen) {
if len(line) > w.w-2 {
line = line[:w.w-2]
}
h.DrawText(x, y, h.PadR(line, w.w), dStyle, screen)
wh.DrawText(x, y, wh.PadR(line, w.w), dStyle, screen)
y--
}
}
@@ -146,11 +149,11 @@ func (w *Cli) Draw(screen tcell.Screen) {
post = w.value[w.cursor+1:]
}
}
h.DrawText(x, y, pre, dStyle, screen)
wh.DrawText(x, y, pre, dStyle, screen)
x += len(pre)
h.DrawText(x, y, cursor, dStyle.Reverse(w.active), screen)
wh.DrawText(x, y, cursor, dStyle.Reverse(w.active), screen)
x += 1
h.DrawText(x, y, h.PadR(post, w.w-x), dStyle, screen)
wh.DrawText(x, y, wh.PadR(post, w.w-x), dStyle, screen)
// x += len(post) - 1
}
@@ -179,8 +182,8 @@ func (w *Cli) GetH() int { return w.h }
func (w *Cli) SetW(wd int) { w.w = wd }
func (w *Cli) SetH(h int) { w.h = h }
func (w *Cli) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Cli) WantW() int { return w.w }
func (w *Cli) WantH() int { return w.h }
func (w *Cli) WantW() int { return wh.MaxInt }
func (w *Cli) WantH() int { return wh.MaxInt }
func (w *Cli) MinW() int { return 20 }
func (w *Cli) MinH() int { return 6 }
@@ -297,7 +300,7 @@ func (w *Cli) findBestGuess() string {
func (w *Cli) Log(txt string, args ...any) {
val := fmt.Sprintf(txt, args...)
w.rawLog = append(w.rawLog, val)
w.log = append(w.log, h.WrapStringToSlice(val, w.w-2)...)
w.log = append(w.log, wh.WrapStringToSlice(val, w.w-2)...)
}
func (w *Cli) Clear() {
@@ -307,6 +310,8 @@ func (w *Cli) Clear() {
type cliCommand func(args ...string) bool
// TODO
func (c *cliCommand) findBestGuess(args ...string) string {
_ = args
return ""
}