From 11d9235d0b04eb483ee88ef75fc672de1640d2d7 Mon Sep 17 00:00:00 2001 From: sloum Date: Sun, 4 Apr 2021 15:22:41 -0700 Subject: [PATCH] Fixes editable line input to work reliably on xterm derivatives, but ungeneralizes qline --- board.go | 3 ++- main.go | 2 +- qline/qline.go | 17 +++++------------ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/board.go b/board.go index 32c85e1..a879cbb 100644 --- a/board.go +++ b/board.go @@ -126,6 +126,7 @@ func (b *Board) CreateLane(name string) { name = GetEditableLine("Lane title: ", "") if name == "" { b.SetMessage("Lane creation canceled", true) + return } } b.Lanes = append(b.Lanes, MakeLane(name)) @@ -296,7 +297,7 @@ func (b *Board) Update(args []string) { var title string var err error if len(args) == 1 { - title = GetEditableLine("New board title: ", "") + title = GetEditableLine("Board title: ", b.Title) if title == "" { b.SetMessage(err.Error(), true) break diff --git a/main.go b/main.go index 169f742..9fe5f2a 100644 --- a/main.go +++ b/main.go @@ -75,7 +75,7 @@ func GetLine(prefix string) (string, error) { func GetEditableLine(prompt, defaultText string) string { fmt.Printf("%s%s\033[2K\033[?25h", upAndLeft, style.Input) - str := qline.GetInput(prompt, defaultText) + str := qline.GetInput(prompt, defaultText, board.width) fmt.Print("\033[?25l") fmt.Print(cursorEnd) return str diff --git a/qline/qline.go b/qline/qline.go index 6eed600..780c345 100644 --- a/qline/qline.go +++ b/qline/qline.go @@ -34,8 +34,6 @@ import ( "fmt" "os" "strings" - - "tildegit.org/sloum/swim/termios" ) const ( @@ -67,26 +65,21 @@ type buffer struct { prompt string } -func GetInput(prompt string, content string) string { - // termios.SetCharMode() - cols, _ := termios.GetWindowSize() +func GetInput(prompt string, content string, cols int) string { b := buffer{make([]rune, 0, (len(content)+1)*2), 0, cols-len(prompt), 0, 0, prompt} fmt.Print(prompt) - fmt.Print("\033[6n") var ch rune var err error reader := bufio.NewReader(os.Stdin) + b.seedContent(content) + b.printBuf() + for { ch, err = readKey(reader) - if err != nil && err.Error() == "response" { - b.cursorStart = int(ch) - b.maxWidth = cols - b.cursorStart - b.seedContent(content) - b.printBuf() - } else if err != nil { + if err != nil { continue } if ch == CarriageReturn || ch == NewLine {