mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-29 01:38:10 -08:00
Text screens (.asc, .txt), the [strings] and a menu's prompt take tags
such as {clear}, {pause}, {red}, {on blue}, {bright}, {underline} and
{reset}, as .3270 files take {color}: ANSI escape sequences on an ANSI
terminal, bold alone on one without color, a Commodore's colors through
the PETSCII translator, the clears and cursor moves on a VT52, nothing
on a plain terminal. A 3270 shows a text screen's color tags as its
colors and drops the rest, and .3270 files take the text terminals'
names (magenta, cyan, reset) and {clear}/{pause} too.
Only the sysop's text has tags: values of @-codes (a caller's name) are
never read for them. Strings carry their tags to the terminal as
control-character marks, which values cannot contain, and are dropped
wherever they cannot be shown (Who's online, the 3270). .3270 lines now
take their colors from those marks as well, so a caller named "{red}"
no longer colors a 3270 screen.
Text screens keep their lines' indentation (it was trimmed), and a line
holding only a clear or a pause leaves no blank line.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
package textui
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/Neo-Desktop/bbs-sec/internal/screens"
|
|
)
|
|
|
|
type bufConn struct{ bytes.Buffer }
|
|
|
|
func (*bufConn) SetReadDeadline(time.Time) error { return nil }
|
|
|
|
// TestCode: the sysop's tags as each terminal's escape sequences.
|
|
func TestCode(t *testing.T) {
|
|
ansi := NewTerm(&bufConn{})
|
|
ansi.ANSI = true
|
|
mono := NewTerm(&bufConn{})
|
|
mono.ANSI, mono.Mono = true, true
|
|
plain := NewTerm(&bufConn{})
|
|
vt52 := NewTerm(&bufConn{})
|
|
vt52.SetVT52()
|
|
for _, c := range []struct {
|
|
tag string
|
|
ansi, mono, plain, vt52 string
|
|
}{
|
|
{"red", "\x1b[31m", "", "", ""},
|
|
{"pink", "\x1b[35m", "", "", ""},
|
|
{"turquoise", "\x1b[36m", "", "", ""},
|
|
{"on blue", "\x1b[44m", "", "", ""},
|
|
{"bright", "\x1b[1m", "\x1b[1m", "", ""},
|
|
{"normal", "\x1b[22m", "\x1b[22m", "", ""},
|
|
{"underline", "\x1b[4m", "\x1b[4m", "", ""},
|
|
{"reset", "\x1b[0m", "\x1b[0m", "", ""},
|
|
{"clear", "\x1b[2J\x1b[H", "\x1b[2J\x1b[H", "\r\n", "\x1b[2J\x1b[H"},
|
|
{"eol", "\x1b[K", "\x1b[K", "", "\x1b[K"},
|
|
} {
|
|
for _, x := range []struct {
|
|
t *Term
|
|
want string
|
|
}{{ansi, c.ansi}, {mono, c.mono}, {plain, c.plain}, {vt52, c.vt52}} {
|
|
if got := x.t.Code(c.tag); got != x.want {
|
|
t.Errorf("%s: %q, want %q", c.tag, got, x.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Print turns marks into the terminal's codes, on a Commodore too
|
|
c := &bufConn{}
|
|
pet := NewTerm(c)
|
|
pet.SetPETSCII(true, 40)
|
|
c.Reset()
|
|
pet.Print(screens.Mark("red") + "HI" + screens.Mark("reset"))
|
|
pet.Flush()
|
|
// red (0x1c), the letters in PETSCII, then the default light grey
|
|
if out := c.String(); strings.ContainsAny(out, "\x1b\x1e\x1f") || len(out) != 4 || out[0] != 0x1c {
|
|
t.Errorf("PETSCII: %q", out)
|
|
}
|
|
c2 := &bufConn{}
|
|
a := NewTerm(c2)
|
|
a.ANSI = true
|
|
a.Print(screens.Mark("green") + "go" + screens.Mark("default"))
|
|
a.Flush()
|
|
if got := c2.String(); got != "\x1b[32mgo\x1b[0m" {
|
|
t.Errorf("ANSI: %q", got)
|
|
}
|
|
}
|