Skip to content

Commit

Permalink
Rearange UI elements disposition
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielseibel1 committed Jun 24, 2024
1 parent 21de917 commit 8fd9bc8
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 82 deletions.
5 changes: 4 additions & 1 deletion .godo/godo.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{"UI actions to match cmds":{"id":"UI actions to match cmds","description":"do, undo, work, tag, create etc","duration":1800000000000,"done":false,"tags":{"UI":{}}},"UI tags":{"id":"UI tags","description":"filter the items by tags in the UI, listing the tags for selection","duration":0,"done":true,"tags":{"TAGS":{},"UI":{}}},"dep inv on tabs":{"id":"dep inv on tabs","description":"apply dependency inversion in tabs.go","duration":0,"done":false,"tags":{"OTHER":{},"REFACTOR":{}}},"list tags":{"id":"list tags","description":"command like 'godo list tag1 tag2 tag3' that lists items in tags","duration":1800000000000,"done":true,"tags":{"TAGS":{}}},"ordering":{"id":"ordering","description":"sort by custom order","duration":3600000000000,"done":false,"tags":{"OTHER":{}}},"tags":{"id":"tags","description":"command like 'godo tags' that lists the existing tags","duration":0,"done":true,"tags":{"TAGS":{}}},"untag":{"id":"untag","description":"command like tag but deletes the tag from items","duration":5400000000000,"done":true,"tags":{"TAGS":{}}},"version":{"id":"version","description":"version command that prints version","duration":0,"done":true,"tags":{"OTHER":{}}}}
{"UI actions to match cmd":{"id":"UI actions to match cmd","description":"do, undo, work","duration":1800000000000,"done":false,"tags":{"UI":{}}},"UI tags":{"id":"UI tags","description":"filter the items by tags in the UI, listing the tags for selection","duration":0,"done":true,"tags":{"TAGS":{},"UI":{}}},"dep inv on tabs":{"id":"dep inv on tabs","description":"apply dependency inversion in tabs.go","duration":0,"done":false,"tags":{"OTHER":{},"REFACTOR":{}}},"list tags":{"id":"list tags","description":"command like 'godo list tag1 tag2 tag3' that lists items in tags","duration":1800000000000,"done":true,"tags":{"TAGS":{}}},"ordering":{"id":"ordering","description":"sort by custom order","duration":3600000000000,"done":false,"tags":{"OTHER":{}}},"tag":{"id":"tag","description":"command like 'godo tags' that lists the existing tags","duration":0,"done":true,"tags":{"TAGS":{}}},"untag":{"id":"untag","description":"command like tag but deletes the tag from items","duration":5400000000000,"done":true,"tags":{"TAGS":{}}},"version":{"id":"version","description":"version command that prints version","duration":0,"done":true,"tags":{"OTHER":{}}}}
}
":{"OTHER":{}}}}
}
ersion","description":"version command that prints version","duration":0,"done":true,"tags":{"OTHER":{}}}}
ration":5400000000000,"done":true,"tags":{"TAGS":{}}},"version":{"id":"version","description":"version command that prints version","duration":0,"done":true,"tags":{"OTHER":{}}}}
2 changes: 0 additions & 2 deletions commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (

const InitCommandName CommandName = "init"

type Initializer func() error

type Init struct {
initializers []Initializer
}
Expand Down
3 changes: 0 additions & 3 deletions commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import (
"fmt"

"github.com/gabrielseibel1/godo/data"
"github.com/gabrielseibel1/godo/types"
)

type Displayer func(types.Actionable)

const ListCommandName CommandName = "list"

type List struct {
Expand Down
17 changes: 11 additions & 6 deletions commands/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ import (

type Parser func([]string) (Command, error)

type Deps struct {
Repo data.Repository
Displayer Displayer
Initializers []Initializer
}
type (
Initializer func() error
Displayer func(types.Actionable)
Deps struct {
Repo data.Repository
Displayer Displayer
Initializers []Initializer
Version string
}
)

func NewParser(deps Deps) Parser {
return func(tokens []string) (Command, error) {
Expand Down Expand Up @@ -51,7 +56,7 @@ func NewParser(deps Deps) Parser {
case string(UntagCommandName):
cmd = &Untag{repo: deps.Repo}
case string(VersionCommandName):
cmd = &Version{}
cmd = &Version{version: deps.Version}
case string(HelpCommandName):
cmd = &Help{}
default:
Expand Down
8 changes: 4 additions & 4 deletions commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import "fmt"

const VersionCommandName CommandName = "version"

const version = "v0.3.0"

type Version struct{}
type Version struct {
version string
}

func (v *Version) Parameterize(args []string) error {
if len(args) > 0 {
Expand All @@ -16,7 +16,7 @@ func (v *Version) Parameterize(args []string) error {
}

func (v *Version) Execute() error {
fmt.Println(version)
fmt.Println(v.version)
return nil
}

Expand Down
5 changes: 5 additions & 0 deletions logic/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package logic

func Version() string {
return "v0.4.0"
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func runCommand(repo data.Repository, path string) {
Repo: repo,
Displayer: presentation.PrintItem,
Initializers: []commands.Initializer{data.DotGodoDirCreater(filepath.Base("")), data.FileCreater(path)},
Version: logic.Version(),
})
command, err := parse(os.Args)
if err != nil {
Expand All @@ -70,6 +71,7 @@ func showUI(repo data.Repository) {
}
mt := presentation.NewTabbedListModel(
dir,
logic.Version(),
presentation.NewListModel(lipgloss.NewStyle()),
presentation.NewEditorModel(),
logic.DoFrom(repo),
Expand Down
19 changes: 8 additions & 11 deletions presentation/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ func NewEditorModel() *EditorModel {
title := textarea.New()
title.SetHeight(1)
title.ShowLineNumbers = false
description := textarea.New()
description.ShowLineNumbers = false
return &EditorModel{
title: title,
description: textarea.New(),
description: description,
err: nil,
}
}
Expand Down Expand Up @@ -64,6 +66,7 @@ func (m *EditorModel) updateEditingTitle(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.title.Focused() {
m.title.Blur()
}
m.state = editorModelStateNothing
return m, nil
}
case errMsg:
Expand All @@ -83,6 +86,7 @@ func (m *EditorModel) updatEditingDescription(msg tea.Msg) (tea.Model, tea.Cmd)
if m.description.Focused() {
m.description.Blur()
}
m.state = editorModelStateNothing
return m, nil
}
case errMsg:
Expand All @@ -97,16 +101,9 @@ func (m *EditorModel) updatEditingDescription(msg tea.Msg) (tea.Model, tea.Cmd)
// View renders the program's UI, which is just a string. The view is
// rendered after every Update.
func (m *EditorModel) View() string {
if m.state == editorModelStateDescription {
m.description.ShowLineNumbers = true
}
return lipgloss.NewStyle().Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color("9")).Padding(1, 2).Render(
fmt.Sprintf(
"%s\n\n%s\n\n%s",
m.title.View(),
m.description.View(),
`("e" to start editing, Ctrl+S to save, Esc to cancel editing)`,
))
return lipgloss.NewStyle().Border(lipgloss.NormalBorder(), true, false, false).Padding(1, 2).Render(
fmt.Sprintf("\n%s\n\n%s\n\n%s", m.title.View(), m.description.View(), `("r" to rename, "e" to edit, Ctrl+S to save, Esc to cancel)`),
)
}

func (m *EditorModel) Description() string {
Expand Down
66 changes: 33 additions & 33 deletions presentation/items.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package presentation

import (
"fmt"
"slices"
"strings"
"time"

Expand All @@ -11,54 +12,27 @@ import (
"github.com/gabrielseibel1/godo/types"
)

type UIItem struct {
types.Actionable
}

func (i UIItem) Title() string {
return string(i.Identity())
}

func (i UIItem) Description() string {
return fmt.Sprintf("%s %s",
checkbox(i.Done(), i.Worked()),
lipgloss.NewStyle().Bold(true).SetString(i.Actionable.Description()),
)
func PrintItem(a types.Actionable) {
fmt.Println(CommandItem{Actionable: a}.String())
}

func (i UIItem) FilterValue() string { return i.Title() }

type CommandItem struct {
types.Actionable
style lipgloss.Style
}

func (c CommandItem) String() string {
return fmt.Sprintf("%s %s -(%s)-> %s ~ %s",
checkbox(c.Done(), c.Worked()),
title(c.Identity(), c.Done(), c.Worked()),
c.title(c.Identity(), c.Done(), c.Worked()),
c.Worked(),
c.Description(),
tags(c.Tags()),
)
}

func PrintItem(a types.Actionable) {
fmt.Println(CommandItem{Actionable: a}.String())
}

func checkbox(done bool, worked time.Duration) string {
if done {
return "✅"
}
if worked > 0 {
return "📶"
} else {
return "🆕"
}
}

func title(id types.ID, done bool, worked time.Duration) string {
style := lipgloss.NewStyle().SetString(fmt.Sprintf("\"%s\"", string(id))).Bold(true)
func (c CommandItem) title(id types.ID, done bool, worked time.Duration) string {
style := c.style.SetString(fmt.Sprintf("\"%s\"", string(id))).Bold(true)
if done {
return style.Foreground(lipgloss.Color("10")).String() // green
}
Expand All @@ -76,7 +50,33 @@ func tags(t map[types.ID]struct{}) string {
return fmt.Sprintf("[%s]", types.IDToString(id))
},
)
slices.Sort(tagsSlice)
return strings.Join(tagsSlice, ",")
}
return ""
}

func checkbox(done bool, worked time.Duration) string {
if done {
return "✅"
}
if worked > 0 {
return "📶"
}
return "🆕"
}

type UIItem struct {
types.Actionable
style lipgloss.Style
}

func (i UIItem) Title() string {
return i.style.Render(fmt.Sprintf("%s %s (%s)",
checkbox(i.Done(), i.Worked()),
fmt.Sprintf("\"%s\"", string(i.Identity())),
i.Worked(),
))
}

func (i UIItem) FilterValue() string { return i.Title() }
7 changes: 3 additions & 4 deletions presentation/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ type ListModel struct {

func NewListModel(style lipgloss.Style) ListModel {
d := list.NewDefaultDelegate()
d.ShowDescription = false
d.SetSpacing(0)
d.Styles.SelectedTitle.Foreground(lipgloss.Color("9"))
d.Styles.SelectedDesc.Foreground(lipgloss.Color("9"))
d.Styles.SelectedTitle.BorderForeground(lipgloss.Color("9"))
d.Styles.SelectedDesc.BorderForeground(lipgloss.Color("9"))
m := ListModel{
list: list.New(make([]list.Item, 0), d, 0, 0),
style: style,
}
m.list.SetShowTitle(false)
m.list.SetShowHelp(false)
return m
}

Expand All @@ -51,7 +50,7 @@ func (m ListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
slices.SortFunc(msg, func(a, b types.Actionable) int {
return strings.Compare(string(a.Identity()), string(b.Identity()))
})
items := apply.ToSlice(msg, func(a types.Actionable) list.Item { return UIItem{a} })
items := apply.ToSlice(msg, func(a types.Actionable) list.Item { return UIItem{Actionable: a, style: m.style} })
return m, m.list.SetItems(items)
}

Expand Down
31 changes: 13 additions & 18 deletions presentation/tabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type TabbedListModel struct {

func NewTabbedListModel(
path string,
version string,
list selectableListModel,
editor editableTextModel,
do doer,
Expand All @@ -75,7 +76,7 @@ func NewTabbedListModel(
edit editor,
) *TabbedListModel {
return &TabbedListModel{
title: lipgloss.NewStyle().Padding(1, 1).SetString(fmt.Sprintf("%s\n%s", banner, path)),
title: lipgloss.NewStyle().Padding(1, 1).SetString(fmt.Sprintf("GoDo (%s) your todo list at...\n%s", version, path)),
listModel: list,
editorModel: editor,
activeTab: 0,
Expand Down Expand Up @@ -109,9 +110,11 @@ func (m *TabbedListModel) updateEditingTitle(msg tea.Msg) (tea.Model, tea.Cmd) {
panic(err)
}
m.editorModel.Blur()
m.editorModel.Clear()
m.state = tabbedListModelStateBrowsing
}
case tea.KeyEsc.String():
m.editorModel.Blur()
m.state = tabbedListModelStateBrowsing
}
}

Expand All @@ -130,9 +133,11 @@ func (m *TabbedListModel) updateEditingDescription(msg tea.Msg) (tea.Model, tea.
panic(err)
}
m.editorModel.Blur()
m.editorModel.Clear()
m.state = tabbedListModelStateBrowsing
}
case tea.KeyEsc.String():
m.editorModel.Blur()
m.state = tabbedListModelStateBrowsing
}
}
editor, cmd := m.editorModel.Update(msg)
Expand Down Expand Up @@ -250,27 +255,17 @@ func (m *TabbedListModel) View() string {
}
}

// TODO turn tabs into paged list
return lipgloss.JoinVertical(
lipgloss.Left,
m.title.String(),
lipgloss.JoinHorizontal(lipgloss.Top, lipgloss.JoinVertical(lipgloss.Left, renderedTabs...), m.listModel.View()),
lipgloss.JoinVertical(lipgloss.Left, lipgloss.JoinHorizontal(lipgloss.Top, renderedTabs...), m.listModel.View()),
m.editorModel.View(),
)
}

var (
inactiveTabBorder = lipgloss.HiddenBorder()
activeTabBorder = lipgloss.RoundedBorder()
highlightColor = lipgloss.AdaptiveColor{Light: "#874BFD", Dark: "#7D56F4"}
inactiveTabStyle = lipgloss.NewStyle().Border(inactiveTabBorder).BorderForeground(highlightColor).Padding(0, 1)
activeTabStyle = inactiveTabStyle.Copy().Border(activeTabBorder).BorderForeground(lipgloss.Color("9"))
)

const (
banner = `
_____ ___
/ ___/__ / _ \___
/ (_ / _ \/ // / _ \
\___/\___/____/\___/ your to-do list at...
`
highlightColor = lipgloss.AdaptiveColor{Light: "#874BFD", Dark: "#7D56F4"}

Check failure on line 268 in presentation/tabs.go

View workflow job for this annotation

GitHub Actions / tests

var highlightColor is unused (U1000)
inactiveTabStyle = lipgloss.NewStyle().PaddingRight(4).PaddingLeft(4)
activeTabStyle = inactiveTabStyle.Copy().Underline(true)
)

0 comments on commit 8fd9bc8

Please sign in to comment.