Redraw the status bar when a line arrives in another window (closes #232) #243
@@ -752,6 +752,31 @@ func TestStatusBar(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestUnreadLine checks that a line added to a window that is not
|
||||
// shown puts that window in the status bar's unread list at once,
|
||||
// and that the status bar keeps the nick, target and connection
|
||||
// state last set.
|
||||
func TestUnreadLine(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ui := NewUI()
|
||||
runUI(t, ui)
|
||||
|
||||
// Window 1, the one shown, is the channel's. The line goes to
|
||||
// window 2 after SetStatus, so only AddLine can show it in the
|
||||
// status bar.
|
||||
ui.SwitchToBuffer(testChannel)
|
||||
ui.SetStatus(testNick, testChannel, "connected")
|
||||
ui.AddLine(testOtherNick, testText)
|
||||
|
||||
const want = " [connected] erin [1:#chan] #chan [Act: 2:bob(1)]"
|
||||
|
||||
got := statusBarText(ui)
|
||||
if got != want {
|
||||
t.Fatalf("status bar is %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestOwnEventFromOtherClient checks that a message, notice,
|
||||
// join or part that the user's session makes from another
|
||||
// client shows as one line in the buffer it belongs to.
|
||||
|
||||
+14
-2
@@ -30,6 +30,12 @@ type UI struct {
|
||||
buffers []*Buffer
|
||||
currentBuffer int
|
||||
|
||||
// The nick, target and connection state last passed to
|
||||
// SetStatus.
|
||||
nick string
|
||||
target string
|
||||
connStatus string
|
||||
|
||||
onInput func(string)
|
||||
// inputDone is closed once the line last passed to onInput
|
||||
// has been handled. Only callOnInput, on the event loop, uses
|
||||
@@ -179,7 +185,11 @@ func (ui *UI) SetStatus(
|
||||
nick, target, connStatus string,
|
||||
) {
|
||||
ui.app.QueueUpdateDraw(func() {
|
||||
ui.renderStatusBar(nick, target, connStatus)
|
||||
ui.nick = nick
|
||||
ui.target = target
|
||||
ui.connStatus = connStatus
|
||||
|
||||
ui.refreshStatusBar()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -300,8 +310,10 @@ func (ui *UI) callOnInput(text string) {
|
||||
}()
|
||||
}
|
||||
|
||||
// refreshStatusBar redraws the status bar with the nick, target
|
||||
// and connection state last passed to SetStatus.
|
||||
func (ui *UI) refreshStatusBar() {
|
||||
// Placeholder; full refresh needs nick/target context.
|
||||
ui.renderStatusBar(ui.nick, ui.target, ui.connStatus)
|
||||
}
|
||||
|
||||
func (ui *UI) renderStatusBar(
|
||||
|
||||
Reference in New Issue
Block a user