Skip to content

Commit

Permalink
feat: add theme arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
claby2 committed Jun 2, 2021
1 parent 8f072d3 commit 68ffa18
Showing 4 changed files with 35 additions and 14 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -7,4 +7,5 @@ require (
github.com/gizak/termui/v3 v3.1.0
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/nsf/termbox-go v0.0.0-20201124104050-ed494de23a00 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -37,6 +37,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
42 changes: 30 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
@@ -2,10 +2,12 @@ package main

import (
"bufio"
"flag"
"fmt"
"log"
"os"

"github.com/alecthomas/chroma/styles"
"github.com/spf13/pflag"
)

// Check is a helper function to error check functions which can be used to error check deferred functions
@@ -34,16 +36,26 @@ func getFileContent(filePath string) []string {

func main() {
var filePath string
flag.StringVar(&filePath, "f", "", "Parse given file as Makefile")
helpFlag := flag.Bool("h", false, "Print this message and exit")
allFlag := flag.Bool("a", false, "Display all targets including special built-in targets")
flag.Parse()
var theme string

pflag.StringVarP(&filePath, "file-name", "f", "", "Parse given file as Makefile")
help := pflag.BoolP("help", "h", false, "Print this message and exit")
all := pflag.BoolP("all", "a", false, "Display all targets including special built-in targets")
list := pflag.Bool("list-themes", false, "List built-in syntax highlighting themes")
pflag.StringVar(&theme, "theme", "vim", "Use a built-in syntax highlighting theme")
pflag.Parse()

if *helpFlag {
if *help {
// Print help message
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
os.Exit(1)
pflag.PrintDefaults()
os.Exit(0)
} else if *list {
fmt.Println("Built-in themes:")
for theme := range styles.Registry {
fmt.Println("\t" + theme)
}
os.Exit(0)
} else if filePath == "" {
// Attempt to find makefile in current directory
defaultMakefileNames := []string{"GNUmakefile", "makefile", "Makefile"}
@@ -57,16 +69,22 @@ func main() {
}
}
if !foundFile {
log.Fatal("no Makefile found")
os.Exit(1)
log.Fatalln("No Makefile found.")
}
}

if theme != "" {
// Ensure given theme exists in registry.
if _, ok := styles.Registry[theme]; !ok {
log.Fatalln("\"" + theme + "\" is not a built-in theme.")
}
}

content := NewParsedContent(filePath, getFileContent(filePath))
if *allFlag {
if *all {
content.SetIncludeSpecialTargets(true)
}
content.Parse()

Render(content)
Render(content, theme)
}
4 changes: 2 additions & 2 deletions render.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import (
)

// Render sets up and renders widgets to build the user interface
func Render(content *ParsedContent) {
func Render(content *ParsedContent, theme string) {
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
@@ -22,7 +22,7 @@ func Render(content *ParsedContent) {
target := NewTarget(0, len(content.Rules), content.Rules)
target.Rows = getTargets(content.Rules)

highlighter := NewHighlighter("vim")
highlighter := NewHighlighter(theme)

dependencyWidget := widgets.NewParagraph()
dependencyWidget.Title = "Dependencies"

0 comments on commit 68ffa18

Please sign in to comment.