Fixed race condition for reading changed screen in console. Means we shouldn't be hearing all those random space characters any more.
This commit is contained in:
1 parent
6a02035373
commit
b96d7f270d
6 files changed
+162
-4
No files matched your search
@@ -5,6 +5,7 @@ package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -16,6 +17,46 @@ import (
|
||||
"git.stormux.org/storm/fenrir/internal/screen"
|
||||
)
|
||||
|
||||
func TestUnstableCapturePreservesTypingAndReaderState(t *testing.T) {
|
||||
source := &fakeSource{snapshot: screen.Snapshot{Terminal: 2, Active: true, Rows: 1, Cols: 5, X: 2, Cells: []rune("$ ")}}
|
||||
voice := &fakeVoice{}
|
||||
a, err := newApplication(context.Background(), source, &fakeKeys{}, voice, RunOptions{Settings: config.Defaults()})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(a.ui.close)
|
||||
if err := a.readScreen(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
voice.messages = nil
|
||||
a.engine.NoteInput(true, true, false)
|
||||
source.readErr = fmt.Errorf("%w: console cursor moved", screen.ErrChanged)
|
||||
if err := a.readScreen(); err != nil {
|
||||
t.Fatal("unstable capture stopped the reader", err)
|
||||
}
|
||||
if !a.lastActive || a.lastTerminal != 2 || a.lastSnapshot.X != 2 || len(voice.messages) != 0 {
|
||||
t.Fatal("unstable capture changed reader state", a.lastSnapshot, voice.messages)
|
||||
}
|
||||
source.readErr = nil
|
||||
source.snapshot.X = 3
|
||||
source.snapshot.Cells = []rune("$ r ")
|
||||
if err := a.readScreen(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(voice.messages, []string{"r"}) {
|
||||
t.Fatal("retry lost typing feedback", voice.messages)
|
||||
}
|
||||
voice.messages = nil
|
||||
a.engine.NoteInput(true, false, false)
|
||||
source.snapshot.X = 4
|
||||
if err := a.readScreen(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(voice.messages, []string{"space"}) {
|
||||
t.Fatal("real cursor navigation lost space feedback", voice.messages)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoginPromptStartupAndDelayedActivation(t *testing.T) {
|
||||
for _, terminal := range []int{1, 2} {
|
||||
// tty1 already has its boot login prompt. tty2's login program
|
||||
|
||||
@@ -18,12 +18,14 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.stormux.org/storm/fenrir/internal/diagnostic"
|
||||
"git.stormux.org/storm/fenrir/internal/i18n"
|
||||
"git.stormux.org/storm/fenrir/internal/presentation"
|
||||
"git.stormux.org/storm/fenrir/internal/screen"
|
||||
"git.stormux.org/storm/fenrir/internal/spellcheck"
|
||||
)
|
||||
|
||||
@@ -31,6 +33,9 @@ func (a *application) readScreen() error {
|
||||
started := time.Now()
|
||||
snapshot, err := a.source.Read()
|
||||
diagnostic.Timing("screen capture", started)
|
||||
if errors.Is(err, screen.ErrChanged) {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user