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