Skip to content

Commit

Permalink
allow changing color theme
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Winther <jippignu@gmail.com>
  • Loading branch information
jippi committed Nov 19, 2018
1 parent 55de5f7 commit c917134
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions command/tail/color_log_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import (
)

type colorLogWriter struct {
Type string
Type string
Theme string
}

func (w colorLogWriter) Write(p []byte) (n int, err error) {
s := string(p)

if string(s[0]) == "{" {
buffer := bytes.NewBufferString("")
highlight(buffer, s, "json", "terminal", "emacs")
highlight(buffer, s, "json", "terminal", w.Theme)
s = buffer.String()
}

Expand Down
8 changes: 4 additions & 4 deletions command/tail/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ func Run(c *cli.Context) error {
if c.BoolT("stdout") {
wg.Add(1)
logger := log.WithField("log_type", "stdout")
go Tail(getWriter("stdout", c.String("writer")), "stderr", taskName, alloc, nomadClient, &wg, logger)
go Tail(getWriter("stdout", c.String("writer"), c.String("theme")), "stderr", taskName, alloc, nomadClient, &wg, logger)
}

if c.BoolT("stderr") {
wg.Add(1)
logger := log.WithField("log_type", "stderr")
go Tail(getWriter("stderr", c.String("writer")), "stdout", taskName, alloc, nomadClient, &wg, logger)
go Tail(getWriter("stderr", c.String("writer"), c.String("theme")), "stdout", taskName, alloc, nomadClient, &wg, logger)
}

go func() {
Expand All @@ -76,10 +76,10 @@ func Run(c *cli.Context) error {
return nil
}

func getWriter(target, kind string) io.Writer {
func getWriter(target, kind, theme string) io.Writer {
switch kind {
case "color":
return colorLogWriter{Type: target}
return colorLogWriter{Type: target, Theme: theme}
case "simple":
return simpleLogWriter{Type: target}
case "raw":
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ func main() {
Value: "color",
Usage: "(optional, default: color) writer type (raw, color, simple)",
},
cli.StringFlag{
Name: "theme, ct",
Value: "emacs",
Usage: "(optional, default: emacs) Chroma color scheme to use - see https://xyproto.github.io/splash/docs/",
},
},
Action: func(c *cli.Context) error {
if err := tail.Run(c); err != nil {
Expand Down

0 comments on commit c917134

Please sign in to comment.