Skip to content

Commit

Permalink
Change default view orientation and edit help
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed Jan 1, 2018
1 parent fbe44e5 commit 532d3c9
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 8 deletions.
64 changes: 60 additions & 4 deletions layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,88 @@ const (
Incoming = 2
Up = 3
Down = 4

Horizontal = 5
Vertical = -6
)

var (
ViewOrientation = Vertical
inputHeight = 2
)

func layout(g *gocui.Gui) error {
func layout(g *gocui.Gui) (err error) {
if err = makePanels(g); err != nil {
return
}

if err = makeOverviewPanel(g); err != nil {
return
}

if err = makePrompt(g); err != nil {
return
}
return
}

func makePanels(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 {
var x0, x1, y0, y1 int
var x2, x3, y2, y3 int

if ViewOrientation == Horizontal {
x0, x1 = 0, branchViewWidth
y0, y1 = 0, viewHeight
x2, x3 = branchViewWidth, branchViewWidth*2
y2, y3 = 0, viewHeight

} else {
branchViewWidth = branchViewWidth * 2
viewHeight = viewHeight / 2

x0, x1 = 0, branchViewWidth
y0, y1 = 0, viewHeight
x2, x3 = 0, branchViewWidth
y2, y3 = viewHeight, viewHeight*2
}

if _, err := g.SetView(Current, x0, y0, x1, y1); 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, x2, y2, x3, y3); err != nil {
if err != gocui.ErrUnknownView {
return err
}
}

return nil
}

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

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

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

if v, err := g.SetView(Prompt, 0, viewHeight, 14, viewHeight+inputHeight); err != nil {
if err != gocui.ErrUnknownView {
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func parseInput(g *gocui.Gui, v *gocui.View) error {
MoveToItem(Down, g, v)
case in == 'p':
MoveToItem(Up, g, v)
case in == 'v':
ViewOrientation = ^ViewOrientation
layout(g)
case in == 'h' || in == '?':
Select(&conflict.All[cur], g, true)
case in == 'q':
Expand Down
9 changes: 5 additions & 4 deletions summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ func printHelp(v *gocui.View) {
j - scroll down
k - scroll up
n - next conflict
p - previous conflict
v - [v]iew orientation
n - [n]ext conflict
p - [p]revious conflict
h | ? - print help
q | Ctrl+c - quit
h | ? - [h]elp
q | Ctrl+c - [q]uit
`
fmt.Fprintf(v, color.Blue(color.Regular, instruction))
}
Expand Down

0 comments on commit 532d3c9

Please sign in to comment.