rendering changes, no more "dirty"
This commit is contained in:
parent
13d57534a6
commit
d69f375a57
4 changed files with 43 additions and 55 deletions
87
display.go
87
display.go
|
|
@ -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,16 +73,52 @@ 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
|
||||
func (app *App) submitTextInput() {
|
||||
if len(app.input.Characters()) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if app.input.Characters()[0].Grapheme == "/" {
|
||||
name, rest, _ := strings.Cut(app.input.String()[1:], " ")
|
||||
if cmd, ok := CommandMap[name]; ok {
|
||||
cmd(app, rest)
|
||||
} else {
|
||||
app.AppendSystemMessage("unknown command \"%s\"", name)
|
||||
}
|
||||
} else {
|
||||
message := fmt.Sprintf("%s: %s", app.nick, app.input.String())
|
||||
app.AppendMessage(message)
|
||||
app.outgoing <- Message(message)
|
||||
app.outgoing <- Stat("")
|
||||
}
|
||||
|
||||
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:
|
||||
|
|
@ -98,41 +128,6 @@ func (app *App) HandleTerminalEvent(ev vaxis.Event) {
|
|||
}
|
||||
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"):
|
||||
if len(app.input.Characters()) == 0 {
|
||||
break
|
||||
}
|
||||
if app.input.Characters()[0].Grapheme == "/" {
|
||||
name, rest, _ := strings.Cut(app.input.String()[1:], " ")
|
||||
if cmd, ok := CommandMap[name]; ok {
|
||||
cmd(app, rest)
|
||||
} else {
|
||||
app.AppendSystemMessage("unknown command \"%s\"", name)
|
||||
}
|
||||
} else {
|
||||
message := fmt.Sprintf("%s: %s", app.nick, app.input.String())
|
||||
app.AppendMessage(message)
|
||||
app.outgoing <- Message(message)
|
||||
app.outgoing <- Stat("")
|
||||
}
|
||||
|
||||
app.input.SetContent("")
|
||||
}
|
||||
}
|
||||
|
||||
app.input.Update(ev)
|
||||
|
|
|
|||
1
event.go
1
event.go
|
|
@ -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()
|
||||
|
|
|
|||
3
main.go
3
main.go
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue