1 Commits
Author SHA1 Message Date
sneak aace2b4549 Show the neoirc-cli screen without waiting at start-up (closes #226)
check / check (push) Canceled after 0s
Run added the start-up status bar and welcome lines through
SetStatus and AddStatus before it started the tview event loop. Both
wait for that loop, so neoirc-cli stopped before it showed its
screen. They now run on a goroutine, as typed lines do.

Run now passes a new UI to run, which holds the start-up path and
returns its error. TestStartUp calls run with a simulation screen. It
fails unless, within five seconds, the status window holds two lines:
first the one with "Welcome to neoirc-cli", then the /connect hint.

Model: opus-5-5
2026-11-02 00:44:41 +00:00
+27 -8
View File
@@ -4,6 +4,8 @@ import (
"io" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"slices"
"strings"
"testing" "testing"
"time" "time"
@@ -359,7 +361,8 @@ func TestLinesKeepOrder(t *testing.T) {
// TestStartUp runs the client's start-up path on a simulation // TestStartUp runs the client's start-up path on a simulation
// screen. It fails unless the event loop starts and the status // screen. It fails unless the event loop starts and the status
// window gets the welcome lines. // window gets two lines: first the one that holds "Welcome to
// neoirc-cli", then the /connect hint.
func TestStartUp(t *testing.T) { func TestStartUp(t *testing.T) {
t.Parallel() t.Parallel()
@@ -386,16 +389,22 @@ func TestStartUp(t *testing.T) {
}) })
// run adds the welcome lines on a goroutine, so the status // run adds the welcome lines on a goroutine, so the status
// window is read until they are there. Each read waits for // window is read until it holds two lines. Each read waits for
// the event loop, so the reads run on a goroutine too, which // the event loop, so the reads run on a goroutine too, which
// this test stops waiting for after eventLoopTimeout. // this test stops waiting for after eventLoopTimeout. The
shown := make(chan struct{}) // channel has one slot, so that goroutine can still end.
shown := make(chan []string, 1)
go func() { go func() {
for { for {
lines, _ := bufferState(ui, "(status)") var lines []string
if lines == welcomeLines {
close(shown) ui.app.QueueUpdate(func() {
lines = slices.Clone(ui.getOrCreateBuffer("(status)").Lines)
})
if len(lines) == welcomeLines {
shown <- lines
return return
} }
@@ -404,12 +413,22 @@ func TestStartUp(t *testing.T) {
} }
}() }()
var lines []string
select { select {
case <-shown: case lines = <-shown:
case <-time.After(eventLoopTimeout): case <-time.After(eventLoopTimeout):
t.Fatalf("the status window did not get the welcome lines within %v", t.Fatalf("the status window did not get the welcome lines within %v",
eventLoopTimeout) eventLoopTimeout)
} }
if !strings.Contains(lines[0], "Welcome to neoirc-cli") {
t.Errorf("first status line is %q, want the welcome line", lines[0])
}
if !strings.Contains(lines[1], "/connect <server-url>") {
t.Errorf("second status line is %q, want the /connect hint", lines[1])
}
} }
// TestOwnEventFromOtherClient checks that a message, notice, // TestOwnEventFromOtherClient checks that a message, notice,