From d7bc26684af331949ab5c87c8d57dff05ddbd845 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 22 Apr 2018 23:39:33 -0700 Subject: [PATCH] Some minor cleanup --- todo/display.go | 3 --- todo/widget.go | 2 +- wtf/config_files.go | 6 ++--- wtf/focus_tracker.go | 4 ++-- wtf/utils.go | 56 ++++++++++++++++++++++++-------------------- 5 files changed, 35 insertions(+), 36 deletions(-) diff --git a/todo/display.go b/todo/display.go index 45a0673f..82e8d4a8 100644 --- a/todo/display.go +++ b/todo/display.go @@ -7,9 +7,6 @@ import ( func (widget *Widget) display() { widget.View.Clear() - title := fmt.Sprintf(" 📝 %s ", widget.FilePath) - widget.View.SetTitle(title) - str := "" for idx, item := range widget.list.Items { foreColor, backColor := "white", "black" diff --git a/todo/widget.go b/todo/widget.go index 510ea382..a4ab4c42 100644 --- a/todo/widget.go +++ b/todo/widget.go @@ -117,7 +117,7 @@ func (widget *Widget) load() { confDir, _ := wtf.ConfigDir() filePath := fmt.Sprintf("%s/%s", confDir, widget.FilePath) - fileData, _ := wtf.ReadYamlFile(filePath) + fileData, _ := wtf.ReadFileBytes(filePath) yaml.Unmarshal(fileData, &widget.list) } diff --git a/wtf/config_files.go b/wtf/config_files.go index 0161b108..c19fb861 100644 --- a/wtf/config_files.go +++ b/wtf/config_files.go @@ -3,7 +3,6 @@ package wtf import ( "fmt" "os" - "io/ioutil" "github.com/olebedev/config" ) @@ -73,7 +72,6 @@ func LoadConfigFile(filePath string) *config.Config { return cfg } - func ReadFile(fileName string) (string, error) { configDir, err := ConfigDir() if err != nil { @@ -82,10 +80,10 @@ func ReadFile(fileName string) (string, error) { filePath := fmt.Sprintf("%s/%s", configDir, fileName) - bytes, err := ioutil.ReadFile(filePath) + fileData, err := ReadFileBytes(filePath) if err != nil { return "", err } - return string(bytes), nil + return string(fileData), nil } diff --git a/wtf/focus_tracker.go b/wtf/focus_tracker.go index 76ac5edf..298eeecd 100644 --- a/wtf/focus_tracker.go +++ b/wtf/focus_tracker.go @@ -40,7 +40,7 @@ func (tracker *FocusTracker) Prev() { func (tracker *FocusTracker) blur(idx int) { view := tracker.Widgets[idx].TextView() view.Blur() - view.SetBorderColor(ColorFor(Config.UString("wtf.border.normal"))) + view.SetBorderColor(ColorFor(Config.UString("wtf.border.normal", "gray"))) } func (tracker *FocusTracker) decrement() { @@ -54,7 +54,7 @@ func (tracker *FocusTracker) decrement() { func (tracker *FocusTracker) focus(idx int) { view := tracker.Widgets[idx].TextView() tracker.App.SetFocus(view) - view.SetBorderColor(ColorFor(Config.UString("wtf.border.focus"))) + view.SetBorderColor(ColorFor(Config.UString("wtf.border.focus", "gray"))) } func (tracker *FocusTracker) increment() { diff --git a/wtf/utils.go b/wtf/utils.go index 7b6cbb57..9508eb6a 100644 --- a/wtf/utils.go +++ b/wtf/utils.go @@ -10,10 +10,6 @@ import ( "github.com/rivo/tview" ) -// DateFormat defines the format we expect to receive dates from BambooHR in -const DateFormat = "2006-01-02" -const TimeFormat = "15:04" - func CenterText(str string, width int) string { return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str)) } @@ -50,14 +46,6 @@ func Exclude(strs []string, val string) bool { return true } -func IsToday(date time.Time) bool { - now := time.Now() - - return (date.Year() == now.Year()) && - (date.Month() == now.Month()) && - (date.Day() == now.Day()) -} - func NameFromEmail(email string) string { parts := strings.Split(email, "@") return strings.Title(strings.Replace(parts[0], ".", " ", -1)) @@ -73,16 +61,7 @@ func NamesFromEmails(emails []string) []string { return names } -func PrettyDate(dateStr string) string { - newTime, _ := time.Parse(DateFormat, dateStr) - return fmt.Sprint(newTime.Format("Jan 2, 2006")) -} - -func Now() time.Time { - return time.Now().Local() -} - -func ReadYamlFile(filePath string) ([]byte, error) { +func ReadFileBytes(filePath string) ([]byte, error) { fileData, err := ioutil.ReadFile(filePath) if err != nil { return []byte{}, err @@ -96,6 +75,8 @@ func RightAlignFormat(view *tview.TextView) string { return fmt.Sprintf("%%%ds", w-1) } +/* -------------------- Slice Conversion -------------------- */ + func ToInts(slice []interface{}) []int { results := []int{} for _, val := range slice { @@ -105,10 +86,6 @@ func ToInts(slice []interface{}) []int { return results } -func Tomorrow() time.Time { - return Now().AddDate(0, 0, 1) -} - func ToStrs(slice []interface{}) []string { results := []string{} for _, val := range slice { @@ -118,6 +95,33 @@ func ToStrs(slice []interface{}) []string { return results } +/* -------------------- Date/Time -------------------- */ + +// DateFormat defines the format we expect to receive dates from BambooHR in +const DateFormat = "2006-01-02" +const TimeFormat = "15:04" + +func IsToday(date time.Time) bool { + now := Now() + + return (date.Year() == now.Year()) && + (date.Month() == now.Month()) && + (date.Day() == now.Day()) +} + +func Now() time.Time { + return time.Now().Local() +} + +func PrettyDate(dateStr string) string { + newTime, _ := time.Parse(DateFormat, dateStr) + return fmt.Sprint(newTime.Format("Jan 2, 2006")) +} + +func Tomorrow() time.Time { + return Now().AddDate(0, 0, 1) +} + func UnixTime(unix int64) time.Time { return time.Unix(unix, 0) }