mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Minor code cleanup
This commit is contained in:
parent
fb69547fc8
commit
9bd2430063
19
_sample_configs/uniconfig.yml
Normal file
19
_sample_configs/uniconfig.yml
Normal file
@ -0,0 +1,19 @@
|
||||
wtf:
|
||||
grid:
|
||||
columns: [40]
|
||||
rows: [16]
|
||||
refreshInterval: 1
|
||||
mods:
|
||||
textfile:
|
||||
enabled: true
|
||||
filePaths:
|
||||
- "~/.config/wtf/config.yml"
|
||||
- "~/.config/wtf/log.txt"
|
||||
format: true
|
||||
formatStyle: "vim"
|
||||
position:
|
||||
top: 1
|
||||
left: 1
|
||||
height: 2
|
||||
width: 1
|
||||
refreshInterval: 15
|
2
main.go
2
main.go
@ -299,7 +299,7 @@ func main() {
|
||||
app.SetInputCapture(keyboardIntercept)
|
||||
|
||||
// Loop in a routine to redraw the screen
|
||||
go redrawApp(app)
|
||||
//go redrawApp(app)
|
||||
go watchForConfigChanges(app, flags.Config, display.Grid, pages)
|
||||
|
||||
if err := app.SetRoot(pages, true).Run(); err != nil {
|
||||
|
@ -54,6 +54,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetWordWrap(true)
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
widget.View.SetChangedFunc(func() {
|
||||
app.Draw()
|
||||
})
|
||||
|
||||
go widget.watchForFileChanges()
|
||||
|
||||
@ -72,7 +75,7 @@ func (widget *Widget) Refresh() {
|
||||
|
||||
func (widget *Widget) display() {
|
||||
title := fmt.Sprintf("[green]%s[white]", widget.CurrentSource())
|
||||
widget.View.SetTitle(widget.ContextualTitle(title))
|
||||
title = widget.ContextualTitle(title)
|
||||
|
||||
text := wtf.SigilStr(len(widget.Sources), widget.Idx, widget.View) + "\n"
|
||||
|
||||
@ -82,6 +85,7 @@ func (widget *Widget) display() {
|
||||
text = text + widget.plainText()
|
||||
}
|
||||
|
||||
widget.View.SetTitle(title)
|
||||
widget.View.SetText(text)
|
||||
}
|
||||
|
||||
|
33
wtf/utils.go
33
wtf/utils.go
@ -6,6 +6,7 @@ import (
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
//"sync"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
@ -26,6 +27,20 @@ func CenterText(str string, width int) string {
|
||||
return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str))
|
||||
}
|
||||
|
||||
func DefaultFocussedRowColor() string {
|
||||
foreColor := Config.UString("wtf.colors.highlight.fore", "black")
|
||||
backColor := Config.UString("wtf.colors.highlight.back", "orange")
|
||||
|
||||
return fmt.Sprintf("%s:%s", foreColor, backColor)
|
||||
}
|
||||
|
||||
func DefaultRowColor() string {
|
||||
foreColor := Config.UString("wtf.colors.foreground", "white")
|
||||
backColor := Config.UString("wtf.colors.background", "black")
|
||||
|
||||
return fmt.Sprintf("%s:%s", foreColor, backColor)
|
||||
}
|
||||
|
||||
func ExecuteCommand(cmd *exec.Cmd) string {
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
@ -109,24 +124,14 @@ func ReadFileBytes(filePath string) ([]byte, error) {
|
||||
}
|
||||
|
||||
func RightAlignFormat(view *tview.TextView) string {
|
||||
//mutex := &sync.Mutex{}
|
||||
//mutex.Lock()
|
||||
_, _, w, _ := view.GetInnerRect()
|
||||
//mutex.Unlock()
|
||||
|
||||
return fmt.Sprintf("%%%ds", w-1)
|
||||
}
|
||||
|
||||
func DefaultRowColor() string {
|
||||
foreColor := Config.UString("wtf.colors.foreground", "white")
|
||||
backColor := Config.UString("wtf.colors.background", "black")
|
||||
|
||||
return fmt.Sprintf("%s:%s", foreColor, backColor)
|
||||
}
|
||||
|
||||
func DefaultFocussedRowColor() string {
|
||||
foreColor := Config.UString("wtf.colors.highlight.fore", "black")
|
||||
backColor := Config.UString("wtf.colors.highlight.back", "orange")
|
||||
|
||||
return fmt.Sprintf("%s:%s", foreColor, backColor)
|
||||
}
|
||||
|
||||
func RowColor(module string, idx int) string {
|
||||
evenKey := fmt.Sprintf("wtf.mods.%s.colors.rows.even", module)
|
||||
oddKey := fmt.Sprintf("wtf.mods.%s.colors.rows.odd", module)
|
||||
|
Loading…
x
Reference in New Issue
Block a user