Skip to content

Commit

Permalink
Create custom editor class for the prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed Dec 29, 2017
1 parent 4faa632 commit 2fc3f18
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions prompt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import "github.com/jroimartin/gocui"

func promptEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
switch {
case ch != 0 && mod == 0:
v.EditWrite(ch)
case key == gocui.KeySpace:
v.EditWrite(' ')
case key == gocui.KeyBackspace || key == gocui.KeyBackspace2:
v.EditDelete(true)
case key == gocui.KeyDelete:
v.EditDelete(false)
case key == gocui.KeyInsert:
v.Overwrite = !v.Overwrite
case key == gocui.KeyEnter:
v.Clear()
v.SetCursor(0, 0)
case key == gocui.KeyArrowDown:
v.MoveCursor(0, 1, false)
case key == gocui.KeyArrowUp:
v.MoveCursor(0, -1, false)
case key == gocui.KeyArrowLeft:
v.MoveCursor(-1, 0, false)
case key == gocui.KeyArrowRight:
v.MoveCursor(1, 0, false)
}
}

0 comments on commit 2fc3f18

Please sign in to comment.