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

ability to switch color theme #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import "time"
type UIData struct {
Services []*Service
Vars []VarName
UITheme string
LastTimestamp time.Time
}

// NewUIData inits and return new data object.
func NewUIData(vars []VarName) *UIData {
func NewUIData(vars []VarName, theme string) *UIData {
return &UIData{
Vars: vars,
Vars: vars,
UITheme: theme,
}
}
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
dummy = flag.Bool("dummy", false, "Use dummy (console) output")
self = flag.Bool("self", false, "Monitor itself")
endpoint = flag.String("endpoint", DefaultEndpoint, "URL endpoint for expvars")
uiTheme = flag.String("theme", "dark", "UI color theme. Possible values: dark, default.")
)

func main() {
Expand Down Expand Up @@ -52,7 +53,7 @@ func main() {
}

// Init UIData
data := NewUIData(vars)
data := NewUIData(vars, ParseUiTheme(*uiTheme))
for _, port := range ports {
service := NewService(port, vars)
data.Services = append(data.Services, service)
Expand Down
2 changes: 1 addition & 1 deletion ui_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (t *TermUI) Init(data UIData) error {
return err
}

termui.UseTheme("helloworld")
termui.UseTheme(data.UITheme)

t.Title = func() *termui.Par {
p := termui.NewPar("")
Expand Down
2 changes: 1 addition & 1 deletion ui_single.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (t *TermUISingle) Init(data UIData) error {

t.Sparklines = make(map[VarName]*termui.Sparkline)

termui.UseTheme("helloworld")
termui.UseTheme(data.UITheme)

t.Title = func() *termui.Par {
p := termui.NewPar("")
Expand Down
8 changes: 8 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import (

var ErrParsePorts = fmt.Errorf("cannot parse ports argument")

func ParseUiTheme(theme string) string {
t := ""
if theme == "dark" {
t = "helloworld"
}
return t
}

// ParseVars returns parsed and validated slice of strings with
// variables names that will be used for monitoring.
func ParseVars(vars string) ([]VarName, error) {
Expand Down