Skip to content

Commit

Permalink
Start handling enter key from input prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed Dec 29, 2017
1 parent e4d7bc3 commit 6ea3727
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func selectConflict(i int, g *gocui.Gui) error {
for idx, conflict := range conflicts {
var out string
if conflict.Resolved {
out = fmt.Sprintf("✅ \033[3%d;%dm%s:%d \033[0m", 2, 1, conflict.FileName, conflict.Start)
out = Green(fmt.Sprintf("✅ %s:%d", conflict.FileName, conflict.Start))
} else {
out = fmt.Sprintf("%d. \033[3%d;%dm%s:%d \033[0m", idx+1, 1, 1, conflict.FileName, conflict.Start)
out = Red(fmt.Sprintf("%d. %s:%d", idx+1, conflict.FileName, conflict.Start))
}

if idx == i {
Expand Down Expand Up @@ -104,13 +104,29 @@ func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}

func keyBindings(g *gocui.Gui) error {
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
return err
}
func parseInput(g *gocui.Gui, v *gocui.View) error {
_ = v.Buffer()
v.Clear()
v.SetCursor(0, 0)

g.Update(func(g *gocui.Gui) error {
v, err := g.View("input prompt")
if err != nil {
return err
}
v.Clear()
v.Write([]byte(Red("[try h] >>")))
return nil
})
return nil
}

func keyBindings(g *gocui.Gui) error {
err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit)
err = g.SetKeybinding("", gocui.KeyEnter, gocui.ModNone, parseInput)
return err
}

func main() {
var err error
conflicts, err = Find()
Expand Down

0 comments on commit 6ea3727

Please sign in to comment.