Skip to content

Commit

Permalink
Merge pull request #14 from jboelter/master
Browse files Browse the repository at this point in the history
add ignore-interrupts option
  • Loading branch information
aybabtme authored Jul 9, 2017
2 parents 8a4c996 + 09c6d21 commit 345d339
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
14 changes: 13 additions & 1 deletion cmd/humanlog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"log"
"os"
"os/signal"
"strings"

"github.com/aybabtme/humanlog"
"github.com/aybabtme/rgbterm"
Expand Down Expand Up @@ -81,14 +83,19 @@ func newApp() *cli.App {
Value: humanlog.DefaultOptions.TimeFormat,
}

ignoreInterrupts := cli.BoolFlag{
Name: "ignore-interrupts, i",
Usage: "ignore interrupts",
}

app := cli.NewApp()
app.Author = "Antoine Grondin"
app.Email = "antoine@digitalocean.com"
app.Name = "humanlog"
app.Version = version
app.Usage = "reads structured logs from stdin, makes them pretty on stdout!"

app.Flags = []cli.Flag{skipFlag, keepFlag, sortLongest, skipUnchanged, truncates, truncateLength, lightBg, timeFormat}
app.Flags = []cli.Flag{skipFlag, keepFlag, sortLongest, skipUnchanged, truncates, truncateLength, lightBg, timeFormat, ignoreInterrupts}

app.Action = func(c *cli.Context) error {

Expand All @@ -99,6 +106,7 @@ func newApp() *cli.App {
opts.TruncateLength = c.Int(truncateLength.Name)
opts.LightBg = c.BoolT(lightBg.Name)
opts.TimeFormat = c.String(timeFormat.Name)
opts.IgnoreInterrupts = c.BoolT(ignoreInterrupts.Name)

switch {
case c.IsSet(skipFlag.Name) && c.IsSet(keepFlag.Name):
Expand All @@ -109,6 +117,10 @@ func newApp() *cli.App {
opts.SetKeep(keep)
}

if c.IsSet(strings.Split(ignoreInterrupts.Name, ",")[0]) {
signal.Ignore(os.Interrupt)
}

log.Print("reading stdin...")
if err := humanlog.Scanner(os.Stdin, colorable.NewColorableStdout(), opts); err != nil {
log.Fatalf("scanning caught an error: %v", err)
Expand Down
38 changes: 20 additions & 18 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,33 @@ type Handler interface {
}

var DefaultOptions = &HandlerOptions{
SortLongest: true,
SkipUnchanged: true,
Truncates: true,
LightBg: false,
TruncateLength: 15,
KeyRGB: RGB{1, 108, 89},
ValRGB: RGB{125, 125, 125},
TimeFormat: time.Stamp,
SortLongest: true,
SkipUnchanged: true,
Truncates: true,
LightBg: false,
TruncateLength: 15,
KeyRGB: RGB{1, 108, 89},
ValRGB: RGB{125, 125, 125},
TimeFormat: time.Stamp,
IgnoreInterrupts: false,
}

type RGB struct{ R, G, B uint8 }

func (r *RGB) tuple() (uint8, uint8, uint8) { return r.R, r.G, r.B }

type HandlerOptions struct {
Skip map[string]struct{}
Keep map[string]struct{}
SortLongest bool
SkipUnchanged bool
Truncates bool
LightBg bool
TruncateLength int
KeyRGB RGB
ValRGB RGB
TimeFormat string
Skip map[string]struct{}
Keep map[string]struct{}
SortLongest bool
SkipUnchanged bool
Truncates bool
LightBg bool
TruncateLength int
KeyRGB RGB
ValRGB RGB
TimeFormat string
IgnoreInterrupts bool
}

func (h *HandlerOptions) shouldShowKey(key string) bool {
Expand Down

0 comments on commit 345d339

Please sign in to comment.