mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
Merge pull request #46 from D-Modem/claude/project-thread-bgcoyt
Configuration: the sysop is never timed out of it
This commit is contained in:
6 files changed
+82
-3
No files matched your search
@@ -59,6 +59,9 @@ func (e *Editor) Run() error {
|
||||
if se, ok := e.UI.(view.SheetEnder); ok {
|
||||
defer se.EndSheets()
|
||||
}
|
||||
if u, ok := e.UI.(view.Unhurried); ok {
|
||||
defer u.HoldIdle()() // the sysop is never timed out of the setup
|
||||
}
|
||||
if ok, err := e.load(); err != nil || !ok {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package textui
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TestHoldIdle: the sysop's configuration waits past the idle timeout
|
||||
// for a key; the timeout is back after it
|
||||
func TestHoldIdle(t *testing.T) {
|
||||
a, b := net.Pipe()
|
||||
defer a.Close()
|
||||
defer b.Close()
|
||||
go func() {
|
||||
buf := make([]byte, 64)
|
||||
for {
|
||||
if _, err := b.Read(buf); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
term := NewTerm(a)
|
||||
term.Idle = 20 * time.Millisecond
|
||||
s := &session{t: term}
|
||||
restore := s.HoldIdle()
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
b.Write([]byte("x"))
|
||||
}()
|
||||
if k, err := term.EditKey(); err != nil || k != 'x' {
|
||||
t.Fatalf("held: %q, %v; want 'x'", k, err)
|
||||
}
|
||||
restore()
|
||||
if term.Idle != 20*time.Millisecond {
|
||||
t.Fatalf("Idle %v after restore", term.Idle)
|
||||
}
|
||||
if _, err := term.EditKey(); !errors.Is(err, ErrIdle) {
|
||||
t.Fatalf("restored: %v, want ErrIdle", err)
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,9 @@ import (
|
||||
// ErrIdle: the caller typed nothing for too long.
|
||||
var ErrIdle = errors.New("idle timeout")
|
||||
|
||||
// noIdle: how long a read waits with no Idle (as good as for ever)
|
||||
const noIdle = 100 * 365 * 24 * time.Hour
|
||||
|
||||
// ErrPETSCII: while WatchPETSCII, a key only a Commodore sends.
|
||||
var ErrPETSCII = errors.New("a Commodore's key")
|
||||
|
||||
@@ -382,7 +385,7 @@ var fkeys = map[string]rune{"11": KeyF1, "12": KeyF1 + 1, "13": KeyF1 + 2, "14":
|
||||
func (t *Term) EditKey() (rune, error) { return t.read(true) }
|
||||
|
||||
// read reads a key for readRune (keys false) or EditKey (true), waiting
|
||||
// at most Idle (or to the deadline, if sooner): ErrIdle then. A LF after
|
||||
// at most Idle (0: no limit) or to the deadline, if sooner: ErrIdle then. A LF after
|
||||
// a CR is dropped; an escape sequence is dropped, or, for EditKey, the
|
||||
// key it is.
|
||||
func (t *Term) read(keys bool) (rune, error) {
|
||||
@@ -392,8 +395,12 @@ func (t *Term) read(keys bool) (rune, error) {
|
||||
t.line.skip.Store(false) // a skipped screen ends at its prompt
|
||||
t.line.noPoll.Store(false)
|
||||
start := time.Now()
|
||||
idle := t.Idle
|
||||
if idle <= 0 {
|
||||
idle = noIdle
|
||||
}
|
||||
for {
|
||||
limit := start.Add(t.Idle)
|
||||
limit := start.Add(idle)
|
||||
if !t.deadline.IsZero() && t.deadline.Before(limit) {
|
||||
limit = t.deadline
|
||||
}
|
||||
|
||||
@@ -389,6 +389,14 @@ func (s *session) edit(lines []string) ([]string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// HoldIdle: no idle timeout until the func returned is called (the
|
||||
// sysop's configuration); the login's deadline still holds.
|
||||
func (s *session) HoldIdle() func() {
|
||||
old := s.t.Idle
|
||||
s.t.Idle = 0
|
||||
return func() { s.t.Idle = old }
|
||||
}
|
||||
|
||||
// Console is the screens on a terminal of the machine's own, with no
|
||||
// login: for bbs config's screens (internal/confui), which want a
|
||||
// view.UI and nothing of a caller's.
|
||||
|
||||
+13
-1
@@ -67,6 +67,7 @@ type ui struct {
|
||||
o Options
|
||||
user *store.User
|
||||
deadline time.Time // the login's limit
|
||||
noIdle bool // no idle timeout (HoldIdle: the sysop's configuration)
|
||||
logo *logo // nil: no graphics logo
|
||||
logoAt [2]int // where the vector logo goes on this screen
|
||||
drawn bool // vector graphics are on the screen
|
||||
@@ -146,7 +147,10 @@ func (u *ui) show(scr go3270.Screen, vals map[string]string) (go3270.Response, m
|
||||
}
|
||||
u.g.n = 0
|
||||
d := time.Now().Add(u.b.Conf().IdleTimeout)
|
||||
if !u.deadline.IsZero() && u.deadline.Before(d) {
|
||||
if u.noIdle {
|
||||
d = time.Time{} // none
|
||||
}
|
||||
if !u.deadline.IsZero() && (d.IsZero() || u.deadline.Before(d)) {
|
||||
d = u.deadline
|
||||
}
|
||||
u.g.SetReadDeadline(d)
|
||||
@@ -500,3 +504,11 @@ func (u *ui) listColored(title, heading string, lines []string, colors []go3270.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HoldIdle: no idle timeout until the func returned is called (the
|
||||
// sysop's configuration); the login's deadline still holds.
|
||||
func (u *ui) HoldIdle() func() {
|
||||
old := u.noIdle
|
||||
u.noIdle = true
|
||||
return func() { u.noIdle = old }
|
||||
}
|
||||
@@ -93,6 +93,13 @@ type SheetEnder interface {
|
||||
EndSheets()
|
||||
}
|
||||
|
||||
// Unhurried is a front end whose idle timeout can be held off, for the
|
||||
// sysop's own screens (the configuration): HoldIdle lifts it, and the
|
||||
// func it returns puts it back. The login's hard limit still holds.
|
||||
type Unhurried interface {
|
||||
HoldIdle() (restore func())
|
||||
}
|
||||
|
||||
// SheetUI is a front end that draws sheets full-screen.
|
||||
type SheetUI interface {
|
||||
Sheet(s *Sheet) (SheetResult, error)
|
||||
|
||||
Reference in new issue
Block a user