diff --git a/service-monitor/logscmd.go b/service-monitor/logscmd.go index e4ca230..1d291fe 100644 --- a/service-monitor/logscmd.go +++ b/service-monitor/logscmd.go @@ -40,6 +40,8 @@ func logsForm() (tview.Primitive, error) { errLogView := tview.NewTextView() errLogView.ScrollToEnd() + list.SetMainTextColor(tcell.GetColor(theme.Colors["Service"])) + list.SetSecondaryTextColor(tcell.GetColor(theme.Colors["Description"])) list. SetDoneFunc(func() { app.SetFocus(logView) diff --git a/service-monitor/main.go b/service-monitor/main.go index 3c85359..1f17d9b 100644 --- a/service-monitor/main.go +++ b/service-monitor/main.go @@ -2,6 +2,7 @@ package main import ( "os" + "strings" "github.com/rivo/tview" "github.com/spf13/cobra" @@ -22,10 +23,26 @@ var ( apperr error app = tview.NewApplication() menu = NewMenu(app) - search string + + search string + themeArg string ) +func parseTheme() { + switch strings.ToLower(themeArg) { + case "ice": + theme = IceTheme + case "terminal": + theme = TerminalTheme + default: + panic("no such theme: " + themeArg) + } +} + func main() { + RootCmd.PersistentFlags().StringVar(&themeArg, "theme", "terminal", "color scheme (ice, terminal)") + cobra.OnInitialize(parseTheme) + if err := RootCmd.Execute(); err != nil { os.Exit(-1) } diff --git a/service-monitor/menu.go b/service-monitor/menu.go index d274041..c30192b 100644 --- a/service-monitor/menu.go +++ b/service-monitor/menu.go @@ -44,10 +44,10 @@ func (m *Menu) Draw(screen tcell.Screen) { x++ for _, i := range m.Items { - tview.Print(screen, tcell.KeyNames[i.Shortcut], x, y, width-2, tview.AlignLeft, tcell.ColorYellow) + tview.Print(screen, tcell.KeyNames[i.Shortcut], x, y, width-2, tview.AlignLeft, tcell.GetColor(theme.Colors["Shortcut"])) x += 3 - tview.Print(screen, i.Text, x, y, width, tview.AlignLeft, tcell.ColorTeal) + tview.Print(screen, i.Text, x, y, width, tview.AlignLeft, tcell.GetColor(theme.Colors["Menu"])) x += runewidth.StringWidth(i.Text) + 2 } } diff --git a/service-monitor/pipe.go b/service-monitor/pipe.go index cb8a2c9..9a5e334 100644 --- a/service-monitor/pipe.go +++ b/service-monitor/pipe.go @@ -98,7 +98,7 @@ func pipeReader(r *LogPipe, w io.Writer) { } func logFormatter(entry *sdjournal.JournalEntry) (string, error) { - color := "gray" + color := theme.Colors["Message"] switch entry.Fields["PRIORITY"] { case "0": fallthrough @@ -107,14 +107,17 @@ func logFormatter(entry *sdjournal.JournalEntry) (string, error) { case "2": fallthrough case "3": - color = "red" + color = theme.Colors["Error"] case "4": - color = "darkred" + color = theme.Colors["Warning"] case "5": - color = "silver" + color = theme.Colors["Notice"] } - return fmt.Sprintf("[green]%s [blue]%s [%s]%s\n", + + return fmt.Sprintf("[%s]%s [%s]%s [%s]%s\n", + theme.Colors["Timestamp"], time.Unix(0, int64(entry.RealtimeTimestamp)*int64(time.Microsecond)).Format("Jan 02 15:04:05"), + theme.Colors["Service"], entry.Fields["SYSLOG_IDENTIFIER"], color, entry.Fields["MESSAGE"]), nil diff --git a/service-monitor/servicescmd.go b/service-monitor/servicescmd.go index 7b47d87..27ac516 100644 --- a/service-monitor/servicescmd.go +++ b/service-monitor/servicescmd.go @@ -37,6 +37,9 @@ func servicesForm() (tview.Primitive, error) { pages := tview.NewPages() confirmDialog := tview.NewModal() list := NewServicesView() + list.SetMainTextColor(tcell.GetColor(theme.Colors["Service"])) + list.SetSecondaryTextColor(tcell.GetColor(theme.Colors["Description"])) + err := list.loadModel(false, activeOnly) if err != nil { return nil, err diff --git a/service-monitor/theme.go b/service-monitor/theme.go new file mode 100644 index 0000000..649f7f6 --- /dev/null +++ b/service-monitor/theme.go @@ -0,0 +1,40 @@ +package main + +type Theme struct { + Name string + Colors map[string]string +} + +var ( + IceTheme = Theme{ + Name: "Ice", + Colors: map[string]string{ + "Error": "#aacdee", + "Warning": "#7997d6", + "Notice": "#5b73b4", + "Message": "gray", + "Timestamp": "#003d6b", + "Service": "#d5d8f0", + "Shortcut": "#00ffdf", + "Menu": "#85e7d2", + "Description": "#003d6b", + }, + } + + TerminalTheme = Theme{ + Name: "Terminal", + Colors: map[string]string{ + "Error": "red", + "Warning": "darkred", + "Notice": "silver", + "Message": "gray", + "Timestamp": "green", + "Service": "blue", + "Shortcut": "yellow", + "Menu": "teal", + "Description": "green", + }, + } + + theme = TerminalTheme +)