93 lines
1.7 KiB
Go
93 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"tildegit.org/sloum/swim/termios"
|
|
"time"
|
|
)
|
|
|
|
var board Board
|
|
|
|
func Getch() rune {
|
|
reader := bufio.NewReader(os.Stdin)
|
|
char, _, err := reader.ReadRune()
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
return char
|
|
}
|
|
|
|
func GetLine(prefix string) (string, error) {
|
|
defer termios.SetCharMode()
|
|
termios.SetLineMode()
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
fmt.Print(prefix)
|
|
fmt.Print("\033[?25h")
|
|
text, err := reader.ReadString('\n')
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
fmt.Print("\033[?25l")
|
|
|
|
return text[:len(text)-1], nil
|
|
}
|
|
|
|
func GetCommandLine(prefix string) (string, error) {
|
|
fmt.Print(upAndLeft) // Move up one and over all
|
|
fmt.Print(style.Input)
|
|
line, err := GetLine(prefix)
|
|
fmt.Print(cursorEnd)
|
|
return line, err
|
|
}
|
|
|
|
func GetAndConfirmCommandLine(prefix string) (string, error) {
|
|
var conf rune
|
|
var err error
|
|
var line string
|
|
for {
|
|
line, err = GetCommandLine(prefix)
|
|
if err != nil {
|
|
return line, err
|
|
}
|
|
VerifyQuery: fmt.Print(upAndLeft) // Move up one and over all
|
|
fmt.Print(style.Input)
|
|
fmt.Printf("%s%s%sIs %q correct? (y/n/c)", cursorEnd, upAndLeft, style.Input, line)
|
|
conf = Getch()
|
|
if conf == 'y' {
|
|
break
|
|
} else if conf == 'n' {
|
|
fmt.Print(cursorEnd)
|
|
continue
|
|
} else if conf == 'c' {
|
|
err = fmt.Errorf("Cancelled")
|
|
break
|
|
} else {
|
|
fmt.Print(cursorEnd)
|
|
goto VerifyQuery
|
|
}
|
|
}
|
|
return line, err
|
|
}
|
|
|
|
func main() {
|
|
style.Init(SimpleColor)
|
|
cols, rows := termios.GetWindowSize()
|
|
board = Board{
|
|
Title: "My Test Board",
|
|
Body: "Some misc info",
|
|
Created: time.Now(),
|
|
Lanes: make([]Lane, 0, 1),
|
|
Current: -1,
|
|
LaneOff: 0,
|
|
Message: "Welcome to SWIM",
|
|
MsgErr: false,
|
|
Width: cols,
|
|
Height: rows,
|
|
Zoom: 3}
|
|
|
|
board.Run()
|
|
}
|