Authentication-Results: mail-b.sr.ht; dkim=pass header.d=gpanders.com header.i=@gpanders.com Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by mail-b.sr.ht (Postfix) with ESMTPS id C400811EFCE for <~delthas/senpai-dev@lists.sr.ht>; Tue, 10 May 2022 01:30:06 +0000 (UTC) Received: (Authenticated sender: greg@gpanders.com) by mail.gandi.net (Postfix) with ESMTPSA id 0C1A5E0002; Tue, 10 May 2022 01:30:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gpanders.com; s=gm1; t=1652146205; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=EZiVzpqW6cH6Xh61UmLE7VPz0EQmhfvjY4P+dPD6p6E=; b=ppt38RVtsPK5yAjn9WqhhT+S/0PxzQZ1litEeKgiJvEMxHk9dQTB3ErV23zAYF7RRWjK3A zyHByndXT4zS4ZilELMNIydAauIJoQZumgZ7slCH8iNIBNsblWJXx5WuXzxrwO6C/F5UJG 6qjry/sSxT6D/ISnzdNNGkFp34hyClYdGSuesnCrvP5i1KZTVrldt0jkhaaofvL9APqKO0 n11vUfqiorgBBcn9I6fp8WtaYl3hOFOjmSHQvkurLCYoSGhJ1fr91D56VrisqPU5HLbk2i bLHDybmCV0xS6uGvy2aCcyAN2LxYBan4VOZbmfaGC5llU+tXu3RdJ0Vj3BUgYQ== From: Gregory Anders To: ~delthas/senpai-dev@lists.sr.ht Cc: Gregory Anders Subject: [PATCH] Add support for standard readline bindings Date: Mon, 9 May 2022 19:30:00 -0600 Message-Id: <20220510013000.63808-1-greg@gpanders.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit * Use Ctrl-F and Ctrl-B to move forward/backward one character * Use Alt-F and Alt-B to move forward/backward one word * Use Ctrl-A and Ctrl-E to move to the beginning/end of the input line * Use Ctrl-K to delete all text from the cursor position to the end of the current line --- app.go | 14 ++++++++++++++ doc/senpai.1.scd | 22 ++++++++++++++++++++++ ui/editor.go | 15 +++++++++++++++ ui/ui.go | 4 ++++ 4 files changed, 55 insertions(+) diff --git a/app.go b/app.go index b044a06..768327f 100644 --- a/app.go +++ b/app.go @@ -505,6 +505,16 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) { } else { app.win.InputSet("/quit") } + case tcell.KeyCtrlA: + app.win.InputHome() + case tcell.KeyCtrlB: + app.win.InputLeft() + case tcell.KeyCtrlE: + app.win.InputEnd() + case tcell.KeyCtrlF: + app.win.InputRight() + case tcell.KeyCtrlK: + app.win.InputKillLine() case tcell.KeyCtrlL: app.win.Resize() case tcell.KeyCtrlU, tcell.KeyPgUp: @@ -614,6 +624,10 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) { app.win.ScrollDownHighlight() case 'p': app.win.ScrollUpHighlight() + case 'f': + app.win.InputRightWord() + case 'b': + app.win.InputLeftWord() case '1', '2', '3', '4', '5', '6', '7', '8', '9': app.win.GoToBufferNo(int(ev.Rune()-'0') - 1) } diff --git a/doc/senpai.1.scd b/doc/senpai.1.scd index abb0af8..4e62405 100644 --- a/doc/senpai.1.scd +++ b/doc/senpai.1.scd @@ -65,9 +65,25 @@ of messages are in the timeline: # KEYBOARD SHORTCUTS +*CTRL-A* + Move the cursor to the beginning of the input field. + +*CTRL-B* + Move the cursor backward one character. + +*CTRL-E* + Move the cursor to the end of the input field. + +*CTRL-F* + Move the cursor forward one character. + *CTRL-C* Clear input line. +*CTRL-K* + Remove all of the text from the cursor position to the end of the input + line. + *CTRL-U*, *PgUp* Go up in the timeline. @@ -86,6 +102,12 @@ of messages are in the timeline: *ALT-END* Go to the last buffer. +*ALT-B* + Move the cursor backward one word. + +*ALT-F* + Move the cursor forward one word. + *ALT-P* Go to the previous highlight diff --git a/ui/editor.go b/ui/editor.go index 606bf8d..ddd7039 100644 --- a/ui/editor.go +++ b/ui/editor.go @@ -143,6 +143,21 @@ func (e *Editor) RemRuneForward() (ok bool) { return } +func (e *Editor) RemLineForward() (ok bool) { + ok = e.cursorIdx < len(e.text[e.lineIdx]) + if !ok { + return + } + + for i := len(e.text[e.lineIdx]); i > e.cursorIdx; i-- { + e.remRuneAt(i - 1) + } + + e.autoCache = nil + e.backsearchEnd() + return +} + func (e *Editor) remRuneAt(idx int) { // TODO avoid looping twice rw := e.textWidth[idx+1] - e.textWidth[idx] diff --git a/ui/ui.go b/ui/ui.go index 77757cb..98e048e 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -377,6 +377,10 @@ func (ui *UI) InputDeleteWord() (ok bool) { return ui.e.RemWord() } +func (ui *UI) InputKillLine() (ok bool) { + return ui.e.RemLineForward() +} + func (ui *UI) InputAutoComplete(offset int) (ok bool) { return ui.e.AutoComplete(offset) } -- 2.35.3