rendering changes, no more "dirty"

This commit is contained in:
Lobo 2025-10-12 14:01:07 -03:00
parent 13d57534a6
commit d69f375a57
4 changed files with 43 additions and 55 deletions

View file

@ -29,8 +29,6 @@ func (app *App) FinishUI() {
}
func (app *App) resize() {
app.dirty = true
win := app.vx.Window()
app.w.log = win.New(0, 1, win.Width, win.Height-2)
app.w.title = win.New(0, 0, win.Width, 1)
@ -39,13 +37,9 @@ func (app *App) resize() {
}
func (app *App) Redraw() {
if !app.dirty {
return
}
app.dirty = false
app.w.title.Clear()
titlebarStyle := vaxis.Style{Attribute: vaxis.AttrBold}
titleStyle := vaxis.Style{Attribute: vaxis.AttrBold}
delimiterStyle := vaxis.Style{Attribute: vaxis.AttrDim}
if app.conn != nil {
@ -59,7 +53,7 @@ func (app *App) Redraw() {
segments := []vaxis.Segment{
{Text: "• "},
{Text: titleString, Style: titlebarStyle},
{Text: titleString, Style: titleStyle},
{Text: " │ ", Style: delimiterStyle},
{Text: fmt.Sprintf("↻ %s", rateString)},
}
@ -79,44 +73,17 @@ func (app *App) Redraw() {
app.vx.SetTitle("nanite (disconnected)")
app.w.title.PrintTruncate(0,
vaxis.Segment{Text: "✕ "},
vaxis.Segment{Text: "disconnected", Style: titlebarStyle},
vaxis.Segment{Text: "disconnected", Style: titleStyle},
)
}
app.vx.Render()
}
func (app *App) HandleTerminalEvent(ev vaxis.Event) {
app.dirty = true
switch ev := ev.(type) {
case vaxis.Mouse:
switch ev.Button {
case vaxis.MouseWheelUp:
app.pager.ScrollUpN(2)
case vaxis.MouseWheelDown:
app.pager.ScrollDownN(2)
}
case vaxis.Resize:
app.resize()
case vaxis.Key:
if ev.MatchString("ctrl+c") {
app.stop()
}
switch {
case ev.MatchString("up"):
app.pager.ScrollUp()
case ev.MatchString("down"):
app.pager.ScrollDown()
case ev.MatchString("ctrl+p"):
app.outgoing <- ManualPoll(app.last)
case ev.MatchString("ctrl+l"):
app.Redraw()
app.vx.Refresh()
app.dirty = false
case ev.MatchString("enter"):
func (app *App) submitTextInput() {
if len(app.input.Characters()) == 0 {
break
return
}
if app.input.Characters()[0].Grapheme == "/" {
name, rest, _ := strings.Cut(app.input.String()[1:], " ")
if cmd, ok := CommandMap[name]; ok {
@ -132,7 +99,35 @@ func (app *App) HandleTerminalEvent(ev vaxis.Event) {
}
app.input.SetContent("")
}
func (app *App) HandleTerminalEvent(ev vaxis.Event) {
switch ev := ev.(type) {
case vaxis.Key:
switch ev.String() {
case "Up":
app.pager.ScrollUp()
case "Down":
app.pager.ScrollDown()
case "Enter":
app.submitTextInput()
case "Ctrl+p":
app.outgoing <- ManualPoll(app.last)
case "Ctrl+l":
app.Redraw()
app.vx.Refresh()
case "Ctrl+c":
app.stop()
}
case vaxis.Mouse:
switch ev.Button {
case vaxis.MouseWheelUp:
app.pager.ScrollUpN(2)
case vaxis.MouseWheelDown:
app.pager.ScrollDownN(2)
}
case vaxis.Resize:
app.resize()
}
app.input.Update(ev)

View file

@ -76,7 +76,6 @@ type Stat string
func (data Stat) HandleIncoming(app *App) {
app.stats = string(data)
app.dirty = true
}
func (_ Stat) HandleOutgoing(app *App) error {
res, err := app.Stat()

View file

@ -90,7 +90,6 @@ type App struct {
}
pager *pager.Model
input *textinput.Model
dirty bool
}
func (app *App) Connect(host, port string) (err error) {
@ -168,7 +167,6 @@ func (app *App) AppendMessage(data string) {
)
app.last += 1
app.pager.Offset = math.MaxInt
app.dirty = true
}
func (app *App) AppendSystemMessage(format string, args ...any) {
@ -179,7 +177,6 @@ func (app *App) AppendSystemMessage(format string, args ...any) {
vaxis.Segment{Text: "\n"},
)
app.pager.Offset = math.MaxInt
app.dirty = true
}
func (app *App) SetNick(nick string) {

View file

@ -111,17 +111,14 @@ func (m *Model) layoutSlow() {
total += char.Width
}
switch {
case total > cols:
case total+col > cols:
if total > cols || total+col > cols {
m.lines = append(m.lines, l)
l = &line{}
col = 0
default:
}
for _, char := range chars {
if uniseg.HasTrailingLineBreakInString(char.Grapheme) {
if uniseg.HasTrailingLineBreakInString(char.Grapheme) && col != 0 {
m.lines = append(m.lines, l)
l = &line{}
col = 0