Skip to content

Commit

Permalink
Create colorize function for colored outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed Dec 29, 2017
1 parent 43293a7 commit e27a37f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
14 changes: 9 additions & 5 deletions color.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package main

import "fmt"

func Red(s string) string {
return fmt.Sprintf("\033[3%d;%dm%s\033[0m", 1, 1, s)
}
const (
Red = 1
Green = 2
Yellow = 3
Blue = 4
Purple = 5
)

func Green(s string) string {
return fmt.Sprintf("\033[3%d;%dm%s\033[0m", 2, 1, s)
func Colorize(s string, c int) string {
return fmt.Sprintf("\033[3%d;%dm%s\033[0m", c, 1, s)
}
4 changes: 2 additions & 2 deletions conflict.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func (c *Conflict) Select(g *gocui.Gui) error {
for idx, conflict := range conflicts {
var out string
if conflict.Resolved {
out = Green(fmt.Sprintf("✅ %s:%d", conflict.FileName, conflict.Start))
out = Colorize(fmt.Sprintf("✅ %s:%d", conflict.FileName, conflict.Start), Green)
} else {
out = Red(fmt.Sprintf("%d. %s:%d", idx+1, conflict.FileName, conflict.Start))
out = Colorize(fmt.Sprintf("%d. %s:%d", idx+1, conflict.FileName, conflict.Start), Red)
}

if conflict.isEqual(c) {
Expand Down
6 changes: 3 additions & 3 deletions layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ func layout(g *gocui.Gui) error {
v.Title = "Conflicts"
}

if v, err := g.SetView("input prompt", 0, viewHeight, 15, viewHeight+inputHeight); err != nil {
if v, err := g.SetView("input prompt", 0, viewHeight, 14, viewHeight+inputHeight); err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Frame = false
prompt := Green("[a | d] >>")
prompt := Colorize("[wasd] >>", Green)
v.Write([]byte(prompt))
v.MoveCursor(11, 0, true)
}

if v, err := g.SetView("input", 11, 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
}
Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ func parseInput(g *gocui.Gui, v *gocui.View) error {
switch {
case in == "a":
conflicts[cur].Resolve(g, v, Local)
printPrompt(g, Green("[a | d] >>"))
case in == "d":
conflicts[cur].Resolve(g, v, Incoming)
printPrompt(g, Green("[a | d] >>"))
case in == "h":
conflicts[cur].Select(g, true)
default:
printPrompt(g, Red("[a | d] >>"))
printPrompt(g, Colorize("[wasd] >>", Red))
return nil
}
printPrompt(g, Colorize("[wasd] >>", Green))
return nil
}

Expand Down

0 comments on commit e27a37f

Please sign in to comment.