Skip to content

Commit

Permalink
Change string literals to const vars
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed Dec 30, 2017
1 parent 41b4847 commit 0a548c6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
10 changes: 6 additions & 4 deletions conflict.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type Conflict struct {

CurrentName string
ForeignName string

topPeek int
bottomPeek int
}

const (
Expand All @@ -36,7 +39,7 @@ func (c *Conflict) isEqual(c2 *Conflict) bool {

func (c *Conflict) Select(g *gocui.Gui, withHelp bool) error {
g.Update(func(g *gocui.Gui) error {
v, err := g.View("panel")
v, err := g.View(Panel)
if err != nil {
return err
}
Expand Down Expand Up @@ -64,7 +67,7 @@ func (c *Conflict) Select(g *gocui.Gui, withHelp bool) error {
})

g.Update(func(g *gocui.Gui) error {
v, err := g.View("current")
v, err := g.View(Current)
if err != nil {
return err
}
Expand All @@ -75,7 +78,7 @@ func (c *Conflict) Select(g *gocui.Gui, withHelp bool) error {

printLines(v, c.ColoredCurrentLines)

v, err = g.View("foreign")
v, err = g.View(Foreign)
if err != nil {
return err
}
Expand All @@ -87,7 +90,6 @@ func (c *Conflict) Select(g *gocui.Gui, withHelp bool) error {
printLines(v, c.ColoredForeignLines)
return nil
})

return nil
}

Expand Down
20 changes: 14 additions & 6 deletions layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,40 @@ import (
"github.com/jroimartin/gocui"
)

const (
Current = "current"
Foreign = "foreign"
Panel = "panel"
Prompt = "prompt"
Input = "input prompt"
)

func layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
inputHeight := 2
viewHeight := maxY - inputHeight
branchViewWidth := (maxX / 5) * 2

if _, err := g.SetView("current", 0, 0, branchViewWidth, viewHeight); err != nil {
if _, err := g.SetView(Current, 0, 0, branchViewWidth, viewHeight); err != nil {
if err != gocui.ErrUnknownView {
return err
}
}

if _, err := g.SetView("foreign", branchViewWidth, 0, branchViewWidth*2, viewHeight); err != nil {
if _, err := g.SetView(Foreign, branchViewWidth, 0, branchViewWidth*2, viewHeight); err != nil {
if err != gocui.ErrUnknownView {
return err
}
}

if v, err := g.SetView("panel", branchViewWidth*2, 0, maxX-2, viewHeight); err != nil {
if v, err := g.SetView(Panel, branchViewWidth*2, 0, maxX-2, viewHeight); err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Title = "Conflicts"
}

if v, err := g.SetView("input prompt", 0, viewHeight, 14, viewHeight+inputHeight); err != nil {
if v, err := g.SetView(Prompt, 0, viewHeight, 14, viewHeight+inputHeight); err != nil {
if err != gocui.ErrUnknownView {
return err
}
Expand All @@ -39,15 +47,15 @@ func layout(g *gocui.Gui) error {
v.MoveCursor(11, 0, true)
}

if v, err := g.SetView("input", 10, viewHeight, maxX, viewHeight+inputHeight); err != nil {
if v, err := g.SetView(Input, 10, viewHeight, maxX, viewHeight+inputHeight); err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Frame = false
v.Editable = true
v.Wrap = false
v.Editor = gocui.EditorFunc(promptEditor)
if _, err := g.SetCurrentView("input"); err != nil {
if _, err := g.SetCurrentView(Input); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func globalQuit(g *gocui.Gui) {

func printPrompt(g *gocui.Gui, str string) {
g.Update(func(g *gocui.Gui) error {
v, err := g.View("input prompt")
v, err := g.View(Prompt)
if err != nil {
return err
}
Expand Down

0 comments on commit 0a548c6

Please sign in to comment.