mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
PETSCII: internal/petscii translates what the text BBS writes for ANSI terminals (UTF-8, SGR colors, clearing, cursor movement, box drawing) into the C64's lower/upper case set and color codes, and reads its keys back (DEL, RETURN, shifted letters). A listener's petscii = yes makes every caller a Commodore, auto asks a non-ANSI caller to press DEL, and telnet terminal types like c64 or petscii are believed. Callers get 40 columns (80 for a C128 from the profile): one column menus and lists that fit. .seq display files are sent as they are; doors are not offered. RIPscrip: internal/rip writes RIPscrip 1.54 (MegaNums, drawing, button styles, buttons, text windows). rip = auto asks BBS terminals with ESC [ ! and a position report; a RIP terminal gets every menu, built-in or the sysop's, as a scene of buttons that send their keys, cleared on a choice, and .rip display files before .ans. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package textui
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/Neo-Desktop/bbs-sec/internal/bbs"
|
|
"github.com/Neo-Desktop/bbs-sec/internal/rip"
|
|
)
|
|
|
|
// choice is a menu's item.
|
|
type choice struct{ key, label string }
|
|
|
|
// menu shows a menu and reads its key: the title and items (unless list
|
|
// is false: a screen of the sysop's showed them) in two columns, or one
|
|
// on a narrow screen, or as buttons on a RIP terminal; then the prompt.
|
|
// Enter is '\r'.
|
|
func (s *session) menu(title string, items []choice, prompt string, list bool) (rune, error) {
|
|
t := s.t
|
|
if t.RIP && list {
|
|
// what the last choice printed is read before the buttons cover it
|
|
if t.sinceKey > 0 {
|
|
if err := t.Pause(); err != nil {
|
|
return 0, err
|
|
}
|
|
}
|
|
ri := make([]rip.Item, len(items))
|
|
for i, it := range items {
|
|
ri[i] = rip.Item{Key: it.key, Label: it.label}
|
|
}
|
|
scene, _ := rip.Menu(title, ri)
|
|
t.RIPScene(scene)
|
|
t.Print(strings.TrimLeft(prompt, "\n"))
|
|
} else {
|
|
if list {
|
|
t.Println("")
|
|
t.Println(t.C(Cyan, title))
|
|
cols, width := 2, 22
|
|
if t.Narrow() {
|
|
cols, width = 1, max(t.Cols-7, 10)
|
|
}
|
|
var cells []string
|
|
for _, it := range items {
|
|
cells = append(cells, t.C(Yellow, "["+it.key+"]")+" "+bbs.Fit(it.label, width))
|
|
}
|
|
for i := 0; i < len(cells); i += cols {
|
|
t.Println(" " + strings.Join(cells[i:min(i+cols, len(cells))], ""))
|
|
}
|
|
}
|
|
t.Print(prompt)
|
|
}
|
|
k, err := t.Key()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
if t.ripScene {
|
|
t.RIPClear()
|
|
} else if k != '\r' {
|
|
t.Println(string(k))
|
|
} else {
|
|
t.Println("")
|
|
}
|
|
return k, nil
|
|
}
|