mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
Setup screens in the style of 1990s BBS setup programs
The configuration screens (bbs config, and the sysop's Configuration) on an ANSI terminal are now a shaded blue desk with a menu bar of pull-down menus, each menu a window cascading over the one it was opened from, the line's help in a box below and the keys on a bar at the foot. Values are typed in boxes that pop up, choices picked from lists, and questions, help and the save's report come up as dialogs. Only the cells that change are sent, and a terminal without UTF-8 gets code page 437. The menus now reach every front end: Online services (AOL, CompuServe, MSN 1995), Messengers and chat (AIM/ICQ, MSN Messenger, Yahoo!, IRC and its links, MRC), E-mail, Networks and doors, and Time, beside Internet services. The pull-down menus jump to any of them from anywhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRUCKaoTaTTA2EiiN7Z
This commit is contained in:
14 files changed
+2292
-309
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 295 KiB |
@@ -62,21 +62,36 @@ password.
|
||||
|
||||
## Editing it: the configuration screens
|
||||
|
||||
`bbs -config /etc/bbs/bbs.conf config` opens full-screen menus on your
|
||||
`bbs -config /etc/bbs/bbs.conf config` opens the setup screens on your
|
||||
terminal for editing the file and the accounts, whether or not the BBS is
|
||||
running. The same menus are in the [sysop tools](Sysop-Tools) (`F`,
|
||||
Configuration). They are full screen on ANSI terminals, use PF keys on a
|
||||
3270, and become numbered lines on a terminal with neither.
|
||||
running. The same screens are in the [sysop tools](Sysop-Tools) (`F`,
|
||||
Configuration). On an ANSI terminal they look like the BBS setup programs
|
||||
of the 1990s: a menu bar of pull-down menus, a shaded blue desk, each menu
|
||||
a window over the one it was opened from, the line's help in a box below,
|
||||
and values changed in boxes that pop up. They use PF keys on a 3270, and
|
||||
become numbered lines on a terminal with neither.
|
||||
|
||||
<img src="https://raw.githubusercontent.com/D-Modem/bbs/main/.github/config-screens.png" alt="The setup screens: the Online pull-down menu over the main menu" width="100%">
|
||||
|
||||
| Menu | What is in it |
|
||||
|---|---|
|
||||
| Board configuration | the BBS's name, the sysop's, the location, postal address, dial-in numbers and internet addresses; the banner, message of the day, goodbye, logo; menus and prompts |
|
||||
| System configuration | the user and group it runs as; the database and log; where files are kept and how large they may be; deny lists, the hack log, bans; scheduled events; every section of the file as it is |
|
||||
| Connections and modems | modem lines and every listener; callers at once, logins, time-outs, lock-outs; passwords by modemmenu's auth socket ([Modem callers](Modem-Callers#the-same-password-for-telnet-ssh-and-the-web)); the caller ID country and GeoIP |
|
||||
| Services | telnet, TN3270, SSH and RLogin listeners; finger, gopher, Gemini, FTP, IRC, news, the web (API, forum, image boards); MRC, FidoNet, QWK networks, doors |
|
||||
| Internet services | telnet, TN3270, SSH and RLogin listeners; finger, gopher, Gemini, FTP, news, the web (API, forum, image boards) |
|
||||
| Online services | [AOL](AOL), [CompuServe](CompuServe) (its listeners) and [The Microsoft Network](MSN-Classic) (its TCP host and dial-in listeners) |
|
||||
| Messengers and chat | [AIM and ICQ](AIM-and-ICQ), [MSN Messenger](MSN-Messenger), [Yahoo! Messenger](Yahoo-Messenger), the [IRC](IRC) server, [IRC network links](IRC-Linking) and their peers, [MRC](MRC) |
|
||||
| E-mail | [`[mail]`](E-mail), the smarthost, POP3, IMAP, SMTP submission, MX and LMTP |
|
||||
| Networks and doors | [FidoNet](FidoNet) and binkp, QWK networks, doors |
|
||||
| Time | the clock and its sources, and the NTP, NTS-KE and PTP servers ([Time](Time)) |
|
||||
| Users and groups | the accounts (level, flags, sysop, locked, a new password; new ones; deleted ones) and the access levels |
|
||||
| Maintenance | disk space; what message areas keep, old messages taken out; the image boards' archive; backups: one now, those made, `[backup]` ([Backups](Backups)) |
|
||||
|
||||
The menu bar's pull-down menus (`/`, F12, or Alt and the menu's red
|
||||
letter) go straight to any of these from anywhere: File (review, check,
|
||||
save, quit), Setup, Lines, Internet, Online (the online services and the
|
||||
messengers), Mail, Networks, Time and Help.
|
||||
|
||||
System passwords (PAM, LDAP) are checked by modemmenu, which logs callers
|
||||
in and hands them to the BBS (see [Modem callers](Modem-Callers)). Running
|
||||
the BBS as a user of its own (System configuration's Run as user) is
|
||||
@@ -85,13 +100,21 @@ covered in [Running](Running#running-as-a-user-of-its-own).
|
||||
| Key | What it does |
|
||||
|---|---|
|
||||
| arrows, PgUp, PgDn, Home, End | move (a letter goes to the next line beginning with it) |
|
||||
| Enter | open a menu, change a value (typed on the foot line, Enter to keep it), do an action |
|
||||
| Enter | open a menu, change a value (typed in a box that pops up, or picked from a list of its choices), do an action |
|
||||
| Space | turn a yes/no over, or go to the next choice |
|
||||
| Esc, left arrow | back |
|
||||
| Esc, left arrow | back a window |
|
||||
| `/`, F12, Alt+letter | the menu bar's pull-down menus (arrows between them, Enter to go) |
|
||||
| F1 or `?` | the whole help for the line (from bbs.conf.sample) |
|
||||
| F9 | quit without saving (after a yes, if anything changed) |
|
||||
| F10 | save and exit |
|
||||
| `A`, `D` | add one (a listener, a door, a user ...), delete it |
|
||||
| Ctrl-L | draw the screen again |
|
||||
|
||||
In a box where a value is typed, the arrows, Home and End move, Ctrl-U
|
||||
clears it, Enter keeps it and Esc leaves the value as it was. The screens
|
||||
are sent a changed cell at a time, so moving the bar costs a modem caller
|
||||
a few bytes, and a terminal without UTF-8 gets code page 437's lines and
|
||||
shading.
|
||||
|
||||
On a 3270, type `S` beside a menu to open it, type over values and send
|
||||
them with Enter; PF1 is help, PF3 goes back, and PF9 and PF10 work like F9
|
||||
@@ -99,7 +122,7 @@ and F10. On a terminal without ANSI, type a line's number to open or change
|
||||
it, `S` to save and exit, or `X` to leave without saving.
|
||||
|
||||
Nothing changes until you save. A changed line is marked `*`, and the
|
||||
bottom line counts the unsaved changes. The main menu's Review changes
|
||||
help box counts the unsaved changes. The main menu's Review changes
|
||||
lists them all, and Check the configuration reads the file as the BBS
|
||||
would.
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ any terminal, although watching a node needs a text terminal.
|
||||
| statistics | `S` | totals (users, messages, mail, files; logins, posts, pages and failed logins since the start), and calls, new users, posts and uploads for each of the last 14 days, as bars |
|
||||
| hack log and bans | `H` | the addresses banned now (a number lifts its ban), and `L` the [hack log](Security#keeping-callers-out)'s last 100 lines |
|
||||
| scheduled events | `E` | the events, when they run next and how their last run went; one's command and output, and `R` runs it now |
|
||||
| configuration | `F` | the configuration menus: the board, the system, connections, services, users and groups, maintenance; nothing changes until F10 saves (F9 quits), and then what may change while callers are on is put in force at once ([Configuration](Configuration#editing-it-the-configuration-screens)). Shown when the BBS runs with `-config` |
|
||||
| configuration | `F` | the setup screens (blue windows and pull-down menus on ANSI terminals): the board, the system, connections, internet and online services, messengers, e-mail, networks, time, users and groups, maintenance; nothing changes until F10 saves (F9 quits), and then what may change while callers are on is put in force at once ([Configuration](Configuration#editing-it-the-configuration-screens)). Shown when the BBS runs with `-config` |
|
||||
| available | `A` | whether pages reach you; when not, a caller who pages is told you are not available and may leave you a message |
|
||||
|
||||
Validating new users stays on the main menu (`V`, when some wait).
|
||||
|
||||
@@ -41,7 +41,10 @@ type Editor struct {
|
||||
|
||||
db *data // the accounts and areas, as read and as changed (nil: not read yet)
|
||||
crumbs []string
|
||||
flash string // a word for the next screen's foot
|
||||
trail []string // the label of the item each page in crumbs was opened by ("": the first, or not by one)
|
||||
via string // the label of the item opening a page now
|
||||
jump []string // where a pull-down menu's item goes: labels of items to open from the first page
|
||||
flash string // a word for the next screen's foot
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -53,11 +56,14 @@ var (
|
||||
// Run shows the screens until the sysop saves or leaves.
|
||||
func (e *Editor) Run() error {
|
||||
e.cat = confedit.NewCatalog(bbssec.Sample)
|
||||
if se, ok := e.UI.(view.SheetEnder); ok {
|
||||
defer se.EndSheets()
|
||||
}
|
||||
if ok, err := e.load(); err != nil || !ok {
|
||||
return err
|
||||
}
|
||||
for {
|
||||
e.crumbs = nil
|
||||
e.crumbs, e.trail, e.jump = nil, nil, nil
|
||||
err := e.show(e.mainMenu())
|
||||
switch {
|
||||
case err == nil || errors.Is(err, errQuit):
|
||||
@@ -121,6 +127,7 @@ func (e *Editor) load() (bool, error) {
|
||||
type item struct {
|
||||
view.Entry
|
||||
open func() error // EntryMenu: another page
|
||||
sub func() page // and that page, where it is known (for the pull-down menus)
|
||||
set func(v string) error // a value's
|
||||
do func() error // EntryAction
|
||||
help string // the whole help, for F1 (Entry.Help: its first line)
|
||||
@@ -141,12 +148,61 @@ type page struct {
|
||||
// back a page (nil).
|
||||
func (e *Editor) show(p page) error {
|
||||
e.crumbs = append(e.crumbs, p.title)
|
||||
defer func() { e.crumbs = e.crumbs[:len(e.crumbs)-1] }()
|
||||
e.trail = append(e.trail, e.via)
|
||||
e.via = ""
|
||||
defer func() {
|
||||
e.crumbs = e.crumbs[:len(e.crumbs)-1]
|
||||
e.trail = e.trail[:len(e.trail)-1]
|
||||
}()
|
||||
cursor := 0
|
||||
for {
|
||||
its := p.items()
|
||||
if e.jump != nil {
|
||||
// a pull-down's item: back to where its path and this page's
|
||||
// meet, then on down it
|
||||
at := e.trail[1:]
|
||||
if len(at) > len(e.jump) || !prefix(at, e.jump) {
|
||||
return nil
|
||||
}
|
||||
if len(at) == len(e.jump) {
|
||||
e.jump = nil
|
||||
} else {
|
||||
next, last := e.jump[len(at)], len(at) == len(e.jump)-1
|
||||
i := -1
|
||||
for j, it := range its {
|
||||
if it.Label == next && it.Choosable() {
|
||||
i = j
|
||||
break
|
||||
}
|
||||
}
|
||||
if i < 0 {
|
||||
e.jump = nil
|
||||
} else {
|
||||
cursor = i
|
||||
var err error
|
||||
switch it := its[i]; {
|
||||
case it.open != nil:
|
||||
e.via = it.Label
|
||||
err = it.open()
|
||||
e.via = ""
|
||||
case it.do != nil && last:
|
||||
e.jump = nil
|
||||
err = it.do()
|
||||
default:
|
||||
e.jump = nil
|
||||
}
|
||||
if errors.Is(err, errClose) {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
sh := &view.Sheet{Title: p.title, Crumbs: strings.Join(e.crumbs, " > "), Note: p.note,
|
||||
Cursor: cursor, Keys: p.keys, Status: e.status()}
|
||||
Cursor: cursor, Keys: p.keys, Status: e.status(), Menus: e.pullDowns()}
|
||||
for _, it := range its {
|
||||
sh.Entries = append(sh.Entries, it.Entry)
|
||||
}
|
||||
@@ -164,6 +220,11 @@ func (e *Editor) show(p page) error {
|
||||
return errSave
|
||||
case view.SheetQuit:
|
||||
return errQuit
|
||||
case view.SheetJump:
|
||||
e.jump = r.Jump
|
||||
if len(e.jump) == 0 {
|
||||
e.jump = nil
|
||||
}
|
||||
case view.SheetHelp:
|
||||
if r.Entry >= 0 && r.Entry < len(its) {
|
||||
err = e.helpOf(its[r.Entry])
|
||||
@@ -174,7 +235,9 @@ func (e *Editor) show(p page) error {
|
||||
}
|
||||
switch it := its[r.Entry]; {
|
||||
case it.open != nil:
|
||||
e.via = it.Label
|
||||
err = it.open()
|
||||
e.via = ""
|
||||
case it.do != nil:
|
||||
err = it.do()
|
||||
}
|
||||
@@ -202,6 +265,19 @@ func (e *Editor) show(p page) error {
|
||||
}
|
||||
}
|
||||
|
||||
// prefix is whether a begins b.
|
||||
func prefix(a, b []string) bool {
|
||||
if len(a) > len(b) {
|
||||
return false
|
||||
}
|
||||
for i := range a {
|
||||
if a[i] != b[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// helpOf shows an item's whole help (F1), wrapped to the screen, and when a
|
||||
// change to it takes effect.
|
||||
func (e *Editor) helpOf(it item) error {
|
||||
@@ -358,8 +434,8 @@ func (e *Editor) save() (bool, error) {
|
||||
if len(ch) > 0 {
|
||||
if e.Tools.Reload == nil {
|
||||
lines = append(lines, view.L(""),
|
||||
view.L("A BBS running puts the green changes in force at a reload (systemctl reload"),
|
||||
view.L("bbs, or SIGHUP); the yellow ones when it starts again."), view.L(""))
|
||||
view.L("A BBS running puts the green changes in force at a reload (systemctl reload bbs, or SIGHUP); the yellow ones when it starts again."),
|
||||
view.L(""))
|
||||
lines = append(lines, e.diffLines(ch)...)
|
||||
} else {
|
||||
applied, restart, err := e.Tools.Reload()
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
bbssec "github.com/D-Modem/bbs"
|
||||
"github.com/D-Modem/bbs/internal/backup"
|
||||
"github.com/D-Modem/bbs/internal/bbs"
|
||||
"github.com/D-Modem/bbs/internal/confedit"
|
||||
"github.com/D-Modem/bbs/internal/store"
|
||||
"github.com/D-Modem/bbs/internal/view"
|
||||
)
|
||||
@@ -291,7 +292,7 @@ func TestServices(t *testing.T) {
|
||||
p := writeConf(t)
|
||||
os.WriteFile(p, []byte(file+"\n; finger\n;[finger]\n;address = :79\n"), 0o600)
|
||||
ui := &script{t: t, forms: []map[string]string{{"name": "ssh"}}, steps: []step{
|
||||
open("Services"),
|
||||
open("Internet services"),
|
||||
open("Finger"), expect("Enabled", "no", false, set("Enabled", "yes")), set("online", "no"), back,
|
||||
open("SSH"), key("add"),
|
||||
expect("type", "ssh", true, set("address", ":2222")), back, back,
|
||||
@@ -451,3 +452,87 @@ func TestBackUpNow(t *testing.T) {
|
||||
t.Errorf("written:\n%s", data)
|
||||
}
|
||||
}
|
||||
|
||||
// jump is a step that picks a pull-down menu's item (by the menu's label
|
||||
// and the item's), checking the sheet has it.
|
||||
func jump(menu, item string) step {
|
||||
return func(t *testing.T, sh *view.Sheet) view.SheetResult {
|
||||
t.Helper()
|
||||
for _, m := range sh.Menus {
|
||||
if m.Label != menu {
|
||||
continue
|
||||
}
|
||||
for _, it := range m.Items {
|
||||
if it.Label == item && !it.Heading {
|
||||
if it.Action != "" {
|
||||
return view.SheetResult{Action: it.Action}
|
||||
}
|
||||
return view.SheetResult{Action: view.SheetJump, Jump: it.Path}
|
||||
}
|
||||
}
|
||||
}
|
||||
t.Fatalf("%s: no %s > %s in the menus", sh.Crumbs, menu, item)
|
||||
return view.SheetResult{}
|
||||
}
|
||||
}
|
||||
|
||||
// at is a step that checks the sheet is the one crumbs names, then does
|
||||
// then.
|
||||
func at(crumbs string, then step) step {
|
||||
return func(t *testing.T, sh *view.Sheet) view.SheetResult {
|
||||
t.Helper()
|
||||
if sh.Crumbs != crumbs {
|
||||
t.Fatalf("at %q, not %q", sh.Crumbs, crumbs)
|
||||
}
|
||||
return then(t, sh)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPullDowns: a pull-down menu's item goes from deep in one menu to a
|
||||
// page of another, by the pages between; every front end is on a menu.
|
||||
func TestPullDowns(t *testing.T) {
|
||||
p := writeConf(t)
|
||||
ui := &script{t: t, steps: []step{
|
||||
open("Internet services"), open("Finger"),
|
||||
jump("Online", "America Online (AOL)"),
|
||||
at("Configuration > Online services > America Online (AOL)", set("Enabled", "yes")),
|
||||
jump("Online", "Yahoo! Messenger"),
|
||||
at("Configuration > Messengers and chat > Yahoo! Messenger", set("Enabled", "yes")),
|
||||
jump("Time", "NTP server"),
|
||||
at("Configuration > Time > NTP server", back),
|
||||
at("Configuration > Time", back),
|
||||
at("Configuration", jump("File", "Save and exit F10")),
|
||||
}}
|
||||
if err := (&Editor{UI: ui, Tools: bbs.ConfigTools{Path: p}}).Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, _ := os.ReadFile(p)
|
||||
for _, want := range []string{"[aol]", "[ymsg]"} {
|
||||
if !strings.Contains(string(data), want) {
|
||||
t.Errorf("no %q in:\n%s", want, data)
|
||||
}
|
||||
}
|
||||
// every kind of section the sample has is on a menu's page
|
||||
e := &Editor{UI: ui}
|
||||
e.cat = confeditCatalog()
|
||||
e.doc, _ = confeditParse(nil)
|
||||
e.orig, _ = confeditParse(nil)
|
||||
var labels []string
|
||||
for _, m := range e.pullDowns() {
|
||||
for _, it := range m.Items {
|
||||
labels = append(labels, it.Label)
|
||||
}
|
||||
}
|
||||
all := strings.Join(labels, "|")
|
||||
for _, want := range []string{"America Online (AOL)", "CompuServe (CIS)", "The Microsoft Network (MSN 1995)",
|
||||
"AIM and ICQ (OSCAR)", "MSN Messenger", "Yahoo! Messenger", "IRC server", "IRC network links", "Multi Relay Chat",
|
||||
"POP3", "IMAP", "Smarthost (send through)", "Gopher", "Gemini", "Finger", "NTP server", "PTP grandmaster", "FidoNet", "Doors"} {
|
||||
if !strings.Contains("|"+all+"|", "|"+want+"|") {
|
||||
t.Errorf("no %q in the pull-down menus: %s", want, all)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func confeditCatalog() *confedit.Catalog { return confedit.NewCatalog(bbssec.Sample) }
|
||||
|
||||
func confeditParse(b []byte) (*confedit.Doc, error) { return confedit.Parse(b) }
|
||||
+265
-28
@@ -10,31 +10,139 @@ import (
|
||||
|
||||
// The menus, by what a sysop looks for.
|
||||
|
||||
// The first page's menus, by their labels (the pull-down menus' paths
|
||||
// name them).
|
||||
const (
|
||||
mBoard = "Board configuration"
|
||||
mSystem = "System configuration"
|
||||
mLines = "Connections and modems"
|
||||
mInternet = "Internet services"
|
||||
mOnline = "Online services"
|
||||
mChat = "Messengers and chat"
|
||||
mMail = "E-mail"
|
||||
mNetworks = "Networks and doors"
|
||||
mTime = "Time"
|
||||
mUsers = "Users and groups"
|
||||
mMaint = "Maintenance"
|
||||
mReview = "Review changes"
|
||||
mCheck = "Check the configuration"
|
||||
)
|
||||
|
||||
// mainMenu is the first page: the menus, then review, check, save and quit.
|
||||
func (e *Editor) mainMenu() page {
|
||||
return page{title: "Configuration", items: func() []item {
|
||||
g := sec("general")
|
||||
name, _ := e.doc.Get(g, "name")
|
||||
n := e.changes()
|
||||
review := menu("Review changes", fmt.Sprintf("%d not saved", n), e.review)
|
||||
review.Kind = view.EntryAction
|
||||
review.do, review.open = e.review, nil
|
||||
review := action(mReview, e.review)
|
||||
review.Value = fmt.Sprintf("%d not saved", n)
|
||||
return []item{
|
||||
menu("Board configuration", name, func() error { return e.show(e.boardMenu()) }),
|
||||
menu("System configuration", "", func() error { return e.show(e.systemMenu()) }),
|
||||
menu("Connections and modems", e.count("listen", nil, "listener"), func() error { return e.show(e.connectionsMenu()) }),
|
||||
menu("Services", "", func() error { return e.show(e.servicesMenu()) }),
|
||||
menu("Users and groups", "", func() error { return e.show(e.usersMenu()) }),
|
||||
menu("Maintenance", "", func() error { return e.show(e.maintenanceMenu()) }),
|
||||
withHelp(e.submenu(mBoard, name, e.boardMenu), "The BBS's name, sysop and where it is; what callers see; the menus and prompts."),
|
||||
withHelp(e.submenu(mSystem, "", e.systemMenu), "The database and log, where files are kept, security, the user it runs as, scheduled events, and every section of the file."),
|
||||
withHelp(e.submenu(mLines, e.count("listen", nil, "listener"), e.connectionsMenu), "Modem lines and listeners (the ports callers come in by), callers' limits, modemmenu's passwords, caller ID."),
|
||||
heading("What callers reach"),
|
||||
withHelp(e.submenu(mInternet, "", e.servicesMenu), "Telnet, TN3270, SSH and RLogin for terminals; finger, gopher, Gemini, FTP, news and the web."),
|
||||
withHelp(e.submenu(mOnline, e.onCount("aol", "marvel"), e.onlineMenu), "The BBS as America Online, CompuServe and The Microsoft Network, for their own 1990s client programs."),
|
||||
withHelp(e.submenu(mChat, e.onCount("oscar", "msn", "ymsg", "irc", "irclink", "mrc"), e.chatMenu), "AIM and ICQ, MSN Messenger, Yahoo! Messenger, the IRC server and its network links, Multi Relay Chat."),
|
||||
withHelp(e.submenu(mMail, e.onOff(sec("mail")), e.mailMenu), "Each user's e-mail: the domain, sending (direct or by a smarthost), POP3, IMAP, SMTP, MX and LMTP."),
|
||||
withHelp(e.submenu(mNetworks, "", e.networksMenu), "FidoNet and binkp, QWK networks, and the doors."),
|
||||
withHelp(e.submenu(mTime, e.onCount("time", "ntp", "nts", "ptp"), e.timeMenu), "The clock the BBS follows (NTP, NTS, PTP servers) and the time servers it can be."),
|
||||
heading("Accounts and upkeep"),
|
||||
withHelp(e.submenu(mUsers, "", e.usersMenu), "User accounts, access levels and flags."),
|
||||
withHelp(e.submenu(mMaint, "", e.maintenanceMenu), "Disk space, what the message areas keep, backups."),
|
||||
heading(""),
|
||||
review,
|
||||
action("Check the configuration", e.check),
|
||||
action(mCheck, e.check),
|
||||
action("Save and exit (F10)", func() error { return errSave }),
|
||||
action("Quit without saving (F9)", func() error { return errQuit }),
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
// withHelp is it with its help.
|
||||
func withHelp(it item, help string) item {
|
||||
it.Help = help
|
||||
return it
|
||||
}
|
||||
|
||||
// submenu is an item that opens the page p makes.
|
||||
func (e *Editor) submenu(label, value string, p func() page) item {
|
||||
it := menu(label, value, func() error { return e.show(p()) })
|
||||
it.sub = p
|
||||
return it
|
||||
}
|
||||
|
||||
// onCount is how many of the sections of kinds the file has, in words.
|
||||
func (e *Editor) onCount(kinds ...string) string {
|
||||
n := 0
|
||||
for _, k := range kinds {
|
||||
if e.doc.Has(sec(k)) {
|
||||
n++
|
||||
}
|
||||
}
|
||||
if n == 0 {
|
||||
return "off"
|
||||
}
|
||||
return fmt.Sprintf("%d on", n)
|
||||
}
|
||||
|
||||
// pullDowns are the menu bar's menus: File, then the first page's menus
|
||||
// gathered under short names, each item a jump to its page.
|
||||
func (e *Editor) pullDowns() []view.PullDown {
|
||||
tops := map[string]item{}
|
||||
for _, it := range e.mainMenu().items() {
|
||||
tops[it.Label] = it
|
||||
}
|
||||
// expand is a first-page menu's own menus, under a heading of it
|
||||
expand := func(label string, head bool) []view.PullItem {
|
||||
var out []view.PullItem
|
||||
top, ok := tops[label]
|
||||
if !ok || top.sub == nil {
|
||||
return nil
|
||||
}
|
||||
if head {
|
||||
out = append(out, view.PullItem{Label: label, Heading: true})
|
||||
}
|
||||
for _, it := range top.sub().items() {
|
||||
switch {
|
||||
case it.Kind == view.EntryHeading:
|
||||
if len(out) > 0 && !out[len(out)-1].Heading {
|
||||
out = append(out, view.PullItem{Label: it.Label, Heading: true})
|
||||
}
|
||||
case it.Kind == view.EntryMenu && !it.Disabled:
|
||||
out = append(out, view.PullItem{Label: it.Label, Path: []string{label, it.Label}})
|
||||
}
|
||||
}
|
||||
for len(out) > 0 && out[len(out)-1].Heading {
|
||||
out = out[:len(out)-1]
|
||||
}
|
||||
return out
|
||||
}
|
||||
page := func(label string) view.PullItem { return view.PullItem{Label: label, Path: []string{label}} }
|
||||
pd := func(label string, items ...[]view.PullItem) view.PullDown {
|
||||
m := view.PullDown{Label: label}
|
||||
for _, its := range items {
|
||||
m.Items = append(m.Items, its...)
|
||||
}
|
||||
return m
|
||||
}
|
||||
one := func(its ...view.PullItem) []view.PullItem { return its }
|
||||
rule := view.PullItem{Heading: true}
|
||||
return []view.PullDown{
|
||||
pd("File", one(page(mReview), page(mCheck), rule,
|
||||
view.PullItem{Label: "Save and exit F10", Action: view.SheetSave},
|
||||
view.PullItem{Label: "Quit without saving F9", Action: view.SheetQuit})),
|
||||
pd("Setup", one(page(mBoard), page(mSystem), page(mUsers), page(mMaint), rule,
|
||||
view.PullItem{Label: "All settings, by section", Path: []string{mSystem, "All settings, by section"}})),
|
||||
pd("Lines", one(page(mLines), rule), expand(mLines, false)),
|
||||
pd("Internet", one(page(mInternet), rule), expand(mInternet, false)),
|
||||
pd("Online", expand(mOnline, true), expand(mChat, true)),
|
||||
pd("Mail", one(page(mMail), rule), expand(mMail, false)),
|
||||
pd("Networks", one(page(mNetworks), rule), expand(mNetworks, false)),
|
||||
pd("Time", one(page(mTime), rule), expand(mTime, false)),
|
||||
}
|
||||
}
|
||||
|
||||
// count is how many sections of a kind there are, in words.
|
||||
func (e *Editor) count(kind string, keep func(confedit.Section) bool, noun string) string {
|
||||
n := len(e.instances(kind, keep))
|
||||
@@ -163,21 +271,40 @@ func (e *Editor) onOff(s confedit.Section) string {
|
||||
return "off"
|
||||
}
|
||||
|
||||
// servicesMenu is Services: listeners by type, the servers whose section
|
||||
// turns them on, and the networks and doors.
|
||||
func (e *Editor) servicesMenu() page {
|
||||
ofType := func(t string) func(confedit.Section) bool {
|
||||
return func(s confedit.Section) bool { return listenType(e, s) == t }
|
||||
// ofType keeps the listeners of a type.
|
||||
func (e *Editor) ofType(t string) func(confedit.Section) bool {
|
||||
return func(s confedit.Section) bool { return listenType(e, s) == t }
|
||||
}
|
||||
|
||||
// ofFrontEnd keeps the listeners that answer as a front end (compuserve,
|
||||
// marvel).
|
||||
func (e *Editor) ofFrontEnd(f string) func(confedit.Section) bool {
|
||||
return func(s confedit.Section) bool {
|
||||
v, _ := e.doc.Get(s, "frontend")
|
||||
return v == f
|
||||
}
|
||||
}
|
||||
|
||||
// single is an item for a section whose being there turns a server on:
|
||||
// its page has Enabled and its keys.
|
||||
func (e *Editor) single(label, kind string) item {
|
||||
it := menu(label, e.onOff(sec(kind)), func() error { return e.show(e.sectionPage(sec(kind), label, true)) })
|
||||
if k := e.cat.Kind(kind); k != nil {
|
||||
it.Help = firstSentence(k.Help)
|
||||
it.help = k.Help
|
||||
}
|
||||
return it
|
||||
}
|
||||
|
||||
// servicesMenu is Internet services: the terminals' listeners by type, and
|
||||
// the servers whose section turns them on.
|
||||
func (e *Editor) servicesMenu() page {
|
||||
listeners := func(label, t, addr string) item {
|
||||
return menu(label, e.count("listen", ofType(t), "listener"), func() error {
|
||||
return e.show(e.listeners(ofType(t), label, map[string]string{"type": t, "address": addr}))
|
||||
return menu(label, e.count("listen", e.ofType(t), "listener"), func() error {
|
||||
return e.show(e.listeners(e.ofType(t), label, map[string]string{"type": t, "address": addr}))
|
||||
})
|
||||
}
|
||||
single := func(label, kind string) item {
|
||||
return menu(label, e.onOff(sec(kind)), func() error { return e.show(e.sectionPage(sec(kind), label, true)) })
|
||||
}
|
||||
return page{title: "Services", items: func() []item {
|
||||
return page{title: mInternet, items: func() []item {
|
||||
return []item{
|
||||
heading("Callers' terminals"),
|
||||
listeners("Telnet", "telnet", ":23"),
|
||||
@@ -185,15 +312,112 @@ func (e *Editor) servicesMenu() page {
|
||||
listeners("SSH", "ssh", ":22"),
|
||||
listeners("RLogin", "rlogin", "127.0.0.1:513"),
|
||||
heading("Servers"),
|
||||
single("Finger", "finger"),
|
||||
single("Gopher", "gopher"),
|
||||
single("Gemini", "gemini"),
|
||||
single("FTP", "ftp"),
|
||||
single("IRC (ircd)", "irc"),
|
||||
e.single("Finger", "finger"),
|
||||
e.single("Gopher", "gopher"),
|
||||
e.single("Gemini", "gemini"),
|
||||
e.single("FTP", "ftp"),
|
||||
menu("News (NNTP)", e.onOff(sec("nntp")), func() error { return e.show(e.newsPage()) }),
|
||||
menu("Web: API, forum, image boards", e.onOff(sec("http")), func() error { return e.show(e.webPage()) }),
|
||||
heading("Networks and doors"),
|
||||
single("Multi Relay Chat", "mrc"),
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
// onlineMenu is Online services: the dial-up services of the 1990s the BBS
|
||||
// answers as, for their own client programs.
|
||||
func (e *Editor) onlineMenu() page {
|
||||
return page{title: mOnline,
|
||||
note: []view.Line{view.T(view.Dim, "The BBS as the online services, for their own client programs.")},
|
||||
items: func() []item {
|
||||
return []item{
|
||||
e.single("America Online (AOL)", "aol"),
|
||||
menu("CompuServe (CIS)", e.count("listen", e.ofFrontEnd("compuserve"), "listener"), func() error {
|
||||
return e.show(e.frontEndListeners("CompuServe (CIS)", "compuserve",
|
||||
"Listeners with frontend = compuserve answer as CompuServe.",
|
||||
map[string]string{"type": "telnet", "address": ":2324", "frontend": "compuserve"}))
|
||||
}),
|
||||
menu("The Microsoft Network (MSN 1995)", e.onOff(sec("marvel")), func() error { return e.show(e.marvelPage()) }),
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
// frontEndListeners is the listeners that answer as a front end, with a
|
||||
// word on it; added ones get the keys of with.
|
||||
func (e *Editor) frontEndListeners(title, frontend, note string, with map[string]string) page {
|
||||
p := e.listeners(e.ofFrontEnd(frontend), title, with)
|
||||
p.note = []view.Line{view.T(view.Dim, note)}
|
||||
return p
|
||||
}
|
||||
|
||||
// marvelPage is MSN Classic: its TCP host, and its dial-in listeners.
|
||||
func (e *Editor) marvelPage() page {
|
||||
return page{title: "The Microsoft Network (MSN 1995)", items: func() []item {
|
||||
out := []item{e.enabled(sec("marvel"), "Over TCP (port 569)")}
|
||||
out = append(out, e.sectionFields(sec("marvel"))...)
|
||||
out = append(out, heading("Modem callers"),
|
||||
menu("Listeners with frontend = marvel", e.count("listen", e.ofFrontEnd("marvel"), "listener"), func() error {
|
||||
return e.show(e.frontEndListeners("MSN dial-in listeners", "marvel",
|
||||
"Windows 95's MSN client dialing in comes through these.",
|
||||
map[string]string{"type": "raw", "address": "127.0.0.1:2325", "frontend": "marvel"}))
|
||||
}))
|
||||
return out
|
||||
}}
|
||||
}
|
||||
|
||||
// chatMenu is Messengers and chat: the instant messengers, IRC and its
|
||||
// links, Multi Relay Chat.
|
||||
func (e *Editor) chatMenu() page {
|
||||
return page{title: mChat, items: func() []item {
|
||||
return []item{
|
||||
heading("Instant messengers"),
|
||||
e.single("AIM and ICQ (OSCAR)", "oscar"),
|
||||
e.single("MSN Messenger", "msn"),
|
||||
e.single("Yahoo! Messenger", "ymsg"),
|
||||
heading("IRC"),
|
||||
e.single("IRC server", "irc"),
|
||||
menu("IRC network links", e.onOff(sec("irclink")), func() error { return e.show(e.ircLinkPage()) }),
|
||||
heading("Between BBSes"),
|
||||
e.single("Multi Relay Chat", "mrc"),
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
// ircLinkPage is IRC server linking: [irclink] and the [ircpeer]s.
|
||||
func (e *Editor) ircLinkPage() page {
|
||||
return page{title: "IRC network links", items: func() []item {
|
||||
out := []item{e.enabled(sec("irclink"), "Linked to a network")}
|
||||
out = append(out, e.sectionFields(sec("irclink"))...)
|
||||
out = append(out, heading("Servers linked with"), menu("Peer servers", e.count("ircpeer", nil, "server"), func() error {
|
||||
return e.show(e.listPage("Peer servers", "ircpeer", "server", nil, func(s confedit.Section) string {
|
||||
a, _ := e.doc.Get(s, "address")
|
||||
return a
|
||||
}, nil))
|
||||
}))
|
||||
return out
|
||||
}}
|
||||
}
|
||||
|
||||
// mailMenu is E-mail: [mail], the smarthost, and each mail server.
|
||||
func (e *Editor) mailMenu() page {
|
||||
return page{title: mMail, items: func() []item {
|
||||
out := []item{e.enabled(sec("mail"), "E-mail")}
|
||||
out = append(out, e.sectionFields(sec("mail"))...)
|
||||
out = append(out,
|
||||
heading("Sending"),
|
||||
e.single("Smarthost (send through)", "smarthost"),
|
||||
heading("Servers"),
|
||||
e.single("POP3", "pop3"),
|
||||
e.single("IMAP", "imap"),
|
||||
e.single("SMTP submission", "smtp"),
|
||||
e.single("MX (mail from the internet)", "mx"),
|
||||
e.single("LMTP (from a mail server)", "lmtp"))
|
||||
return out
|
||||
}}
|
||||
}
|
||||
|
||||
// networksMenu is Networks and doors: FidoNet, QWK, the doors.
|
||||
func (e *Editor) networksMenu() page {
|
||||
return page{title: mNetworks, items: func() []item {
|
||||
return []item{
|
||||
menu("FidoNet", e.onOff(sec("fido")), func() error { return e.show(e.fidoPage()) }),
|
||||
menu("QWK networks", e.count("qwknet", nil, "network"), func() error {
|
||||
return e.show(e.listPage("QWK networks", "qwknet", "network", nil, func(s confedit.Section) string {
|
||||
@@ -211,6 +435,19 @@ func (e *Editor) servicesMenu() page {
|
||||
}}
|
||||
}
|
||||
|
||||
// timeMenu is Time: the clock the BBS follows, and its time servers.
|
||||
func (e *Editor) timeMenu() page {
|
||||
return page{title: mTime, items: func() []item {
|
||||
return []item{
|
||||
e.single("Clock and time sources", "time"),
|
||||
heading("Time servers"),
|
||||
e.single("NTP server", "ntp"),
|
||||
e.single("NTS-KE server (secure NTP)", "nts"),
|
||||
e.single("PTP grandmaster", "ptp"),
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
// tn3270Page is TN3270: the 3270 pictures and logo, and the tn3270 key of
|
||||
// each telnet listener.
|
||||
func (e *Editor) tn3270Page() page {
|
||||
|
||||
@@ -133,19 +133,19 @@ func TestConfigScreens(t *testing.T) {
|
||||
saved(t, e, p)
|
||||
}
|
||||
|
||||
// TestConfigScreensANSI: on an ANSI terminal, the full screen: the arrow
|
||||
// keys, Enter to change a value, F10 to save and leave.
|
||||
// TestConfigScreensANSI: on an ANSI terminal, the setup screens: the arrow
|
||||
// keys, Enter to change a value in its box, F10 to save and leave.
|
||||
func TestConfigScreensANSI(t *testing.T) {
|
||||
e, p := configEnv(t, "yes")
|
||||
s := ansiLogin(e)
|
||||
s.send("*")
|
||||
s.expect("Configuration")
|
||||
s.send("F")
|
||||
s.expect("F10 save+exit")
|
||||
s.expect("Messengers and chat")
|
||||
s.send("\x1b[B\x1b[A\r") // down, up: Board configuration
|
||||
s.expect("Configuration > Board configuration")
|
||||
s.expect("Sysop's name")
|
||||
s.send("\r")
|
||||
s.expect("BBS name: ")
|
||||
s.expect("Clear") // the box the name is typed in
|
||||
s.send("\x15Renamed BBS\r")
|
||||
s.expect("1 change not saved")
|
||||
s.send("\x1b[21~") // F10
|
||||
@@ -158,9 +158,9 @@ func TestConfigQuit(t *testing.T) {
|
||||
e, p := configEnv(t, "yes")
|
||||
s := ansiLogin(e)
|
||||
s.send("*F")
|
||||
s.expect("F10 save+exit")
|
||||
s.expect("Messengers and chat")
|
||||
s.send("\r\r")
|
||||
s.expect("BBS name: ")
|
||||
s.expect("Clear")
|
||||
s.send("\x15Not Saved\r")
|
||||
s.expect("1 change not saved")
|
||||
s.send("\x1b[20~") // F9
|
||||
|
||||
@@ -0,0 +1,297 @@
|
||||
package textui
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// The desk: a full screen drawn in character cells, as the setup programs
|
||||
// of the 1990s drew theirs (blue windows over a shaded desktop, a menu bar,
|
||||
// a bar of keys). What is drawn is kept, and only the cells that changed
|
||||
// are sent, so that a caller at 2400 bit/s is not sent the whole screen for
|
||||
// a moved bar.
|
||||
|
||||
// The sixteen colors of a PC's text mode: 0-7 as backgrounds too.
|
||||
const (
|
||||
cBlack = iota
|
||||
cBlue
|
||||
cGreen
|
||||
cCyan
|
||||
cRed
|
||||
cMagenta
|
||||
cBrown
|
||||
cLightGray
|
||||
cDarkGray
|
||||
cLightBlue
|
||||
cLightGreen
|
||||
cLightCyan
|
||||
cLightRed
|
||||
cLightMagenta
|
||||
cYellow
|
||||
cWhite
|
||||
)
|
||||
|
||||
// attr is a cell's colors: foreground (0-15) and background (0-7).
|
||||
type attr struct{ fg, bg uint8 }
|
||||
|
||||
// cell is a character cell.
|
||||
type cell struct {
|
||||
r rune
|
||||
a attr
|
||||
}
|
||||
|
||||
// screen is a screen's cells.
|
||||
type screen struct {
|
||||
cols, rows int
|
||||
c []cell
|
||||
}
|
||||
|
||||
func newScreen(cols, rows int) *screen {
|
||||
s := &screen{cols: cols, rows: rows, c: make([]cell, cols*rows)}
|
||||
for i := range s.c {
|
||||
s.c[i] = cell{' ', attr{cLightGray, cBlack}}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// clone is a copy of s.
|
||||
func (s *screen) clone() *screen {
|
||||
n := &screen{cols: s.cols, rows: s.rows, c: make([]cell, len(s.c))}
|
||||
copy(n.c, s.c)
|
||||
return n
|
||||
}
|
||||
|
||||
// at is the cell at row and column (from 0), nil off the screen.
|
||||
func (s *screen) at(row, col int) *cell {
|
||||
if row < 0 || col < 0 || row >= s.rows || col >= s.cols {
|
||||
return nil
|
||||
}
|
||||
return &s.c[row*s.cols+col]
|
||||
}
|
||||
|
||||
// put writes str from row, col in a, cut at the screen's edge; how many
|
||||
// cells it took.
|
||||
func (s *screen) put(row, col int, str string, a attr) int {
|
||||
n := 0
|
||||
for _, r := range str {
|
||||
if c := s.at(row, col+n); c != nil {
|
||||
*c = cell{r, a}
|
||||
}
|
||||
n++
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// putw writes str in exactly w cells: cut, or padded with spaces.
|
||||
func (s *screen) putw(row, col, w int, str string, a attr) {
|
||||
s.put(row, col, fit(str, w), a)
|
||||
}
|
||||
|
||||
// fill fills a rectangle with r in a.
|
||||
func (s *screen) fill(row, col, h, w int, r rune, a attr) {
|
||||
for y := row; y < row+h; y++ {
|
||||
for x := col; x < col+w; x++ {
|
||||
if c := s.at(y, x); c != nil {
|
||||
*c = cell{r, a}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// paint sets the colors of a rectangle, keeping its characters.
|
||||
func (s *screen) paint(row, col, h, w int, a attr) {
|
||||
for y := row; y < row+h; y++ {
|
||||
for x := col; x < col+w; x++ {
|
||||
if c := s.at(y, x); c != nil {
|
||||
c.a = a
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// boxStyle is a box's lines: corners, sides and the joins of a line
|
||||
// across it.
|
||||
type boxStyle struct{ tl, tr, bl, br, h, v, lj, rj rune }
|
||||
|
||||
var (
|
||||
boxDouble = boxStyle{'╔', '╗', '╚', '╝', '═', '║', '╟', '╢'}
|
||||
boxSingle = boxStyle{'┌', '┐', '└', '┘', '─', '│', '├', '┤'}
|
||||
)
|
||||
|
||||
// box draws a box's frame and fills its inside.
|
||||
func (s *screen) box(row, col, h, w int, st boxStyle, frame, inside attr) {
|
||||
s.fill(row+1, col+1, h-2, w-2, ' ', inside)
|
||||
for x := col + 1; x < col+w-1; x++ {
|
||||
s.put(row, x, string(st.h), frame)
|
||||
s.put(row+h-1, x, string(st.h), frame)
|
||||
}
|
||||
for y := row + 1; y < row+h-1; y++ {
|
||||
s.put(y, col, string(st.v), frame)
|
||||
s.put(y, col+w-1, string(st.v), frame)
|
||||
}
|
||||
s.put(row, col, string(st.tl), frame)
|
||||
s.put(row, col+w-1, string(st.tr), frame)
|
||||
s.put(row+h-1, col, string(st.bl), frame)
|
||||
s.put(row+h-1, col+w-1, string(st.br), frame)
|
||||
}
|
||||
|
||||
// rule draws a line across a box at row, joined to its sides.
|
||||
func (s *screen) rule(row, col, w int, st boxStyle, a attr) {
|
||||
s.put(row, col, string(st.lj), a)
|
||||
for x := col + 1; x < col+w-1; x++ {
|
||||
s.put(row, x, "─", a)
|
||||
}
|
||||
s.put(row, col+w-1, string(st.rj), a)
|
||||
}
|
||||
|
||||
// title puts a title in a box's top line, centered: "[ Title ]".
|
||||
func (s *screen) title(row, col, w int, t string, a attr) {
|
||||
t = " " + trunc(t, w-6) + " "
|
||||
s.put(row, col+(w-len([]rune(t)))/2, t, a)
|
||||
}
|
||||
|
||||
// shadow darkens the cells to the right of and below a rectangle, as a
|
||||
// window's shadow on the desk.
|
||||
func (s *screen) shadow(row, col, h, w int) {
|
||||
dark := attr{cDarkGray, cBlack}
|
||||
s.paint(row+1, col+w, h, 2, dark)
|
||||
s.paint(row+h, col+2, 1, w, dark)
|
||||
}
|
||||
|
||||
// render is what turns the terminal's screen, old (nil: unknown), into s:
|
||||
// each changed run of cells, with its colors. The last cell of the last
|
||||
// line is left alone (writing it scrolls some terminals).
|
||||
func (s *screen) render(old *screen, mono bool) string {
|
||||
var b strings.Builder
|
||||
if old == nil || old.cols != s.cols || old.rows != s.rows {
|
||||
b.WriteString("\x1b[0m\x1b[2J")
|
||||
old = nil
|
||||
}
|
||||
cur := attr{255, 255}
|
||||
for y := 0; y < s.rows; y++ {
|
||||
last := s.cols
|
||||
if y == s.rows-1 {
|
||||
last--
|
||||
}
|
||||
at := -1 // where the cursor is after the last cell written (-1: unknown)
|
||||
for x := 0; x < last; x++ {
|
||||
c := s.c[y*s.cols+x]
|
||||
if old != nil && old.c[y*s.cols+x] == c {
|
||||
// unchanged: skipped, unless a change follows so near
|
||||
// that writing the cells costs less than moving
|
||||
if at != x || !s.changedWithin(old, y, x, last, 8) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if at != x {
|
||||
b.WriteString("\x1b[" + strconv.Itoa(y+1) + ";" + strconv.Itoa(x+1) + "H")
|
||||
}
|
||||
if c.a != cur {
|
||||
b.WriteString(sgr(c.a, mono))
|
||||
cur = c.a
|
||||
}
|
||||
r := c.r
|
||||
if r < ' ' || r == 0x7f || !utf8.ValidRune(r) {
|
||||
r = ' '
|
||||
}
|
||||
b.WriteRune(r)
|
||||
at = x + 1
|
||||
}
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// changedWithin is whether a cell of row y from x, before last, within n
|
||||
// of x, differs from old's.
|
||||
func (s *screen) changedWithin(old *screen, y, x, last, n int) bool {
|
||||
for i := x; i < min(x+n, last); i++ {
|
||||
if old.c[y*s.cols+i] != s.c[y*s.cols+i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// sgr is the escape that gives a's colors (in mono: bright as bold, a light
|
||||
// background as reverse).
|
||||
func sgr(a attr, mono bool) string {
|
||||
if mono {
|
||||
s := "\x1b[0"
|
||||
if a.fg >= 8 {
|
||||
s += ";1"
|
||||
}
|
||||
if a.bg == cLightGray || a.bg == cCyan || a.bg == cGreen {
|
||||
s += ";7"
|
||||
}
|
||||
return s + "m"
|
||||
}
|
||||
ansi := []int{0, 4, 2, 6, 1, 5, 3, 7} // the PC's order to ANSI's
|
||||
s := "\x1b[0"
|
||||
if a.fg >= 8 {
|
||||
s += ";1"
|
||||
}
|
||||
return s + ";" + strconv.Itoa(30+ansi[a.fg%8]) + ";" + strconv.Itoa(40+ansi[a.bg%8]) + "m"
|
||||
}
|
||||
|
||||
// fit is s cut or padded with spaces to exactly w runes.
|
||||
func fit(s string, w int) string {
|
||||
if w <= 0 {
|
||||
return ""
|
||||
}
|
||||
r := []rune(s)
|
||||
if len(r) > w {
|
||||
return string(r[:w])
|
||||
}
|
||||
return s + strings.Repeat(" ", w-len(r))
|
||||
}
|
||||
|
||||
// trunc is s cut to w runes, with "…" where it was cut.
|
||||
func trunc(s string, w int) string {
|
||||
r := []rune(s)
|
||||
if w <= 0 {
|
||||
return ""
|
||||
}
|
||||
if len(r) <= w {
|
||||
return s
|
||||
}
|
||||
if w == 1 {
|
||||
return string(r[:1])
|
||||
}
|
||||
return string(r[:w-1]) + "…"
|
||||
}
|
||||
|
||||
// wrapText breaks s into lines of at most w runes, at spaces where it can.
|
||||
func wrapText(s string, w int) []string {
|
||||
var out []string
|
||||
for _, para := range strings.Split(s, "\n") {
|
||||
words := strings.Fields(para)
|
||||
if len(words) == 0 {
|
||||
out = append(out, "")
|
||||
continue
|
||||
}
|
||||
line := ""
|
||||
for _, wd := range words {
|
||||
for len([]rune(wd)) > w {
|
||||
if line != "" {
|
||||
out = append(out, line)
|
||||
line = ""
|
||||
}
|
||||
r := []rune(wd)
|
||||
out = append(out, string(r[:w]))
|
||||
wd = string(r[w:])
|
||||
}
|
||||
switch {
|
||||
case line == "":
|
||||
line = wd
|
||||
case len([]rune(line))+1+len([]rune(wd)) <= w:
|
||||
line += " " + wd
|
||||
default:
|
||||
out = append(out, line)
|
||||
line = wd
|
||||
}
|
||||
}
|
||||
out = append(out, line)
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package textui
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/D-Modem/bbs/internal/view"
|
||||
)
|
||||
|
||||
// keyConn is a terminal whose keys are given and whose output is kept.
|
||||
type keyConn struct {
|
||||
in *bytes.Reader
|
||||
out bytes.Buffer
|
||||
}
|
||||
|
||||
func (c *keyConn) Read(p []byte) (int, error) { return c.in.Read(p) }
|
||||
func (c *keyConn) Write(p []byte) (int, error) { return c.out.Write(p) }
|
||||
func (c *keyConn) SetReadDeadline(time.Time) error { return nil }
|
||||
func deskTerm(keys string, utf8 bool) (*session, *keyConn) {
|
||||
c := &keyConn{in: bytes.NewReader([]byte(keys))}
|
||||
t := NewTerm(c)
|
||||
t.ANSI, t.UTF8, t.Cols, t.Rows = true, utf8, 80, 25
|
||||
return &session{t: t}, c
|
||||
}
|
||||
|
||||
// sample is a sheet of each kind of entry, with a pull-down menu.
|
||||
func sample() *view.Sheet {
|
||||
return &view.Sheet{Title: "Services", Crumbs: "Configuration > Services",
|
||||
Entries: []view.Entry{
|
||||
{ID: "h", Kind: view.EntryHeading, Label: "Servers"},
|
||||
{ID: "name", Kind: view.EntryText, Label: "BBS name", Value: "Old", Help: "the name"},
|
||||
{ID: "on", Kind: view.EntryBool, Label: "Enabled", Value: "no"},
|
||||
{ID: "tls", Kind: view.EntryChoice, Label: "TLS", Choices: []string{"no", "optional", "required"}, Value: "no"},
|
||||
{ID: "aol", Kind: view.EntryMenu, Label: "AOL"},
|
||||
},
|
||||
Menus: []view.PullDown{{Label: "File", Items: []view.PullItem{{Label: "Save", Action: view.SheetSave}}},
|
||||
{Label: "Online", Items: []view.PullItem{{Label: "Online services", Heading: true},
|
||||
{Label: "America Online", Path: []string{"Online services", "America Online"}},
|
||||
{Label: "CompuServe", Path: []string{"Online services", "CompuServe"}}}}}}
|
||||
}
|
||||
|
||||
// TestDeskSheet: a value typed in its box, a yes/no turned over, a choice
|
||||
// picked from its list, a menu opened, a pull-down's item.
|
||||
func TestDeskSheet(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name, keys string
|
||||
want view.SheetResult
|
||||
}{
|
||||
{"text", "\r\x15New\r", view.SheetResult{Action: view.SheetSet, Entry: 1, Values: map[string]string{"name": "New"}}},
|
||||
{"bool", "\x1b[B\r", view.SheetResult{Action: view.SheetSet, Entry: 2, Values: map[string]string{"on": "yes"}}},
|
||||
{"choice", "\x1b[B\x1b[B\r\x1b[B\x1b[B\r", view.SheetResult{Action: view.SheetSet, Entry: 3, Values: map[string]string{"tls": "required"}}},
|
||||
{"menu", "A\r", view.SheetResult{Action: view.Pick, Entry: 4}},
|
||||
{"save", "\x1b[21~", view.SheetResult{Action: view.SheetSave, Entry: 1}},
|
||||
{"pull-down", "/\x1b[C\x1b[B\r", view.SheetResult{Action: view.SheetJump, Entry: 1, Jump: []string{"Online services", "CompuServe"}}},
|
||||
{"pull-down action", "/\r", view.SheetResult{Action: view.SheetSave, Entry: 1}},
|
||||
} {
|
||||
s, conn := deskTerm(c.keys, true)
|
||||
r, err := s.Sheet(sample())
|
||||
if err != nil {
|
||||
t.Errorf("%s: %v", c.name, err)
|
||||
continue
|
||||
}
|
||||
if r.Action != c.want.Action || r.Entry != c.want.Entry || len(r.Values) != len(c.want.Values) ||
|
||||
strings.Join(r.Jump, ">") != strings.Join(c.want.Jump, ">") {
|
||||
t.Errorf("%s: %+v, not %+v", c.name, r, c.want)
|
||||
}
|
||||
for k, v := range c.want.Values {
|
||||
if r.Values[k] != v {
|
||||
t.Errorf("%s: %s = %q, not %q", c.name, k, r.Values[k], v)
|
||||
}
|
||||
}
|
||||
out := conn.out.String()
|
||||
for _, want := range []string{"╔", "Services", "░", "nline"} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Errorf("%s: no %q drawn", c.name, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestDeskCP437: a terminal without UTF-8 gets the lines and shading in
|
||||
// code page 437, not question marks.
|
||||
func TestDeskCP437(t *testing.T) {
|
||||
s, conn := deskTerm("\x1b[21~", false)
|
||||
if _, err := s.Sheet(sample()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out := conn.out.Bytes()
|
||||
for _, b := range []byte{0xC9, 0xBB, 0xB0, 0xCD} { // ╔ ╗ ░ ═
|
||||
if !bytes.Contains(out, []byte{b}) {
|
||||
t.Errorf("no %#x", b)
|
||||
}
|
||||
}
|
||||
if !bytes.Contains(out, []byte{0x10}) { // ►
|
||||
t.Errorf("no ►")
|
||||
}
|
||||
if bytes.Contains(bytes.ReplaceAll(out, []byte("\x1b[?25l"), nil), []byte("?")) {
|
||||
t.Errorf("a ? in %q", out)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDeskDialogs: with the desk up, a question and help come up as
|
||||
// dialogs over it; EndSheets clears it.
|
||||
func TestDeskDialogs(t *testing.T) {
|
||||
s, conn := deskTerm("\x1b[21~"+"y"+"\r", true)
|
||||
if _, err := s.Sheet(sample()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
yes, err := s.Confirm("Leave without saving 3 changes?", false)
|
||||
if err != nil || !yes {
|
||||
t.Fatalf("confirm: %v %v", yes, err)
|
||||
}
|
||||
if err := s.Show("Check", []view.Line{view.T(view.Good, "As the BBS would take it.")}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(conn.out.String(), "Confirm") || !strings.Contains(conn.out.String(), "As the BBS would take it.") {
|
||||
t.Errorf("no dialogs in %q", conn.out.String())
|
||||
}
|
||||
s.EndSheets()
|
||||
if s.desk != nil || !strings.HasSuffix(conn.out.String(), "\x1b[0m\x1b[2J\x1b[H\x1b[?25h") {
|
||||
t.Errorf("desk not ended")
|
||||
}
|
||||
}
|
||||
|
||||
// TestRender: only what changed is sent again.
|
||||
func TestRender(t *testing.T) {
|
||||
a := newScreen(20, 5)
|
||||
a.put(1, 1, "hello", attr{cYellow, cBlue})
|
||||
first := a.render(nil, false)
|
||||
if !strings.Contains(first, "\x1b[2J") || !strings.Contains(first, "hello") {
|
||||
t.Errorf("first %q", first)
|
||||
}
|
||||
b := a.clone()
|
||||
b.put(1, 1, "j", attr{cYellow, cBlue})
|
||||
if got := b.render(a, false); got != "\x1b[2;2H\x1b[0;1;33;44mj" {
|
||||
t.Errorf("diff %q", got)
|
||||
}
|
||||
if got := b.render(b, false); got != "" {
|
||||
t.Errorf("no change %q", got)
|
||||
}
|
||||
}
|
||||
+1313
-249
File diff suppressed because it is too large.
Load diff
@@ -28,7 +28,8 @@ type session struct {
|
||||
o Options
|
||||
user *store.User
|
||||
|
||||
chatting bool // in a chat room: its lines shown as such
|
||||
chatting bool // in a chat room: its lines shown as such
|
||||
desk *desk // the full screen kept up between sheets (sheet.go), if it is up
|
||||
}
|
||||
|
||||
// errHangup: the caller logged off.
|
||||
|
||||
@@ -111,6 +111,7 @@ func (s *session) Narrow() bool { return s.t.Narrow() }
|
||||
// a key until it is an item's. It is that item's key; "" for Enter (none
|
||||
// chosen: the caller shows its menu again, or goes back if it will).
|
||||
func (s *session) Menu(m *view.Menu) (string, error) {
|
||||
s.EndSheets()
|
||||
t := s.t
|
||||
if len(m.Intro) > 0 {
|
||||
t.Println("")
|
||||
@@ -164,6 +165,7 @@ func (s *session) Menu(m *view.Menu) (string, error) {
|
||||
// action's key, More at Enter if there is more, or Back. With nothing to
|
||||
// pick or do it pauses at the end and is Back.
|
||||
func (s *session) Table(tb *view.Table) (view.Choice, error) {
|
||||
s.EndSheets()
|
||||
t := s.t
|
||||
t.Println("")
|
||||
t.Println(t.C(Cyan, tb.Title))
|
||||
@@ -272,6 +274,7 @@ func (s *session) Table(tb *view.Table) (view.Choice, error) {
|
||||
// picture, its body a page at a time; then waits for an action's key (Q:
|
||||
// Quit, Enter or space: Default, each Back if unset).
|
||||
func (s *session) Message(m *view.Message) (string, error) {
|
||||
s.EndSheets()
|
||||
t := s.t
|
||||
t.Clear()
|
||||
t.Println(t.C(Dim, m.Where))
|
||||
@@ -319,6 +322,9 @@ func (s *session) Message(m *view.Message) (string, error) {
|
||||
// Form asks for each field in turn, Enter keeping its value; nothing typed
|
||||
// for a first field with no value is giving up (false).
|
||||
func (s *session) Form(f *view.Form) (map[string]string, bool, error) {
|
||||
if s.desk != nil && len(f.Fields) > 0 {
|
||||
return s.formBox(s.deskBase(), f)
|
||||
}
|
||||
t := s.t
|
||||
for _, l := range f.Intro {
|
||||
t.Println(s.line(l))
|
||||
@@ -365,6 +371,7 @@ func (s *session) Form(f *view.Form) (map[string]string, bool, error) {
|
||||
// Panel shows a panel's title, picture and lines, and reads a key: an
|
||||
// action's ID, Back for Q or Enter, "" for any other.
|
||||
func (s *session) Panel(p *view.Panel) (string, error) {
|
||||
s.EndSheets()
|
||||
t := s.t
|
||||
t.Println("")
|
||||
t.Println(t.C(Cyan, p.Title))
|
||||
@@ -399,6 +406,7 @@ func (s *session) Panel(p *view.Panel) (string, error) {
|
||||
// line editor; true if it was sent. An error sending is told the caller,
|
||||
// and is false.
|
||||
func (s *session) Edit(d *view.Draft) (bool, error) {
|
||||
s.EndSheets()
|
||||
t := s.t
|
||||
t.Println("")
|
||||
to := d.To
|
||||
@@ -466,12 +474,19 @@ func (s *session) Edit(d *view.Draft) (bool, error) {
|
||||
|
||||
// Confirm asks a yes or no question, def at Enter.
|
||||
func (s *session) Confirm(question string, def bool) (bool, error) {
|
||||
if s.desk != nil {
|
||||
return s.confirmBox(s.deskBase(), question, def)
|
||||
}
|
||||
return s.t.YesNo(question, def)
|
||||
}
|
||||
|
||||
// Say prints msg in its tone; a Bright one as a heading, after a blank
|
||||
// line.
|
||||
func (s *session) Say(tn view.Tone, msg string) {
|
||||
if s.desk != nil {
|
||||
s.desk.flash = msg // at the foot of the next screen
|
||||
return
|
||||
}
|
||||
if tn == view.Bright {
|
||||
s.t.Println("")
|
||||
s.t.Println(s.t.C(Cyan, msg))
|
||||
@@ -483,6 +498,9 @@ func (s *session) Say(tn view.Tone, msg string) {
|
||||
// Show shows a title and lines a page at a time, and waits for a key at
|
||||
// the end (not if the caller quit before it).
|
||||
func (s *session) Show(title string, ls []view.Line) error {
|
||||
if s.desk != nil {
|
||||
return s.messageBox(s.deskBase(), title, ls)
|
||||
}
|
||||
t := s.t
|
||||
t.Println("")
|
||||
t.Println(t.C(Cyan, title))
|
||||
|
||||
@@ -25,15 +25,24 @@ func TestKeyLabel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestSheetFoot: the key line names a sheet's keys, leaving out those with
|
||||
// TestSheetFoot: the key bar names a sheet's keys, leaving out those with
|
||||
// a 3270 PF key alone (no NUL for them).
|
||||
func TestSheetFoot(t *testing.T) {
|
||||
term, c := ansiTerm()
|
||||
d := &sheetDraw{t: term, sh: &view.Sheet{Keys: []view.Action{{Key: 'A', Label: "Add"}, {PF: 5, Label: "PFonly"}}}, cur: -1}
|
||||
d.drawFoot()
|
||||
term.Flush()
|
||||
out := c.String()
|
||||
if strings.Contains(out, "\x00") || strings.Contains(out, "PFonly") || !strings.Contains(out, "A Add Enter change") {
|
||||
t.Errorf("foot %q", out)
|
||||
term, _ := ansiTerm()
|
||||
s := &session{t: term}
|
||||
s.startDesk()
|
||||
w := &sheetWin{s: s, sh: &view.Sheet{Title: "T", Keys: []view.Action{{Key: 'A', Label: "Add"}, {PF: 5, Label: "PFonly"}}}, cur: -1}
|
||||
bar := screenRow(w.frame(), term.Rows-1)
|
||||
if strings.Contains(bar, "\x00") || strings.Contains(bar, "PFonly") || !strings.Contains(bar, "A Add F9 Quit") {
|
||||
t.Errorf("key bar %q", bar)
|
||||
}
|
||||
}
|
||||
|
||||
// screenRow is a screen's row as text.
|
||||
func screenRow(scr *screen, row int) string {
|
||||
var b strings.Builder
|
||||
for x := 0; x < scr.cols; x++ {
|
||||
b.WriteRune(scr.at(row, x).r)
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
@@ -16,6 +16,24 @@ type Sheet struct {
|
||||
Cursor int // the entry the cursor begins on
|
||||
Keys []Action // more keys (A Add, D Delete ...), with PF keys on a 3270
|
||||
Status string // the foot's left: "3 changes not saved"
|
||||
// Menus are the pull-down menus of a menu bar, where the front end
|
||||
// draws one (a text terminal's full screen): picking an item jumps
|
||||
// to its Path, or does its Action
|
||||
Menus []PullDown
|
||||
}
|
||||
|
||||
// PullDown is a pull-down menu of a menu bar.
|
||||
type PullDown struct {
|
||||
Label string
|
||||
Items []PullItem
|
||||
}
|
||||
|
||||
// PullItem is a pull-down menu's line.
|
||||
type PullItem struct {
|
||||
Label string
|
||||
Path []string // where it jumps: the labels of the entries to open, from the first sheet
|
||||
Action string // or what it does (SheetSave, SheetQuit), as a sheet's result
|
||||
Heading bool // a line between groups (Label: its words, if any)
|
||||
}
|
||||
|
||||
// EntryKind is what an entry is.
|
||||
@@ -61,6 +79,18 @@ type SheetResult struct {
|
||||
Action string // Pick (a Menu or Action entry chosen), SheetSet, SheetSave, SheetQuit, Back, a Keys ID
|
||||
Entry int // the entry the cursor was on
|
||||
Values map[string]string // SheetSet: entries' new values by ID (a 3270 sends all it changed at once)
|
||||
Jump []string // SheetJump: a pull-down item's Path
|
||||
}
|
||||
|
||||
// SheetJump is a sheet's result when a pull-down item was picked: go to
|
||||
// its Path.
|
||||
const SheetJump = "jump"
|
||||
|
||||
// SheetEnder is a front end that keeps its full screen up between sheets
|
||||
// (to put questions and help over it): EndSheets puts it away when they
|
||||
// are done.
|
||||
type SheetEnder interface {
|
||||
EndSheets()
|
||||
}
|
||||
|
||||
// SheetUI is a front end that draws sheets full-screen.
|
||||
|
||||
Reference in new issue
Block a user