[WIP] Layout
This commit is contained in:
@ -4,24 +4,47 @@ import (
|
||||
"context"
|
||||
|
||||
"tasksquire/taskwarrior"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type Common struct {
|
||||
Ctx context.Context
|
||||
PageStack *Stack[tea.Model]
|
||||
TW taskwarrior.TaskWarrior
|
||||
Keymap *Keymap
|
||||
Styles *Styles
|
||||
Ctx context.Context
|
||||
TW taskwarrior.TaskWarrior
|
||||
Keymap *Keymap
|
||||
Styles *Styles
|
||||
|
||||
pageStack *Stack[Component]
|
||||
width int
|
||||
height int
|
||||
}
|
||||
|
||||
func NewCommon(ctx context.Context, tw taskwarrior.TaskWarrior) *Common {
|
||||
return &Common{
|
||||
Ctx: ctx,
|
||||
PageStack: NewStack[tea.Model](),
|
||||
TW: tw,
|
||||
Keymap: NewKeymap(),
|
||||
Styles: NewStyles(tw.GetConfig()),
|
||||
Ctx: ctx,
|
||||
TW: tw,
|
||||
Keymap: NewKeymap(),
|
||||
Styles: NewStyles(tw.GetConfig()),
|
||||
|
||||
pageStack: NewStack[Component](),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Common) SetSize(width, height int) {
|
||||
c.width = width
|
||||
c.height = height
|
||||
}
|
||||
|
||||
func (c *Common) Width() int {
|
||||
return c.width
|
||||
}
|
||||
|
||||
func (c *Common) Height() int {
|
||||
return c.height
|
||||
}
|
||||
|
||||
func (c *Common) PushPage(page Component) {
|
||||
c.pageStack.Push(page)
|
||||
}
|
||||
|
||||
func (c *Common) PopPage() (Component, error) {
|
||||
return c.pageStack.Pop()
|
||||
}
|
||||
|
||||
9
common/component.go
Normal file
9
common/component.go
Normal file
@ -0,0 +1,9 @@
|
||||
package common
|
||||
|
||||
import tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
type Component interface {
|
||||
tea.Model
|
||||
//help.KeyMap
|
||||
SetSize(width int, height int)
|
||||
}
|
||||
@ -8,12 +8,19 @@ import (
|
||||
type Keymap struct {
|
||||
Quit key.Binding
|
||||
Back key.Binding
|
||||
Ok key.Binding
|
||||
Input key.Binding
|
||||
Add key.Binding
|
||||
Edit key.Binding
|
||||
Up key.Binding
|
||||
Down key.Binding
|
||||
Left key.Binding
|
||||
Right key.Binding
|
||||
SetReport key.Binding
|
||||
SetContext key.Binding
|
||||
SetProject key.Binding
|
||||
Select key.Binding
|
||||
Insert key.Binding
|
||||
}
|
||||
|
||||
// NewKeymap creates a new Keymap.
|
||||
@ -29,6 +36,16 @@ func NewKeymap() *Keymap {
|
||||
key.WithHelp("esc", "Back"),
|
||||
),
|
||||
|
||||
Ok: key.NewBinding(
|
||||
key.WithKeys("enter"),
|
||||
key.WithHelp("enter", "Ok"),
|
||||
),
|
||||
|
||||
Input: key.NewBinding(
|
||||
key.WithKeys(":"),
|
||||
key.WithHelp(":", "Input"),
|
||||
),
|
||||
|
||||
Add: key.NewBinding(
|
||||
key.WithKeys("a"),
|
||||
key.WithHelp("a", "Add new task"),
|
||||
@ -39,6 +56,26 @@ func NewKeymap() *Keymap {
|
||||
key.WithHelp("e", "Edit task"),
|
||||
),
|
||||
|
||||
Up: key.NewBinding(
|
||||
key.WithKeys("k", "up"),
|
||||
key.WithHelp("↑/k", "Up"),
|
||||
),
|
||||
|
||||
Down: key.NewBinding(
|
||||
key.WithKeys("j", "down"),
|
||||
key.WithHelp("↓/j", "Down"),
|
||||
),
|
||||
|
||||
Left: key.NewBinding(
|
||||
key.WithKeys("h", "left"),
|
||||
key.WithHelp("←/h", "Left"),
|
||||
),
|
||||
|
||||
Right: key.NewBinding(
|
||||
key.WithKeys("l", "right"),
|
||||
key.WithHelp("→/l", "Right"),
|
||||
),
|
||||
|
||||
SetReport: key.NewBinding(
|
||||
key.WithKeys("r"),
|
||||
key.WithHelp("r", "Set report"),
|
||||
@ -58,5 +95,10 @@ func NewKeymap() *Keymap {
|
||||
key.WithKeys("enter"),
|
||||
key.WithHelp("enter", "Select"),
|
||||
),
|
||||
|
||||
Insert: key.NewBinding(
|
||||
key.WithKeys("i"),
|
||||
key.WithHelp("insert", "Insert mode"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,7 +72,6 @@ func NewStyles(config *taskwarrior.TWConfig) *Styles {
|
||||
styles.Main = lipgloss.NewStyle()
|
||||
|
||||
formTheme := huh.ThemeBase()
|
||||
formTheme.Focused.Card = formTheme.Focused.Card.BorderStyle(lipgloss.RoundedBorder()).BorderBottom(true).BorderTop(true)
|
||||
formTheme.Focused.Title = formTheme.Focused.Title.Bold(true)
|
||||
formTheme.Focused.SelectSelector = formTheme.Focused.SelectSelector.SetString("> ")
|
||||
formTheme.Focused.SelectedOption = formTheme.Focused.SelectedOption.Bold(true)
|
||||
|
||||
Reference in New Issue
Block a user