Skip to content

Commit

Permalink
fix readme conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemackintosh committed Feb 20, 2023
1 parent c6e192d commit a8a508f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 35 deletions.
17 changes: 2 additions & 15 deletions .ninetails.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,10 @@ tails:
exit_on_match: true

- search: "INFO"
color: PURPLE
color: CUSTOM_PURPLE

- search: "DEBUG"
color: ORANGE

colors:
PURPLE: "38;5;129m"
PINK: "38;5;162m"
RED: "38;5;196m"
ORANGE: "38;5;208m"
YELLOW: "38;5;184m"
GREEN: "38;5;154m"
BLUE: "38;5;32m"
GREY: "38;5;242m"
DARKGREY: "38;5;239m"
LIGHTGREY: "38;5;249m"
BABYBLUE: "38;5;123m"
LIGHTPINK: "38;5;212m"
WHITE: "38;5;7m"
CLEAR: "0m"
CUSTOM_PURPLE: "38;5;128m"
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v1.0.4
- fixed stdin early exit in some scenarios
- defaulted colors to not rely on config, per feedback

v1.0.3
- fixed Sprintf directrive for certain file types

Expand Down
17 changes: 2 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,5 @@ tails:
color: ORANGE
colors:
PURPLE: "38;5;129m"
PINK: "38;5;162m"
RED: "38;5;196m"
ORANGE: "38;5;208m"
YELLOW: "38;5;184m"
GREEN: "38;5;154m"
BLUE: "38;5;32m"
GREY: "38;5;242m"
DARKGREY: "38;5;239m"
LIGHTGREY: "38;5;249m"
BABYBLUE: "38;5;123m"
LIGHTPINK: "38;5;212m"
WHITE: "38;5;7m"
CLEAR: "0m"
```
CUSTOM_PURPLE: "38;5;128m"
```
6 changes: 4 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ func main() {
// Check if the config was provided from stdin. To do so, we need
// to see if stdin was provided via a pipe, before we start blocking
// on the scanner read loop.
var usingStdin bool
fi, err := os.Stdin.Stat()
if err != nil {
panic(err)
}

// If there is stdin, read it
if fi.Mode()&os.ModeNamedPipe != 0 {
usingStdin = true
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
if len(scanner.Text()) > 0 {
Expand All @@ -77,7 +79,7 @@ func main() {
// Otherwise, look for files passed as arguments
var wg = &sync.WaitGroup{}
var args = flag.Args()
if len(args) == 0 {
if len(args) == 0 && !usingStdin {
fmt.Printf("no files specified")
os.Exit(1)
}
Expand Down Expand Up @@ -126,7 +128,7 @@ func readFile(wg *sync.WaitGroup, f string, c chan string) {
// Only show line numbers when we are not following
if flagWithLinenum && !flagWithFollow {
i = i + 1
formattedLine = fmt.Sprintf("%s:\033[38;5;232m%d\033[0m | ", f, i) + formattedLine
formattedLine = fmt.Sprintf("%s:%d | ", f, i) + formattedLine
} else {
formattedLine = fmt.Sprintf("%s | ", f) + formattedLine
}
Expand Down
24 changes: 21 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
package config

// Default Colors
var defaultColors = map[string]string{
"PURPLE": "38;5;129m",
"PINK": "38;5;162m",
"RED": "38;5;196m",
"ORANGE": "38;5;208m",
"YELLOW": "38;5;184m",
"GREEN": "38;5;154m",
"BLUE": "38;5;32m",
"GREY": "38;5;242m",
"DARKGREY": "38;5;239m",
"LIGHTGREY": "38;5;249m",
"BABYBLUE": "38;5;123m",
"LIGHTPINK": "38;5;212m",
"WHITE": "38;5;7m",
"CLEAR": "0m",
}

// Config is an instance of a configuration.
var Config = &Configuration{}
var Config *Configuration

// Configuration is the parsed structure of a configuration file.
type Configuration struct {
Expand All @@ -17,8 +35,8 @@ func Replace(s string) (string, bool) {
if m.re.MatchString(s) {
s, matched = m.Replace(s)

// If we are not combining the results,
// we should return early
// If we get an exit on match, ditch it.
// TODO: This should be refactored.
if m.ExitOnMatch {
return s, matched
}
Expand Down
15 changes: 15 additions & 0 deletions internal/config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ func Parse(f string) error {
m.re = r
}

// Set the instance config
Config = &config

// Check if default colors need to be set
if len(config.Colors) == 0 {
Config.Colors = defaultColors
return nil
}

// write back the default colors, skipping duplicates
for color, code := range defaultColors {
if _, ok := config.Colors[color]; !ok {
config.Colors[color] = code
}
}

return nil
}

0 comments on commit a8a508f

Please sign in to comment.