v0.4.0 terminal over caller's backend
This commit is contained in:
3 files changed
+28
No files matched your search
@@ -35,6 +35,11 @@ consoles with VT processing, and browsers via xterm.js (WASM builds).
|
|||||||
Shared code carries no build tags: cell diffing, ANSI generation, escape parsing.
|
Shared code carries no build tags: cell diffing, ANSI generation, escape parsing.
|
||||||
Platform specifics are isolated in the `Backend` implementations.
|
Platform specifics are isolated in the `Backend` implementations.
|
||||||
|
|
||||||
|
`NewWithBackend(b, mode)` builds a Terminal over a `Backend` of the caller's
|
||||||
|
own: a pipe, an in-process emulator or a test standing in for the tty. It
|
||||||
|
behaves as `New`'s Terminal does, the writer goroutine included; `New` is
|
||||||
|
`NewWithBackend` over the platform's backend and the detected color mode.
|
||||||
|
|
||||||
### Rendering pipeline
|
### Rendering pipeline
|
||||||
|
|
||||||
The application owns a flat `[]Cell` buffer (row-major, `cells[y*width+x]`) and
|
The application owns a flat `[]Cell` buffer (row-major, `cells[y*width+x]`) and
|
||||||
|
|||||||
@@ -156,6 +156,14 @@ func New(colorMode ...ColorMode) Terminal {
|
|||||||
c = ColorModeNone
|
c = ColorModeNone
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NewWithBackend(b, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewWithBackend creates a Terminal over b in color mode c, for a pipe, an
|
||||||
|
// in-process emulator or a test standing in for the tty. b must not be nil;
|
||||||
|
// the Terminal calls its Init on Init and its Fini on Fini, and writes to it
|
||||||
|
// on its own goroutine as New's does
|
||||||
|
func NewWithBackend(b Backend, c ColorMode) Terminal {
|
||||||
return newTerm(b, c)
|
return newTerm(b, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -376,3 +376,18 @@ func waitFor(t *testing.T, what string, ok func() bool) {
|
|||||||
time.Sleep(time.Millisecond)
|
time.Sleep(time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A Terminal built over a caller's backend draws a flushed frame to it
|
||||||
|
func TestNewWithBackendFlushesToTheBackend(t *testing.T) {
|
||||||
|
f := &fakeBackend{}
|
||||||
|
term := NewWithBackend(f, ColorMode256)
|
||||||
|
if err := term.Init(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer term.Fini()
|
||||||
|
if term.ColorMode() != ColorMode256 {
|
||||||
|
t.Fatalf("color mode %v", term.ColorMode())
|
||||||
|
}
|
||||||
|
term.Flush([]Cell{{Rune: 'x'}}, 1, 1)
|
||||||
|
waitFor(t, "the frame to reach the backend", func() bool { return strings.Contains(f.written(), "x") })
|
||||||
|
}
|
||||||
Reference in new issue
Block a user