Skip to content

Commit

Permalink
Update to use custom key bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed May 27, 2018
1 parent 7b53a69 commit 48b1230
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 37 deletions.
2 changes: 1 addition & 1 deletion layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func Select(c *conflict.Conflict, g *gocui.Gui, showHelp bool) error {
}

if showHelp {
printHelp(v)
printHelp(v, &binding)
}
return nil
})
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
"github.com/mkchoi212/fac/color"
"github.com/mkchoi212/fac/conflict"
"github.com/mkchoi212/fac/editor"
"github.com/mkchoi212/fac/key"
)

var (
conflicts = []*conflict.Conflict{}
cur = 0
consecutiveError = 0
binding = key.Binding{}
)

func printLines(v *gocui.View, lines []string) {
Expand Down Expand Up @@ -129,6 +131,13 @@ func die(err error) {
}

func main() {
var err error

binding, err = key.LoadSettings()
if err != nil {
die(err)
}

// Find and parse conflicts
files, err := findConflicts()
if err != nil {
Expand Down
30 changes: 16 additions & 14 deletions prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"errors"
"fmt"

"github.com/mkchoi212/fac/key"

"github.com/jroimartin/gocui"
"github.com/mkchoi212/fac/color"
"github.com/mkchoi212/fac/conflict"
Expand All @@ -20,7 +22,7 @@ var ErrOpenEditor = errors.New("Screen is tainted after opening vim")
// Note that the prompt is composed of two seperate views,
// one that displays just the promptString, and another that takes input from the user
func PrintPrompt(g *gocui.Gui) {
promptString := "[w,a,s,d,e,?] >>"
promptString := binding.Summary()

g.Update(func(g *gocui.Gui) error {
v, err := g.View(Prompt)
Expand All @@ -44,33 +46,33 @@ func PrintPrompt(g *gocui.Gui) {
// It also returns `ErrNeedRefresh` if user uses `e` command to open vim
func Evaluate(g *gocui.Gui, v *gocui.View, conf *conflict.Conflict, input string) (err error) {
for _, c := range input {
switch c {
case 'j':
switch string(c) {
case binding[key.ScrollUp]:
Scroll(g, conflicts[cur], Up)
case 'k':
case binding[key.ScrollDown]:
Scroll(g, conflicts[cur], Down)
case 'w':
case binding[key.ShowLinesUp]:
conflicts[cur].TopPeek++
Select(conflicts[cur], g, false)
case 's':
case binding[key.ShowLinesDown]:
conflicts[cur].BottomPeek++
Select(conflicts[cur], g, false)
case 'a':
case binding[key.SelectLocal]:
Resolve(conflicts[cur], g, v, conflict.Local)
case 'd':
case binding[key.SelectIncoming]:
Resolve(conflicts[cur], g, v, conflict.Incoming)
case 'n':
case binding[key.NextConflict]:
MoveToItem(Down, g, v)
case 'p':
case binding[key.PreviousConflict]:
MoveToItem(Up, g, v)
case 'v':
case binding[key.ToggleViewOrientation]:
ViewOrientation = ^ViewOrientation
layout(g)
case 'e':
case binding[key.EditCode]:
return ErrOpenEditor
case 'h', '?':
case binding[key.ShowHelp], "?":
Select(conflicts[cur], g, true)
case 'q':
case binding[key.QuitApplication]:
globalQuit(g)
default:
return ErrUnknownCmd
Expand Down
26 changes: 4 additions & 22 deletions summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,13 @@ import (
"fmt"
"io"

"github.com/mkchoi212/fac/conflict"

"github.com/mkchoi212/fac/color"
"github.com/mkchoi212/fac/conflict"
"github.com/mkchoi212/fac/key"
)

var instruction = `
w - show more lines up
s - show more lines down
a - use local version
d - use incoming version
e - manually edit code
j - scroll down
k - scroll up
v - [v]iew orientation
n - [n]ext conflict
p - [p]revious conflict
h | ? - [h]elp
q | Ctrl+c - [q]uit
`

func printHelp(v io.Writer) {
fmt.Fprintf(v, color.Blue(color.Regular, instruction))
func printHelp(v io.Writer, binding *key.Binding) {
fmt.Fprintf(v, color.Blue(color.Regular, binding.Help()))
}

func printSummary(conflicts []*conflict.Conflict) {
Expand Down

0 comments on commit 48b1230

Please sign in to comment.