Compare commits
2
Commits
87d65552e3
...
ee8df052ec
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee8df052ec | ||
|
|
2b1a49e59b |
No files matched your search
+7
-1
@@ -402,10 +402,16 @@ func (a *App) cmdQuery(nick string) {
|
|||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
a.target = nick
|
a.target = nick
|
||||||
myNick := a.nick
|
myNick := a.nick
|
||||||
|
connected := a.connected
|
||||||
a.mu.Unlock()
|
a.mu.Unlock()
|
||||||
|
|
||||||
|
connStatus := "disconnected"
|
||||||
|
if connected {
|
||||||
|
connStatus = "connected"
|
||||||
|
}
|
||||||
|
|
||||||
a.ui.SwitchToBuffer(nick)
|
a.ui.SwitchToBuffer(nick)
|
||||||
a.ui.SetStatus(myNick, nick, "connected")
|
a.ui.SetStatus(myNick, nick, connStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) cmdTopic(args string) {
|
func (a *App) cmdTopic(args string) {
|
||||||
|
|||||||
@@ -23,6 +23,13 @@ const (
|
|||||||
testText = "hello"
|
testText = "hello"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// What the status bar shows while the client is connected, and
|
||||||
|
// while it is not.
|
||||||
|
const (
|
||||||
|
statusConnected = "[connected]"
|
||||||
|
statusDisconnected = "[disconnected]"
|
||||||
|
)
|
||||||
|
|
||||||
// eventLoopTimeout is how long a test waits for a typed line to
|
// eventLoopTimeout is how long a test waits for a typed line to
|
||||||
// be handled, for the welcome lines, for the UI to stop, for a poll
|
// be handled, for the welcome lines, for the UI to stop, for a poll
|
||||||
// or for a poll loop to end, before it fails.
|
// or for a poll loop to end, before it fails.
|
||||||
@@ -326,19 +333,19 @@ func TestWindowConnectionState(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "typed line, not connected", send: typeLine,
|
name: "typed line, not connected", send: typeLine,
|
||||||
connected: false, want: "[disconnected]",
|
connected: false, want: statusDisconnected,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Alt and 0, not connected", send: pressAltZero,
|
name: "Alt and 0, not connected", send: pressAltZero,
|
||||||
connected: false, want: "[disconnected]",
|
connected: false, want: statusDisconnected,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "typed line, connected", send: typeLine,
|
name: "typed line, connected", send: typeLine,
|
||||||
connected: true, want: "[connected]",
|
connected: true, want: statusConnected,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Alt and 0, connected", send: pressAltZero,
|
name: "Alt and 0, connected", send: pressAltZero,
|
||||||
connected: true, want: "[connected]",
|
connected: true, want: statusConnected,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,6 +368,46 @@ func TestWindowConnectionState(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestQueryConnectionState checks that typing /query bob leaves the
|
||||||
|
// status bar showing [connected] only while the client is connected,
|
||||||
|
// and [disconnected] otherwise.
|
||||||
|
func TestQueryConnectionState(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
const line = "/query " + testOtherNick
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
connected bool
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{name: "not connected", connected: false, want: statusDisconnected},
|
||||||
|
{name: "connected", connected: true, want: statusConnected},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
app := &App{ui: NewUI(), nick: testNick, connected: test.connected}
|
||||||
|
handled := handledLines(app)
|
||||||
|
runUI(t, app.ui)
|
||||||
|
|
||||||
|
for _, r := range line {
|
||||||
|
app.ui.app.QueueEvent(tcell.NewEventKey(tcell.KeyRune, r, tcell.ModNone))
|
||||||
|
}
|
||||||
|
|
||||||
|
app.ui.app.QueueEvent(tcell.NewEventKey(tcell.KeyEnter, 0, tcell.ModNone))
|
||||||
|
waitHandled(t, handled, line)
|
||||||
|
|
||||||
|
status := statusBarText(app.ui)
|
||||||
|
if !strings.Contains(status, test.want) {
|
||||||
|
t.Fatalf("status bar is %q, want it to show %s", status, test.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestEventLoopKeepsRunning sends Alt and 1, then a typed line and
|
// TestEventLoopKeepsRunning sends Alt and 1, then a typed line and
|
||||||
// Enter, to a running UI. It checks that both are handled, so the
|
// Enter, to a running UI. It checks that both are handled, so the
|
||||||
// event loop did not stop on either.
|
// event loop did not stop on either.
|
||||||
@@ -682,7 +729,7 @@ func TestStartUp(t *testing.T) {
|
|||||||
|
|
||||||
// run sets the status bar before it adds the welcome lines.
|
// run sets the status bar before it adds the welcome lines.
|
||||||
status := statusBarText(ui)
|
status := statusBarText(ui)
|
||||||
if !strings.Contains(status, "[disconnected]") {
|
if !strings.Contains(status, statusDisconnected) {
|
||||||
t.Errorf("status bar is %q, want it to show [disconnected]", status)
|
t.Errorf("status bar is %q, want it to show [disconnected]", status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -752,6 +799,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,
|
// TestOwnEventFromOtherClient checks that a message, notice,
|
||||||
// join or part that the user's session makes from another
|
// join or part that the user's session makes from another
|
||||||
// client shows as one line in the buffer it belongs to.
|
// client shows as one line in the buffer it belongs to.
|
||||||
|
|||||||
+14
-2
@@ -30,6 +30,12 @@ type UI struct {
|
|||||||
buffers []*Buffer
|
buffers []*Buffer
|
||||||
currentBuffer int
|
currentBuffer int
|
||||||
|
|
||||||
|
// The nick, target and connection state last passed to
|
||||||
|
// SetStatus.
|
||||||
|
nick string
|
||||||
|
target string
|
||||||
|
connStatus string
|
||||||
|
|
||||||
onInput func(string)
|
onInput func(string)
|
||||||
// inputDone is closed once the line last passed to onInput
|
// inputDone is closed once the line last passed to onInput
|
||||||
// has been handled. Only callOnInput, on the event loop, uses
|
// has been handled. Only callOnInput, on the event loop, uses
|
||||||
@@ -179,7 +185,11 @@ func (ui *UI) SetStatus(
|
|||||||
nick, target, connStatus string,
|
nick, target, connStatus string,
|
||||||
) {
|
) {
|
||||||
ui.app.QueueUpdateDraw(func() {
|
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() {
|
func (ui *UI) refreshStatusBar() {
|
||||||
// Placeholder; full refresh needs nick/target context.
|
ui.renderStatusBar(ui.nick, ui.target, ui.connStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *UI) renderStatusBar(
|
func (ui *UI) renderStatusBar(
|
||||||
|
|||||||
Reference in new issue
Block a user