diff --git a/layout.go b/layout.go index 697fa83..b6f81a4 100644 --- a/layout.go +++ b/layout.go @@ -155,7 +155,7 @@ func Select(c *conflict.Conflict, g *gocui.Gui, showHelp bool) error { } if showHelp { - printHelp(v) + printHelp(v, &binding) } return nil }) diff --git a/main.go b/main.go index 061e221..a2f072c 100644 --- a/main.go +++ b/main.go @@ -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) { @@ -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 { diff --git a/prompt.go b/prompt.go index 96046a9..b56892d 100644 --- a/prompt.go +++ b/prompt.go @@ -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" @@ -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) @@ -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 diff --git a/summary.go b/summary.go index aac5380..1e321cb 100644 --- a/summary.go +++ b/summary.go @@ -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) {