diff --git a/clocks/display.go b/clocks/display.go new file mode 100644 index 00000000..3eea0298 --- /dev/null +++ b/clocks/display.go @@ -0,0 +1,32 @@ +package clocks + +import ( + "fmt" + "strings" +) + +func (widget *Widget) display() { + locs := widget.locations(Config.UMap("wtf.mods.clocks.locations")) + + if len(locs) == 0 { + fmt.Fprintf(widget.View, "\n%s", " no timezone data available") + return + } + + labels := widget.sortedLabels(locs) + + tzs := []string{} + for idx, label := range labels { + zoneStr := fmt.Sprintf( + " [%s]%-12s %-10s %7s[white]", + widget.colorFor(idx), + label, + locs[label].Format(TimeFormat), + locs[label].Format(DateFormat), + ) + + tzs = append(tzs, zoneStr) + } + + fmt.Fprintf(widget.View, "\n%s", strings.Join(tzs, "\n")) +} diff --git a/clocks/widget.go b/clocks/widget.go index 88c008be..e6bafc7e 100644 --- a/clocks/widget.go +++ b/clocks/widget.go @@ -1,9 +1,7 @@ package clocks import ( - "fmt" "sort" - "strings" "time" "github.com/olebedev/config" @@ -52,32 +50,6 @@ func (widget *Widget) colorFor(idx int) string { return rowColor } -func (widget *Widget) display() { - locs := widget.locations(Config.UMap("wtf.mods.clocks.locations")) - - if len(locs) == 0 { - fmt.Fprintf(widget.View, "\n%s", " no timezone data available") - return - } - - labels := widget.sortedLabels(locs) - - tzs := []string{} - for idx, label := range labels { - zoneStr := fmt.Sprintf( - " [%s]%-12s %-10s %7s[white]", - widget.colorFor(idx), - label, - locs[label].Format(TimeFormat), - locs[label].Format(DateFormat), - ) - - tzs = append(tzs, zoneStr) - } - - fmt.Fprintf(widget.View, "\n%s", strings.Join(tzs, "\n")) -} - func (widget *Widget) locations(locs map[string]interface{}) map[string]time.Time { times := make(map[string]time.Time) diff --git a/gcal/client.go b/gcal/client.go index 19f97f4a..94bbd93d 100644 --- a/gcal/client.go +++ b/gcal/client.go @@ -17,7 +17,7 @@ import ( "path/filepath" "time" - "github.com/senorprogrammer/wtf/homedir" + "github.com/senorprogrammer/wtf/wtf" "golang.org/x/net/context" "golang.org/x/oauth2" "golang.org/x/oauth2/google" @@ -29,7 +29,7 @@ import ( func Fetch() (*calendar.Events, error) { ctx := context.Background() - secretPath, _ := homedir.Expand(Config.UString("wtf.mods.gcal.secretFile")) + secretPath, _ := wtf.ExpandHomeDir(Config.UString("wtf.mods.gcal.secretFile")) b, err := ioutil.ReadFile(secretPath) if err != nil { diff --git a/textfile/widget.go b/textfile/widget.go index 13918ef6..f829d0db 100644 --- a/textfile/widget.go +++ b/textfile/widget.go @@ -6,7 +6,6 @@ import ( "time" "github.com/olebedev/config" - "github.com/senorprogrammer/wtf/homedir" "github.com/senorprogrammer/wtf/wtf" ) @@ -54,7 +53,7 @@ func (widget *Widget) Refresh() { /* -------------------- Uneported Functions -------------------- */ func (widget *Widget) readFile() (string, error) { - absPath, _ := homedir.Expand(widget.FilePath) + absPath, _ := wtf.ExpandHomeDir(widget.FilePath) bytes, err := ioutil.ReadFile(absPath) if err != nil { diff --git a/color/colors.go b/wtf/colors.go similarity index 99% rename from color/colors.go rename to wtf/colors.go index 7d7bea55..44bf71bb 100644 --- a/color/colors.go +++ b/wtf/colors.go @@ -1,4 +1,4 @@ -package color +package wtf import ( "github.com/gdamore/tcell" diff --git a/wtf/config_files.go b/wtf/config_files.go index bf377f89..fd260aa2 100644 --- a/wtf/config_files.go +++ b/wtf/config_files.go @@ -5,12 +5,11 @@ import ( "os" "github.com/olebedev/config" - "github.com/senorprogrammer/wtf/homedir" ) // CreateConfigDir creates the .wtf directory in the user's home dir func CreateConfigDir() bool { - homeDir, _ := homedir.Expand("~/.wtf/") + homeDir, _ := ExpandHomeDir("~/.wtf/") if _, err := os.Stat(homeDir); os.IsNotExist(err) { err := os.Mkdir(homeDir, os.ModePerm) @@ -24,7 +23,7 @@ func CreateConfigDir() bool { // LoadConfigFile loads the config.yml file to configure the app func LoadConfigFile(filePath string) *config.Config { - absPath, _ := homedir.Expand(filePath) + absPath, _ := ExpandHomeDir(filePath) cfg, err := config.ParseYamlFile(absPath) if err != nil { diff --git a/wtf/focus_tracker.go b/wtf/focus_tracker.go index f1c44fc4..76ac5edf 100644 --- a/wtf/focus_tracker.go +++ b/wtf/focus_tracker.go @@ -2,7 +2,6 @@ package wtf import ( "github.com/rivo/tview" - "github.com/senorprogrammer/wtf/color" ) // FocusTracker is used by the app to track which onscreen widget currently has focus, @@ -41,7 +40,7 @@ func (tracker *FocusTracker) Prev() { func (tracker *FocusTracker) blur(idx int) { view := tracker.Widgets[idx].TextView() view.Blur() - view.SetBorderColor(color.ColorFor(Config.UString("wtf.border.normal"))) + view.SetBorderColor(ColorFor(Config.UString("wtf.border.normal"))) } func (tracker *FocusTracker) decrement() { @@ -55,7 +54,7 @@ func (tracker *FocusTracker) decrement() { func (tracker *FocusTracker) focus(idx int) { view := tracker.Widgets[idx].TextView() tracker.App.SetFocus(view) - view.SetBorderColor(color.ColorFor(Config.UString("wtf.border.focus"))) + view.SetBorderColor(ColorFor(Config.UString("wtf.border.focus"))) } func (tracker *FocusTracker) increment() { diff --git a/homedir/homedir.go b/wtf/homedir.go similarity index 83% rename from homedir/homedir.go rename to wtf/homedir.go index 61f77ba3..ef43abf7 100644 --- a/homedir/homedir.go +++ b/wtf/homedir.go @@ -1,8 +1,8 @@ // Package homedir helps with detecting and expanding the user's home directory -// Copied verbatim from https://github.com/Atrox/homedir +// Copied (mostly) verbatim from https://github.com/Atrox/homedir -package homedir +package wtf import ( "errors" @@ -12,7 +12,7 @@ import ( // Dir returns the home directory for the executing user. // An error is returned if a home directory cannot be detected. -func Dir() (string, error) { +func Home() (string, error) { currentUser, err := user.Current() if err != nil { return "", err @@ -27,7 +27,7 @@ func Dir() (string, error) { // Expand expands the path to include the home directory if the path // is prefixed with `~`. If it isn't prefixed with `~`, the path is // returned as-is. -func Expand(path string) (string, error) { +func ExpandHomeDir(path string) (string, error) { if len(path) == 0 { return path, nil } @@ -40,7 +40,7 @@ func Expand(path string) (string, error) { return "", errors.New("cannot expand user-specific home dir") } - dir, err := Dir() + dir, err := Home() if err != nil { return "", err } diff --git a/wtf/text_widget.go b/wtf/text_widget.go index 3b85601f..129cc13a 100644 --- a/wtf/text_widget.go +++ b/wtf/text_widget.go @@ -6,7 +6,6 @@ import ( "github.com/olebedev/config" "github.com/rivo/tview" - "github.com/senorprogrammer/wtf/color" ) var Config *config.Config @@ -42,18 +41,6 @@ func NewTextWidget(name string, configKey string) TextWidget { /* -------------------- Exported Functions -------------------- */ -//func (widget *TextWidget) SetBorder() { - //var colorName string - - //if widget.View.HasFocus() { - //colorName = Config.UString("wtf.border.normal") - //} else { - //colorName = Config.UString("wtf.border.focus") - //} - - //widget.View.SetBorderColor(color.ColorFor(colorName)) -//} - func (widget *TextWidget) Disabled() bool { return !widget.Enabled() } @@ -76,11 +63,10 @@ func (widget *TextWidget) addView() { view := tview.NewTextView() view.SetBorder(true) - view.SetBorderColor(color.ColorFor(Config.UString("wtf.border.normal"))) + view.SetBorderColor(ColorFor(Config.UString("wtf.border.normal"))) view.SetDynamicColors(true) view.SetTitle(widget.Name) view.SetWrap(false) widget.View = view } -