~taiite/public-inbox

senpai: Clear the input on CTRL+C instead of quitting v1 APPLIED

Hubert Hirtz: 1
 Clear the input on CTRL+C instead of quitting
delthas: 1
 Clear the input on CTRL+C instead of quitting

 4 files changed, 18 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~taiite/public-inbox/patches/23791/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH senpai] Clear the input on CTRL+C instead of quitting Export this patch

We have /QUIT for quitting. Most well-known IRC clients don't quit on
CTRL+C but they do on QUIT.

Clearing the editor input on CTRL+C is useful for shell-like behaviour
"abort current line, let me start my line again".
---
Beware!! We'll need to add e.backsearchEnd() to e.Clear() when rebasing 
the backsearch patch.

 app.go       |  2 +-
 ui/editor.go | 12 ++++++++++++
 ui/ui.go     |  4 ++++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/app.go b/app.go
index 57c12de..64c9f8c 100644
--- a/app.go
+++ b/app.go
@@ -320,7 +320,7 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
func (app *App) handleKeyEvent(ev *tcell.EventKey) {
	switch ev.Key() {
	case tcell.KeyCtrlC:
		app.win.Exit()
		app.win.InputClear()
	case tcell.KeyCtrlL:
		app.win.Resize()
	case tcell.KeyCtrlU, tcell.KeyPgUp:
diff --git a/ui/editor.go b/ui/editor.go
index bf21f85..15785e8 100644
--- a/ui/editor.go
+++ b/ui/editor.go
@@ -164,6 +164,18 @@ func (e *Editor) Flush() (content string) {
	return
}

func (e *Editor) Clear() {
	if e.TextLen() == 0 {
		return
	}
	e.text[e.lineIdx] = []rune{}
	e.textWidth = e.textWidth[:1]
	e.cursorIdx = 0
	e.offsetIdx = 0
	e.autoCache = nil
	return
}

func (e *Editor) Right() {
	e.right()
	e.autoCache = nil
diff --git a/ui/ui.go b/ui/ui.go
index 0b45a3c..4ced9f0 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -228,6 +228,10 @@ func (ui *UI) InputEnter() (content string) {
	return ui.e.Flush()
}

func (ui *UI) InputClear() {
	ui.e.Clear()
}

func (ui *UI) Resize() {
	w, h := ui.screen.Size()
	ui.e.Resize(w - 9 - ui.config.ChanColWidth - ui.config.NickColWidth)
-- 
2.30.0

Re: [PATCH senpai] Clear the input on CTRL+C instead of quitting Export this patch

Pushed with this modification to clear the Session state about typing

---
diff --git a/app.go b/app.go
index 64c9f8c..272cd40 100644
--- a/app.go
+++ b/app.go
@@ -321,6 +321,7 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) {
       switch ev.Key() {
       case tcell.KeyCtrlC:
               app.win.InputClear()
               app.typing()
       case tcell.KeyCtrlL:
               app.win.Resize()
       case tcell.KeyCtrlU, tcell.KeyPgUp: