1
0
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:
Chris Cummer
2018-04-18 17:51:43 -07:00
parent 5e186323e0
commit 12ef3919dc
9 changed files with 46 additions and 59 deletions

155
wtf/colors.go Normal file
View File

@@ -0,0 +1,155 @@
package wtf
import (
"github.com/gdamore/tcell"
)
var Colors = map[string]tcell.Color{
"black": tcell.ColorBlack,
"maroon": tcell.ColorMaroon,
"green": tcell.ColorGreen,
"olive": tcell.ColorOlive,
"navy": tcell.ColorNavy,
"purple": tcell.ColorPurple,
"teal": tcell.ColorTeal,
"silver": tcell.ColorSilver,
"gray": tcell.ColorGray,
"red": tcell.ColorRed,
"lime": tcell.ColorLime,
"yellow": tcell.ColorYellow,
"blue": tcell.ColorBlue,
"fuchsia": tcell.ColorFuchsia,
"aqua": tcell.ColorAqua,
"white": tcell.ColorWhite,
"aliceblue": tcell.ColorAliceBlue,
"antiquewhite": tcell.ColorAntiqueWhite,
"aquamarine": tcell.ColorAquaMarine,
"azure": tcell.ColorAzure,
"beige": tcell.ColorBeige,
"bisque": tcell.ColorBisque,
"blanchedalmond": tcell.ColorBlanchedAlmond,
"blueviolet": tcell.ColorBlueViolet,
"brown": tcell.ColorBrown,
"burlywood": tcell.ColorBurlyWood,
"cadetblue": tcell.ColorCadetBlue,
"chartreuse": tcell.ColorChartreuse,
"chocolate": tcell.ColorChocolate,
"coral": tcell.ColorCoral,
"cornflowerblue": tcell.ColorCornflowerBlue,
"cornsilk": tcell.ColorCornsilk,
"crimson": tcell.ColorCrimson,
"darkblue": tcell.ColorDarkBlue,
"darkcyan": tcell.ColorDarkCyan,
"darkgoldenrod": tcell.ColorDarkGoldenrod,
"darkgray": tcell.ColorDarkGray,
"darkgreen": tcell.ColorDarkGreen,
"darkkhaki": tcell.ColorDarkKhaki,
"darkmagenta": tcell.ColorDarkMagenta,
"darkolivegreen": tcell.ColorDarkOliveGreen,
"darkorange": tcell.ColorDarkOrange,
"darkorchid": tcell.ColorDarkOrchid,
"darkred": tcell.ColorDarkRed,
"darksalmon": tcell.ColorDarkSalmon,
"darkseagreen": tcell.ColorDarkSeaGreen,
"darkslateblue": tcell.ColorDarkSlateBlue,
"darkslategray": tcell.ColorDarkSlateGray,
"darkturquoise": tcell.ColorDarkTurquoise,
"darkviolet": tcell.ColorDarkViolet,
"deeppink": tcell.ColorDeepPink,
"deepskyblue": tcell.ColorDeepSkyBlue,
"dimgray": tcell.ColorDimGray,
"dodgerblue": tcell.ColorDodgerBlue,
"firebrick": tcell.ColorFireBrick,
"floralwhite": tcell.ColorFloralWhite,
"forestgreen": tcell.ColorForestGreen,
"gainsboro": tcell.ColorGainsboro,
"ghostwhite": tcell.ColorGhostWhite,
"gold": tcell.ColorGold,
"goldenrod": tcell.ColorGoldenrod,
"greenyellow": tcell.ColorGreenYellow,
"honeydew": tcell.ColorHoneydew,
"hotpink": tcell.ColorHotPink,
"indianred": tcell.ColorIndianRed,
"indigo": tcell.ColorIndigo,
"ivory": tcell.ColorIvory,
"khaki": tcell.ColorKhaki,
"lavender": tcell.ColorLavender,
"lavenderblush": tcell.ColorLavenderBlush,
"lawngreen": tcell.ColorLawnGreen,
"lemonchiffon": tcell.ColorLemonChiffon,
"lightblue": tcell.ColorLightBlue,
"lightcoral": tcell.ColorLightCoral,
"lightcyan": tcell.ColorLightCyan,
"lightgoldenrodyellow": tcell.ColorLightGoldenrodYellow,
"lightgray": tcell.ColorLightGray,
"lightgreen": tcell.ColorLightGreen,
"lightpink": tcell.ColorLightPink,
"lightsalmon": tcell.ColorLightSalmon,
"lightseagreen": tcell.ColorLightSeaGreen,
"lightskyblue": tcell.ColorLightSkyBlue,
"lightslategray": tcell.ColorLightSlateGray,
"lightsteelblue": tcell.ColorLightSteelBlue,
"lightyellow": tcell.ColorLightYellow,
"limegreen": tcell.ColorLimeGreen,
"linen": tcell.ColorLinen,
"mediumaquamarine": tcell.ColorMediumAquamarine,
"mediumblue": tcell.ColorMediumBlue,
"mediumorchid": tcell.ColorMediumOrchid,
"mediumpurple": tcell.ColorMediumPurple,
"mediumseagreen": tcell.ColorMediumSeaGreen,
"mediumslateblue": tcell.ColorMediumSlateBlue,
"mediumspringgreen": tcell.ColorMediumSpringGreen,
"mediumturquoise": tcell.ColorMediumTurquoise,
"mediumvioletred": tcell.ColorMediumVioletRed,
"midnightblue": tcell.ColorMidnightBlue,
"mintcream": tcell.ColorMintCream,
"mistyrose": tcell.ColorMistyRose,
"moccasin": tcell.ColorMoccasin,
"navajowhite": tcell.ColorNavajoWhite,
"oldlace": tcell.ColorOldLace,
"olivedrab": tcell.ColorOliveDrab,
"orange": tcell.ColorOrange,
"orangered": tcell.ColorOrangeRed,
"orchid": tcell.ColorOrchid,
"palegoldenrod": tcell.ColorPaleGoldenrod,
"palegreen": tcell.ColorPaleGreen,
"paleturquoise": tcell.ColorPaleTurquoise,
"palevioletred": tcell.ColorPaleVioletRed,
"papayawhip": tcell.ColorPapayaWhip,
"peachpuff": tcell.ColorPeachPuff,
"peru": tcell.ColorPeru,
"pink": tcell.ColorPink,
"plum": tcell.ColorPlum,
"powderblue": tcell.ColorPowderBlue,
"rebeccapurple": tcell.ColorRebeccaPurple,
"rosybrown": tcell.ColorRosyBrown,
"royalblue": tcell.ColorRoyalBlue,
"saddlebrown": tcell.ColorSaddleBrown,
"salmon": tcell.ColorSalmon,
"sandybrown": tcell.ColorSandyBrown,
"seagreen": tcell.ColorSeaGreen,
"seashell": tcell.ColorSeashell,
"sienna": tcell.ColorSienna,
"skyblue": tcell.ColorSkyblue,
"slateblue": tcell.ColorSlateBlue,
"slategray": tcell.ColorSlateGray,
"snow": tcell.ColorSnow,
"springgreen": tcell.ColorSpringGreen,
"steelblue": tcell.ColorSteelBlue,
"tan": tcell.ColorTan,
"thistle": tcell.ColorThistle,
"tomato": tcell.ColorTomato,
"turquoise": tcell.ColorTurquoise,
"violet": tcell.ColorViolet,
"wheat": tcell.ColorWheat,
"whitesmoke": tcell.ColorWhiteSmoke,
"yellowgreen": tcell.ColorYellowGreen,
}
func ColorFor(label string) tcell.Color {
if _, ok := Colors[label]; ok {
return Colors[label]
} else {
return tcell.ColorBlue
}
}

View File

@@ -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 {

View File

@@ -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() {

49
wtf/homedir.go Normal file
View File

@@ -0,0 +1,49 @@
// Package homedir helps with detecting and expanding the user's home directory
// Copied (mostly) verbatim from https://github.com/Atrox/homedir
package wtf
import (
"errors"
"os/user"
"path/filepath"
)
// Dir returns the home directory for the executing user.
// An error is returned if a home directory cannot be detected.
func Home() (string, error) {
currentUser, err := user.Current()
if err != nil {
return "", err
}
if currentUser.HomeDir == "" {
return "", errors.New("cannot find user-specific home dir")
}
return currentUser.HomeDir, nil
}
// 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 ExpandHomeDir(path string) (string, error) {
if len(path) == 0 {
return path, nil
}
if path[0] != '~' {
return path, nil
}
if len(path) > 1 && path[1] != '/' && path[1] != '\\' {
return "", errors.New("cannot expand user-specific home dir")
}
dir, err := Home()
if err != nil {
return "", err
}
return filepath.Join(dir, path[1:]), nil
}

View File

@@ -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
}