mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 Partial conversion to new Common settings
This commit is contained in:
parent
f09d08bda2
commit
59f0bc6cfc
@ -28,10 +28,16 @@ type Position struct {
|
||||
Width int
|
||||
}
|
||||
|
||||
type Sigils struct {
|
||||
CheckedIcon string
|
||||
UncheckedIcon string
|
||||
}
|
||||
|
||||
type Common struct {
|
||||
Colors
|
||||
Module
|
||||
Position
|
||||
Sigils
|
||||
|
||||
Enabled bool
|
||||
FocusChar int
|
||||
@ -43,6 +49,7 @@ func NewCommonSettingsFromYAML(name, configKey string, ymlConfig *config.Config)
|
||||
colorsPath := "wtf.colors"
|
||||
modulePath := "wtf.mods." + configKey
|
||||
positionPath := "wtf.mods." + configKey + ".position"
|
||||
sigilsPath := "wtf.sigils"
|
||||
|
||||
common := Common{
|
||||
Colors: Colors{
|
||||
@ -50,7 +57,7 @@ func NewCommonSettingsFromYAML(name, configKey string, ymlConfig *config.Config)
|
||||
BorderFocusable: ymlConfig.UString(colorsPath+".border.focusable", "red"),
|
||||
BorderFocused: ymlConfig.UString(colorsPath+".border.focused", "orange"),
|
||||
BorderNormal: ymlConfig.UString(colorsPath+".border.normal", "gray"),
|
||||
Checked: ymlConfig.UString(colorsPath+".checked", "gray"),
|
||||
Checked: ymlConfig.UString(colorsPath+".checked", "white"),
|
||||
HighlightFore: ymlConfig.UString(colorsPath+".highlight.fore", "black"),
|
||||
HighlightBack: ymlConfig.UString(colorsPath+".highlight.back", "green"),
|
||||
Text: ymlConfig.UString(modulePath+".colors.text", ymlConfig.UString(colorsPath+".text", "white")),
|
||||
@ -69,6 +76,11 @@ func NewCommonSettingsFromYAML(name, configKey string, ymlConfig *config.Config)
|
||||
Width: ymlConfig.UInt(positionPath + ".width"),
|
||||
},
|
||||
|
||||
Sigils: Sigils{
|
||||
CheckedIcon: ymlConfig.UString(sigilsPath+".checkedIcon", "x"),
|
||||
UncheckedIcon: ymlConfig.UString(sigilsPath+".uncheckedIcon", " "),
|
||||
},
|
||||
|
||||
Enabled: ymlConfig.UBool(modulePath+".enabled", false),
|
||||
FocusChar: ymlConfig.UInt(modulePath+".focusChar", -1),
|
||||
RefreshInterval: ymlConfig.UInt(modulePath+".refreshInterval", 300),
|
||||
|
@ -3,14 +3,18 @@ package checklist
|
||||
// Checklist is a module for creating generic checklist implementations
|
||||
// See 'Todo' for an implementation example
|
||||
type Checklist struct {
|
||||
Selected int
|
||||
|
||||
Items []*ChecklistItem
|
||||
|
||||
checkedIcon string
|
||||
selected int
|
||||
uncheckedIcon string
|
||||
}
|
||||
|
||||
func NewChecklist() Checklist {
|
||||
func NewChecklist(checkedIcon, uncheckedIcon string) Checklist {
|
||||
list := Checklist{
|
||||
Selected: -1,
|
||||
checkedIcon: checkedIcon,
|
||||
selected: -1,
|
||||
uncheckedIcon: uncheckedIcon,
|
||||
}
|
||||
|
||||
return list
|
||||
@ -20,12 +24,14 @@ func NewChecklist() Checklist {
|
||||
|
||||
// Add creates a new item in the checklist
|
||||
func (list *Checklist) Add(checked bool, text string) {
|
||||
item := ChecklistItem{
|
||||
Checked: checked,
|
||||
Text: text,
|
||||
}
|
||||
item := NewChecklistItem(
|
||||
checked,
|
||||
text,
|
||||
list.checkedIcon,
|
||||
list.uncheckedIcon,
|
||||
)
|
||||
|
||||
list.Items = append([]*ChecklistItem{&item}, list.Items...)
|
||||
list.Items = append([]*ChecklistItem{item}, list.Items...)
|
||||
}
|
||||
|
||||
// CheckedItems returns a slice of all the checked items
|
||||
@ -43,7 +49,7 @@ func (list *Checklist) CheckedItems() []*ChecklistItem {
|
||||
|
||||
// Delete removes the selected item from the checklist
|
||||
func (list *Checklist) Delete() {
|
||||
list.Items = append(list.Items[:list.Selected], list.Items[list.Selected+1:]...)
|
||||
list.Items = append(list.Items[:list.selected], list.Items[list.selected+1:]...)
|
||||
list.Prev()
|
||||
}
|
||||
|
||||
@ -53,18 +59,18 @@ func (list *Checklist) Demote() {
|
||||
return
|
||||
}
|
||||
|
||||
j := list.Selected + 1
|
||||
j := list.selected + 1
|
||||
if j >= len(list.Items) {
|
||||
j = 0
|
||||
}
|
||||
|
||||
list.Swap(list.Selected, j)
|
||||
list.Selected = j
|
||||
list.Swap(list.selected, j)
|
||||
list.selected = j
|
||||
}
|
||||
|
||||
// IsSelectable returns true if the checklist has selectable items, false if it does not
|
||||
func (list *Checklist) IsSelectable() bool {
|
||||
return list.Selected >= 0 && list.Selected < len(list.Items)
|
||||
return list.selected >= 0 && list.selected < len(list.Items)
|
||||
}
|
||||
|
||||
// IsUnselectable returns true if the checklist has no selectable items, false if it does
|
||||
@ -74,9 +80,9 @@ func (list *Checklist) IsUnselectable() bool {
|
||||
|
||||
// Next selects the next item in the checklist
|
||||
func (list *Checklist) Next() {
|
||||
list.Selected = list.Selected + 1
|
||||
if list.Selected >= len(list.Items) {
|
||||
list.Selected = 0
|
||||
list.selected = list.selected + 1
|
||||
if list.selected >= len(list.Items) {
|
||||
list.selected = 0
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,9 +101,9 @@ func (list *Checklist) LongestLine() int {
|
||||
|
||||
// Prev selects the previous item in the checklist
|
||||
func (list *Checklist) Prev() {
|
||||
list.Selected = list.Selected - 1
|
||||
if list.Selected < 0 {
|
||||
list.Selected = len(list.Items) - 1
|
||||
list.selected = list.selected - 1
|
||||
if list.selected < 0 {
|
||||
list.selected = len(list.Items) - 1
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,13 +113,17 @@ func (list *Checklist) Promote() {
|
||||
return
|
||||
}
|
||||
|
||||
j := list.Selected - 1
|
||||
j := list.selected - 1
|
||||
if j < 0 {
|
||||
j = len(list.Items) - 1
|
||||
}
|
||||
|
||||
list.Swap(list.Selected, j)
|
||||
list.Selected = j
|
||||
list.Swap(list.selected, j)
|
||||
list.selected = j
|
||||
}
|
||||
|
||||
func (list *Checklist) Selected() int {
|
||||
return list.selected
|
||||
}
|
||||
|
||||
// SelectedItem returns the currently-selected checklist item or nil if no item is selected
|
||||
@ -122,13 +132,13 @@ func (list *Checklist) SelectedItem() *ChecklistItem {
|
||||
return nil
|
||||
}
|
||||
|
||||
return list.Items[list.Selected]
|
||||
return list.Items[list.selected]
|
||||
}
|
||||
|
||||
func (list *Checklist) SetSelectedByItem(selectableItem *ChecklistItem) {
|
||||
for idx, item := range list.Items {
|
||||
if item == selectableItem {
|
||||
list.Selected = idx
|
||||
list.selected = idx
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -158,7 +168,7 @@ func (list *Checklist) UncheckedItems() []*ChecklistItem {
|
||||
|
||||
// Unselect removes the current select such that no item is selected
|
||||
func (list *Checklist) Unselect() {
|
||||
list.Selected = -1
|
||||
list.selected = -1
|
||||
}
|
||||
|
||||
// Update sets the text of the currently-selected item to the provided text
|
||||
|
@ -1,23 +1,34 @@
|
||||
package checklist
|
||||
|
||||
import (
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
import ()
|
||||
|
||||
// ChecklistItem is a module for creating generic checklist implementations
|
||||
// See 'Todo' for an implementation example
|
||||
type ChecklistItem struct {
|
||||
Checked bool
|
||||
CheckedIcon string
|
||||
Text string
|
||||
UncheckedIcon string
|
||||
}
|
||||
|
||||
func NewChecklistItem(checked bool, text string, checkedIcon, uncheckedIcon string) *ChecklistItem {
|
||||
item := &ChecklistItem{
|
||||
Checked: checked,
|
||||
CheckedIcon: checkedIcon,
|
||||
Text: text,
|
||||
UncheckedIcon: uncheckedIcon,
|
||||
}
|
||||
|
||||
return item
|
||||
}
|
||||
|
||||
// CheckMark returns the string used to indicate a ChecklistItem is checked or unchecked
|
||||
func (item *ChecklistItem) CheckMark() string {
|
||||
if item.Checked {
|
||||
return wtf.Config.UString("wtf.mods.todo.checkedIcon", "x")
|
||||
return item.CheckedIcon
|
||||
}
|
||||
|
||||
return " "
|
||||
return item.UncheckedIcon
|
||||
}
|
||||
|
||||
// Toggle changes the checked state of the ChecklistItem
|
||||
|
@ -13,7 +13,10 @@ const checkWidth = 4
|
||||
|
||||
func (widget *Widget) display() {
|
||||
str := ""
|
||||
newList := checklist.NewChecklist()
|
||||
newList := checklist.NewChecklist(
|
||||
widget.settings.common.Sigils.CheckedIcon,
|
||||
widget.settings.common.Sigils.UncheckedIcon,
|
||||
)
|
||||
|
||||
offset := 0
|
||||
|
||||
@ -33,19 +36,19 @@ func (widget *Widget) display() {
|
||||
|
||||
widget.View.Clear()
|
||||
widget.View.SetText(str)
|
||||
widget.View.Highlight(strconv.Itoa(widget.list.Selected)).ScrollToHighlight()
|
||||
widget.View.Highlight(strconv.Itoa(widget.list.Selected())).ScrollToHighlight()
|
||||
}
|
||||
|
||||
func (widget *Widget) formattedItemLine(idx int, item *checklist.ChecklistItem, selectedItem *checklist.ChecklistItem, maxLen int) string {
|
||||
foreColor, backColor := "white", wtf.Config.UString("wtf.colors.background", "black")
|
||||
foreColor, backColor := widget.settings.common.Colors.Text, widget.settings.common.Colors.Background
|
||||
|
||||
if item.Checked {
|
||||
foreColor = wtf.Config.UString("wtf.colors.checked", "white")
|
||||
foreColor = widget.settings.common.Colors.Checked
|
||||
}
|
||||
|
||||
if widget.View.HasFocus() && (item == selectedItem) {
|
||||
foreColor = wtf.Config.UString("wtf.colors.highlight.fore", "black")
|
||||
backColor = wtf.Config.UString("wtf.colors.highlight.back", "orange")
|
||||
foreColor = widget.settings.common.Colors.HighlightFore
|
||||
backColor = widget.settings.common.Colors.HighlightBack
|
||||
}
|
||||
|
||||
str := fmt.Sprintf(
|
||||
|
@ -54,7 +54,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
app: app,
|
||||
settings: settings,
|
||||
filePath: settings.filePath,
|
||||
list: checklist.NewChecklist(),
|
||||
list: checklist.NewChecklist(settings.common.Sigils.CheckedIcon, settings.common.Sigils.UncheckedIcon),
|
||||
pages: pages,
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,11 @@ func (widget *Widget) display() {
|
||||
maxLen := proj.LongestLine()
|
||||
|
||||
for index, item := range proj.tasks {
|
||||
foreColor, backColor := "white", wtf.Config.UString("wtf.colors.background", "black")
|
||||
foreColor, backColor := widget.settings.common.Colors.Text, widget.settings.common.Colors.Background
|
||||
|
||||
if index == proj.index {
|
||||
foreColor = wtf.Config.UString("wtf.colors.highlight.fore", "black")
|
||||
backColor = wtf.Config.UString("wtf.colors.highlight.back", "orange")
|
||||
foreColor = widget.settings.common.Colors.HighlightFore
|
||||
backColor = widget.settings.common.Colors.HighlightBack
|
||||
}
|
||||
|
||||
row := fmt.Sprintf(
|
||||
|
@ -63,13 +63,13 @@ func (widget *Widget) textContent(items []Ticket) string {
|
||||
}
|
||||
|
||||
func (widget *Widget) format(ticket Ticket, idx int) string {
|
||||
var str string
|
||||
requesterName := widget.parseRequester(ticket)
|
||||
textColor := wtf.Config.UString("wtf.colors.background", "green")
|
||||
textColor := widget.settings.common.Colors.Background
|
||||
if idx == widget.selected {
|
||||
textColor = wtf.Config.UString("wtf.colors.background", "orange")
|
||||
textColor = widget.settings.common.Colors.BorderFocused
|
||||
}
|
||||
str = fmt.Sprintf(" [%s:]%d - %s\n %s\n\n", textColor, ticket.Id, requesterName, ticket.Subject)
|
||||
|
||||
requesterName := widget.parseRequester(ticket)
|
||||
str := fmt.Sprintf(" [%s:]%d - %s\n %s\n\n", textColor, ticket.Id, requesterName, ticket.Subject)
|
||||
return str
|
||||
}
|
||||
|
||||
|
@ -115,6 +115,10 @@ func (widget *TextWidget) SetFocusChar(char string) {
|
||||
widget.focusChar = char
|
||||
}
|
||||
|
||||
func (widget *TextWidget) String() string {
|
||||
return widget.name
|
||||
}
|
||||
|
||||
func (widget *TextWidget) TextView() *tview.TextView {
|
||||
return widget.View
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user