commit edf0d17
delthas
·
2023-11-15 13:25:54 +0000 UTC
parent 4af3f68
Accept sending unknown command after a confirmation Fixes: https://todo.sr.ht/~taiite/senpai/125
3 files changed,
+24,
-5
M
app.go
+6,
-3
1@@ -106,6 +106,8 @@ type App struct {
2
3 lastMessageTime time.Time
4 lastCloseTime time.Time
5+
6+ lastConfirm string
7 }
8
9 func NewApp(cfg Config) (app *App, err error) {
10@@ -671,9 +673,8 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) {
11 app.win.ToggleMemberList()
12 case tcell.KeyCR, tcell.KeyLF:
13 netID, buffer := app.win.CurrentBuffer()
14- input := app.win.InputEnter()
15- err := app.handleInput(buffer, input)
16- if err != nil {
17+ input := string(app.win.InputContent())
18+ if err := app.handleInput(buffer, input); err != nil {
19 app.win.AddLine(netID, buffer, ui.Line{
20 At: time.Now(),
21 Head: "!!",
22@@ -681,6 +682,8 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) {
23 Notify: ui.NotifyUnread,
24 Body: ui.PlainSprintf("%q: %s", input, err),
25 })
26+ } else {
27+ app.win.InputFlush()
28 }
29 case tcell.KeyRune:
30 if ev.Modifiers() == tcell.ModAlt {
+17,
-1
1@@ -931,6 +931,9 @@ func commandDoTableFlip(app *App, args []string) (err error) {
2 }
3
4 func (app *App) handleInput(buffer, content string) error {
5+ confirmed := content == app.lastConfirm
6+ app.lastConfirm = content
7+
8 if content == "" {
9 return nil
10 }
11@@ -956,7 +959,20 @@ func (app *App) handleInput(buffer, content string) error {
12 found = true
13 }
14 if !found {
15- return fmt.Errorf("command %q doesn't exist", cmdName)
16+ if confirmed {
17+ if s := app.CurrentSession(); s != nil {
18+ if rawArgs != "" {
19+ s.SendRaw(fmt.Sprintf("%s %s", cmdName, rawArgs))
20+ } else {
21+ s.SendRaw(cmdName)
22+ }
23+ return nil
24+ } else {
25+ return errOffline
26+ }
27+ } else {
28+ return fmt.Errorf("the senpai command %q does not exist; press enter again to pass the command as is to the server", cmdName)
29+ }
30 }
31
32 cmd := commands[chosenCMDName]
M
ui/ui.go
+1,
-1
1@@ -423,7 +423,7 @@ func (ui *UI) InputAutoComplete(offset int) (ok bool) {
2 return ui.e.AutoComplete(offset)
3 }
4
5-func (ui *UI) InputEnter() (content string) {
6+func (ui *UI) InputFlush() (content string) {
7 return ui.e.Flush()
8 }
9