From 90b68866d98c02a3d180d0ee43903085ceb016f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A1=D1=8B=D1=81?= =?UTF-8?q?=D0=BE=D0=B5=D0=B2?= Date: Sun, 15 Oct 2023 16:42:25 +0800 Subject: [PATCH] Adds possibility to edit multiline requests --- pkg/cli/cli.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index c331090..bbfb55b 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -142,11 +142,19 @@ func (c *CLI) requestMode(keyStream <-chan keyboard.KeyEvent) (string, error) { } if buffer[len(buffer)-1] == '\n' { - continue + buffer = buffer[:len(buffer)-1] + fmt.Print(LINE_UP) + startPrevLine := strings.LastIndex(buffer, "\n") + if startPrevLine == -1 { + startPrevLine = 0 + } else { + startPrevLine++ + } + fmt.Print(buffer[startPrevLine:]) + } else { + fmt.Print("\b \b") + buffer = buffer[:len(buffer)-1] } - - fmt.Print("\b \b") - buffer = buffer[:len(buffer)-1] continue case keyboard.KeyArrowUp: historyIndex++