Skip to content

Commit

Permalink
Change package 'key' to 'binding'
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed Jun 9, 2018
1 parent 0a38b45 commit 3fb2cca
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 28 deletions.
3 changes: 3 additions & 0 deletions binding/.fac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cont_eval: kinda
select_incoming: i
select_local: i
File renamed without changes.
2 changes: 1 addition & 1 deletion key/key.go → binding/binding.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package key
package binding

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion key/key_test.go → binding/binding_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package key
package binding

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func Select(g *gocui.Gui, c *conflict.Conflict, showHelp bool) error {
}

if showHelp {
PrintHelp(v, &binding)
PrintHelp(v, &keyBinding)
}
return nil
})
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (
"strings"

"github.com/jroimartin/gocui"
"github.com/mkchoi212/fac/binding"
"github.com/mkchoi212/fac/color"
"github.com/mkchoi212/fac/conflict"
"github.com/mkchoi212/fac/editor"
"github.com/mkchoi212/fac/key"
)

var (
viewOrientation = Vertical
conflicts = []*conflict.Conflict{}
binding = key.Binding{}
keyBinding = binding.Binding{}
cur = 0
consecutiveErrCnt = 0
g *gocui.Gui
Expand Down Expand Up @@ -112,7 +112,7 @@ func die(err error) {
func main() {
var err error

binding, err = key.LoadSettings()
keyBinding, err = binding.LoadSettings()
if err != nil {
die(err)
}
Expand Down
39 changes: 19 additions & 20 deletions prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (
"fmt"
"strings"

"github.com/mkchoi212/fac/key"

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

g.Update(func(g *gocui.Gui) error {
v, err := g.View(Prompt)
Expand All @@ -48,33 +47,33 @@ func PrintPrompt(g *gocui.Gui) {
func Evaluate(g *gocui.Gui, v *gocui.View, conf *conflict.Conflict, input string) (err error) {
for _, c := range input {
switch string(c) {
case binding[key.ScrollUp]:
case keyBinding[binding.ScrollUp]:
Scroll(g, conflicts[cur], Up)
case binding[key.ScrollDown]:
case keyBinding[binding.ScrollDown]:
Scroll(g, conflicts[cur], Down)
case binding[key.ShowLinesUp]:
case keyBinding[binding.ShowLinesUp]:
conflicts[cur].TopPeek++
Select(g, conflicts[cur], false)
case binding[key.ShowLinesDown]:
case keyBinding[binding.ShowLinesDown]:
conflicts[cur].BottomPeek++
Select(g, conflicts[cur], false)
case binding[key.SelectLocal]:
case keyBinding[binding.SelectLocal]:
Resolve(g, v, conflicts[cur], conflict.Local)
case binding[key.SelectIncoming]:
case keyBinding[binding.SelectIncoming]:
Resolve(g, v, conflicts[cur], conflict.Incoming)
case binding[key.NextConflict]:
case keyBinding[binding.NextConflict]:
Move(g, v, Down)
case binding[key.PreviousConflict]:
case keyBinding[binding.PreviousConflict]:
Move(g, v, Up)
case binding[key.ToggleViewOrientation]:
case keyBinding[binding.ToggleViewOrientation]:
viewOrientation = ^viewOrientation
layout(g)
case binding[key.EditCode]:
return ErrOpenEditor
case binding[key.ShowHelp], "?":
case keyBinding[binding.EditCode]:
globalQuit(g, ErrOpenEditor)
case keyBinding[binding.ShowHelp], "?":
Select(g, conflicts[cur], true)
case binding[key.QuitApplication]:
globalQuit(g)
case keyBinding[binding.QuitApplication]:
globalQuit(g, gocui.ErrQuit)
default:
return ErrUnknownCmd
}
Expand Down Expand Up @@ -106,9 +105,9 @@ func ParseInput(g *gocui.Gui, v *gocui.View) error {

// PromptEditor handles user's interaction with the prompt
// Note that user's `ContinuousEvaluation` setting value changes its behavior
func PromptEditor(v *gocui.View, k gocui.Key, ch rune, mod gocui.Modifier) {
func PromptEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
if ch != 0 && mod == 0 {
if key.ContinuousEvaluation == "true" {
if keyBinding[binding.ContinuousEvaluation] == "true" {
v.Clear()
v.EditWrite(ch)
ParseInput(g, v)
Expand All @@ -119,7 +118,7 @@ func PromptEditor(v *gocui.View, k gocui.Key, ch rune, mod gocui.Modifier) {
return
}

switch k {
switch key {
case gocui.KeyEnter:
ParseInput(g, v)
v.Clear()
Expand Down
4 changes: 2 additions & 2 deletions summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"fmt"
"io"

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

// PrintHelp prints the current key binding rules in the side panel
func PrintHelp(v io.Writer, binding *key.Binding) {
func PrintHelp(v io.Writer, binding *binding.Binding) {
fmt.Fprintf(v, color.Blue(color.Regular, binding.Help()))
}

Expand Down

0 comments on commit 3fb2cca

Please sign in to comment.