1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

A lot of code cleanup for Clocks and Git

This commit is contained in:
Chris Cummer
2018-04-18 16:45:50 -07:00
parent 1c72c71e81
commit 5e186323e0
7 changed files with 121 additions and 88 deletions

View File

@@ -4,6 +4,8 @@ import (
"fmt"
"strings"
"unicode/utf8"
"github.com/senorprogrammer/wtf/wtf"
)
func (widget *Widget) display() {
@@ -83,3 +85,16 @@ func (widget *Widget) formatCommits(data []string) string {
func (widget *Widget) formatCommit(line string) string {
return fmt.Sprintf(" %s\n", strings.Replace(line, "\"", "", -1))
}
func (widget *Widget) tickMarks(data []*GitRepo) string {
str := ""
if len(data) > 1 {
marks := strings.Repeat("*", len(data))
marks = marks[:widget.Idx] + "_" + marks[widget.Idx+1:]
str = "[lightblue]" + fmt.Sprintf(wtf.RightAlignFormat(widget.View), marks) + "[white]"
}
return str
}

View File

@@ -1,8 +1,6 @@
package git
import (
"fmt"
"strings"
"time"
"github.com/gdamore/tcell"
@@ -33,24 +31,13 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Fetch(repoPaths []string) []*GitRepo {
data := []*GitRepo{}
for _, repoPath := range repoPaths {
repo := NewGitRepo(repoPath)
data = append(data, repo)
}
return data
}
func (widget *Widget) Refresh() {
if widget.Disabled() {
return
}
repoPaths := wtf.ToStrs(Config.UList("wtf.mods.git.repositories"))
widget.Data = widget.Fetch(repoPaths)
widget.Data = widget.gitRepos(repoPaths)
widget.display()
widget.RefreshedAt = time.Now()
@@ -88,6 +75,17 @@ func (widget *Widget) currentData() *GitRepo {
return widget.Data[widget.Idx]
}
func (widget *Widget) gitRepos(repoPaths []string) []*GitRepo {
repos := []*GitRepo{}
for _, repoPath := range repoPaths {
repo := NewGitRepo(repoPath)
repos = append(repos, repo)
}
return repos
}
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
switch event.Key() {
case tcell.KeyLeft:
@@ -102,16 +100,3 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
return event
}
func (widget *Widget) tickMarks(data []*GitRepo) string {
str := ""
if len(data) > 1 {
marks := strings.Repeat("*", len(data))
marks = marks[:widget.Idx] + "_" + marks[widget.Idx+1:]
str = "[lightblue]" + fmt.Sprintf(wtf.RightAlignFormat(widget.View), marks) + "[white]"
}
return str
}