Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed Dec 27, 2017
0 parents commit 4c83e3e
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test
113 changes: 113 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright 2014 The gocui Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
"fmt"
"log"

"github.com/jroimartin/gocui"
)

var (
current = 0
conflictCount = 2
conflicts = [...]string{"index.js: 110", "style.css: 69"}
)

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

if v, err := g.SetView("master", 0, 0, branchViewWidth, height); err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Title = "master"
}

if v, err := g.SetView("merge", branchViewWidth, 0, branchViewWidth*2, height); err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Title = "merge"
}

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

func selectConflict(i int, v *gocui.View) error {
//fmt.Fprintf(v, "✅ \033[3%d;%dmindex.js: 110\033[0m\n", 2, 1)
//fmt.Fprintf(v, "2. \033[3%d;%dmstyle.css: 59\033[0m\n", 1, 7)

for idx, conflict := range conflicts {
if idx == i {
fmt.Fprintf(v, "%d. %s <-\n", idx+1, conflict)
} else {
fmt.Fprintf(v, "%d. %s\n", idx+1, conflict)
}
}
return nil
}

func nextConflict(g *gocui.Gui, v *gocui.View) error {
current = current + 1
if current >= conflictCount {
current = 0
}

g.Update(func(g *gocui.Gui) error {
v, err := g.View("panel")
if err != nil {
return nil
}
v.Clear()
selectConflict(current, v)
return nil
})
return nil
}

func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}

func keyBindings(g *gocui.Gui) error {
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
return err
}

if err := g.SetKeybinding("", gocui.KeyTab, gocui.ModNone, nextConflict); err != nil {
return err
}

return nil
}

func main() {
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
log.Panicln(err)
}
defer g.Close()

g.SetManagerFunc(layout)

if err := keyBindings(g); err != nil {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
log.Panicln(err)
}
}

0 comments on commit 4c83e3e

Please sign in to comment.