Skip to content

Commit

Permalink
Add colors to main
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Aug 25, 2017
1 parent 5b50a18 commit 6c9307a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
35 changes: 35 additions & 0 deletions main.go
Expand Up @@ -3,8 +3,11 @@ package main
import (
"fmt"
"os"
"os/exec"
"path"
"time"

"github.com/fatih/color"
gojot "github.com/schollz/gojot/src"
"github.com/urfave/cli"
)
Expand All @@ -28,6 +31,38 @@ func main() {
},
}
app.Action = func(c *cli.Context) (err error) {
if version == "" {
p := path.Join(os.Getenv("GOPATH"), "src", "github.com", "schollz", "gojot")
_, err := os.Stat(p)
fmt.Println(p, err)
if err == nil {
cwd, err2 := os.Getwd()
if err2 != nil {
return err2
}
os.Chdir(p)
cmd := exec.Command("git", "rev-parse", "HEAD")
stdoutStderr, err2 := cmd.CombinedOutput()
if err2 != nil {
return err2
}
version = string(stdoutStderr)[:8]
os.Chdir(cwd)
} else {
version = "?"
}
}

color.Set(color.FgYellow, color.Bold)
fmt.Println(`
___ __ __ __ ____
/ __) / \ _( ) / \(_ _)
( (_ \( O )/ \) \( O ) )(
\___/ \__/ \____/ \__/ (__)
`)

fmt.Printf("version %s\n\n", version)
color.Unset()
return gojot.Run()
}

Expand Down
1 change: 1 addition & 0 deletions src/gojot.go
Expand Up @@ -469,6 +469,7 @@ func (gj *gojot) SaveDocuments(docs Documents) (err error) {
err = err2
return
}
fmt.Printf("Saved '%s' in document '%s'\n", docs[i].Front.Entry, docs[i].Front.Document)
}
}
return
Expand Down
14 changes: 3 additions & 11 deletions src/run.go
Expand Up @@ -6,19 +6,10 @@ import (
"github.com/fatih/color"
)

var highlight = color.New(color.FgYellow).SprintFunc()

func Run() (err error) {
// TODO: Unbundle vim
color.Set(color.FgYellow, color.Bold)
fmt.Println(`
___ __ __ __ ____
/ __) / \ _( ) / \(_ _)
( (_ \( O )/ \) \( O ) )(
\___/ \__/ \____/ \__/ (__)
`)
color.Unset()
gj, err := New(true)

gj, err := New(false)
if err != nil {
return
}
Expand All @@ -29,6 +20,7 @@ func Run() (err error) {
repoString := gj.RepoString
identity := gj.IdentityString
if len(repoString) > 0 && len(identity) > 0 {
highlight := color.New(color.FgYellow).SprintFunc()
fmt.Printf("Loading settings for '%s' \nin repo '%s'\n\nTo load new repo, use -new\n\n", highlight(identity), highlight(repoString))
} else {
repoString = ""
Expand Down

0 comments on commit 6c9307a

Please sign in to comment.