Fixes editable line input to work reliably on xterm derivatives, but ungeneralizes qline
This commit is contained in:
parent
d10e81065a
commit
11d9235d0b
3
board.go
3
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
|
||||
|
|
2
main.go
2
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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue