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

35
chat.go
View File

@@ -25,10 +25,11 @@ import (
"fmt"
"time"
h "git.bullercodeworks.com/brian/tcell-widgets/helpers"
wh "git.bullercodeworks.com/brian/tcell-widgets/helpers"
"github.com/gdamore/tcell"
)
// Chat is a greedy widget and will consume all of the space you give it.
type Chat struct {
id string
style tcell.Style
@@ -53,6 +54,8 @@ type Chat struct {
keyMap KeyMap
}
var _ Widget = (*Chat)(nil)
func NewChat(id string, s tcell.Style) *Chat {
ret := &Chat{}
ret.Init(id, s)
@@ -66,18 +69,22 @@ func (w *Chat) Init(id string, s tcell.Style) {
w.tabbable = true
}
func (w *Chat) Id() string { return w.id }
func (w *Chat) HandleResize(ev *tcell.EventResize) { w.w, w.h = ev.Size() }
func (w *Chat) Id() string { return w.id }
func (w *Chat) HandleResize(ev *tcell.EventResize) {
w.w, w.h = ev.Size()
w.w = wh.Min(w.w, w.WantW())
w.h = wh.Min(w.h, w.WantH())
}
func (w *Chat) 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--
}
@@ -90,7 +97,7 @@ func (w *Chat) 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]
@@ -115,9 +122,9 @@ func (w *Chat) 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
@@ -127,7 +134,7 @@ func (w *Chat) 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--
}
}
@@ -142,11 +149,11 @@ func (w *Chat) 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
}
@@ -175,8 +182,8 @@ func (w *Chat) GetH() int { return w.h }
func (w *Chat) SetW(wd int) { w.w = wd }
func (w *Chat) SetH(h int) { w.h = h }
func (w *Chat) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Chat) WantW() int { return w.w }
func (w *Chat) WantH() int { return w.h }
func (w *Chat) WantW() int { return wh.MaxInt }
func (w *Chat) WantH() int { return wh.MaxInt }
func (w *Chat) MinW() int { return 2 + 20 }
func (w *Chat) MinH() int { return 6 }