Files
bbs/internal/server/vt_test.go
T
Claude b20533e6ff Identify VT terminals as DEC's were asked
internal/vt asks an ANSI terminal everything at once (ENQ answerback,
DA1, DA2, XTVERSION, its cell size), with a cursor position report last
so the answers are complete when it comes, and reads them into a name
(XTVERSION, SyncTERM's CTerm, DEC models by DA2 and firmware, tmux,
screen, mintty, rxvt, xterm, VTE, the answerback, the VT class), a VT
level, sixel and color.  A terminal that is not ANSI is asked ESC Z: a
VT52 answers.

What it said changes what the caller gets: a VT without UTF-8 (not a
PC's CP437 BBS terminal) gets line drawing in DEC Special Graphics and
Latin-1 on a VT220 or later; a DEC monochrome terminal gets bold for
color; a VT52 its own escapes (VT52Writer) with its cursor keys ignored.
Sixel now comes from the same answers.  The name shows in the profile,
the log and the API's who (terminal).  A listener's vt = no asks nothing.

Also: the terminal type and rlogin's rate are set under the BBS's lock
(who's online reads them).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
2026-10-12 07:07:23 +00:00

78 lines
2.5 KiB
Go

package server
import (
"strings"
"testing"
"time"
"github.com/Neo-Desktop/bbs-sec/internal/ui3270"
)
// TestVT220: a VT220 on a raw line says what it is: it gets DEC line
// drawing and Latin-1, bold for colors, and shows as a VT220.
func TestVT220(t *testing.T) {
e := startFull(t, ui3270.Graphics{}, nil, screensOnly(map[string]string{"welcome.asc": "┌──┐ café ░\n"}),
&Listener{Name: "vt", Kind: "raw", Address: "vt.sock", ANSI: "auto", UTF8: "auto", Sixel: "auto", RIP: "auto", VT: "auto"})
d := e.dial("vt.sock")
d.expect("\x1b[6n")
d.send("\x1b[24;80R") // ANSI
d.expect("\x1b[!\x1b[6n")
d.send("\x1b[24;80R") // no RIP
d.expect("\x05\x1b[c\x1b[>c\x1b[>0q\x1b[16t\x1b[6n")
d.send("\x1b[?62;1;2;6;7;8;9c\x1b[>1;10;0c\x1b[24;80R")
d.expect("Name")
d.send("alice\r")
d.expect("Password: ")
d.send("alicepass1\r")
d.expect("\x1b(0lqqk\x1b(B caf\xe9 \x1b(0a\r\n\x1b(B")
d.expect("\x1b[1m[M]\x1b[0m") // bold, not yellow
d.expect("Command: ")
if n := e.b.Nodes(); len(n) != 1 || n[0].Terminal != "VT220" {
t.Errorf("nodes: %+v", n)
}
d.send("P")
d.expect("Terminal: VT220, 80x24, ANSI on, UTF-8 off, DEC graphics, sixel off, RIP off")
if strings.Contains(string(d.got), "\x1b[1;33m") {
t.Errorf("color to a VT220: %q", d.got)
}
}
// TestVT52: a terminal that does not answer ANSI's question but answers a
// VT52's identify gets the VT52's escapes and plain text.
func TestVT52(t *testing.T) {
e := start(t, nil, &Listener{Name: "vt", Kind: "raw", Address: "vt.sock", ANSI: "auto", RIP: "auto", VT: "auto"})
d := e.dial("vt.sock")
d.expect("\x1b[6n")
time.Sleep(10 * time.Millisecond) // no answer: not ANSI
d.expect("\x1bZ")
d.send("\x1b/Z")
d.expect("Name (or NEW): ")
d.send("alice\r")
d.expect("Password: ")
d.send("alicepass1\r")
d.expect("Command: ")
d.send("\x1bA") // a cursor key is no command
d.send("I")
d.expect("Sysop:")
d.expect("[Press a key]")
d.send(" ")
d.send("P")
d.expect("Terminal: VT52, 80x24")
if i := strings.Index(string(d.got), "\x1b["); i >= 0 {
t.Errorf("ANSI to a VT52: %q", d.got)
}
if n := e.b.Nodes(); len(n) != 1 || n[0].Terminal != "VT52" {
t.Errorf("nodes: %+v", n)
}
}
// TestVTPlain: a terminal that answers neither is plain, with the Z its
// VT52 question showed wiped.
func TestVTPlain(t *testing.T) {
e := start(t, nil, &Listener{Name: "vt", Kind: "raw", Address: "vt.sock", ANSI: "auto", VT: "auto"})
d := e.dial("vt.sock")
d.expect("\x1bZ")
d.expect("\r \r")
d.expect("Name (or NEW): ")
}