From fb291b6deface105667604fdaa8f6d8fcf4936b2 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Wed, 25 Dec 2024 22:18:30 +0100 Subject: Improve the terminal filter The new filter comes with these enhancements: - Processing is rune-wise rather than byte-wise; it assumes UTF-8 input and single-cell wide characters, but this condition should be /usually/ satisfied. - Unprocessed control characters are escaped, `cat -v` style. - A lot of escape sequences is at least recognised, if not processed. - Rudimentary preparation for efficient dynamic updates of task views, through Javascript. We make terminal resets and screen clearing commands flush all output and assume that the terminal has a new origin for any later positioning commands. This appears to work well enough with GRUB, at least. The filter is now exposed through a command line option. --- terminal_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 terminal_test.go (limited to 'terminal_test.go') diff --git a/terminal_test.go b/terminal_test.go new file mode 100644 index 0000000..d3fcf45 --- /dev/null +++ b/terminal_test.go @@ -0,0 +1,44 @@ +package main + +import "testing" + +// TODO(p): Add a lot more test cases. +var tests = []struct { + push, want string +}{ + { + "\x1bc\x1b[?7l\x1b[2J\x1b[0mSeaBIOS\r", + "SeaBIOS\n", + }, +} + +func TestTerminal(t *testing.T) { + for _, test := range tests { + tw := terminalWriter{} + if _, err := tw.Write([]byte(test.push)); err != nil { + t.Errorf("%#v: %s", test.push, err) + continue + } + have := string(tw.Serialize(0)) + if have != test.want { + t.Errorf("%#v: %#v; want %#v", test.push, have, test.want) + } + } +} + +func TestTerminalExploded(t *testing.T) { +Loop: + for _, test := range tests { + tw := terminalWriter{} + for _, b := range []byte(test.push) { + if _, err := tw.Write([]byte{b}); err != nil { + t.Errorf("%#v: %s", test.push, err) + continue Loop + } + } + have := string(tw.Serialize(0)) + if have != test.want { + t.Errorf("%#v: %#v; want %#v", test.push, have, test.want) + } + } +} -- cgit v1.2.3-70-g09d2