Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ignore-interrupts option #14

Merged
merged 1 commit into from
Jul 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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