mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Cleanup of stray files. Don't need so many single-use packages
This commit is contained in:
parent
5e186323e0
commit
12ef3919dc
32
clocks/display.go
Normal file
32
clocks/display.go
Normal file
@ -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"))
|
||||
}
|
@ -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)
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package color
|
||||
package wtf
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
@ -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 {
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user