59 lines
1.0 KiB
Go
59 lines
1.0 KiB
Go
package common
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"os"
|
|
|
|
"tasksquire/taskwarrior"
|
|
|
|
"golang.org/x/term"
|
|
)
|
|
|
|
type Common struct {
|
|
Ctx context.Context
|
|
TW taskwarrior.TaskWarrior
|
|
Keymap *Keymap
|
|
Styles *Styles
|
|
Udas []string
|
|
|
|
pageStack *Stack[Component]
|
|
width int
|
|
height int
|
|
}
|
|
|
|
func NewCommon(ctx context.Context, tw taskwarrior.TaskWarrior) *Common {
|
|
return &Common{
|
|
Ctx: ctx,
|
|
TW: tw,
|
|
Keymap: NewKeymap(),
|
|
Styles: NewStyles(tw.GetConfig()),
|
|
Udas: tw.GetUdas(),
|
|
|
|
pageStack: NewStack[Component](),
|
|
}
|
|
}
|
|
|
|
func (c *Common) SetSize(width, height int) {
|
|
c.width = width
|
|
c.height = height
|
|
physicalWidth, physicalHeight, _ := term.GetSize(int(os.Stdout.Fd()))
|
|
slog.Info("SetSize", "width", width, "height", height, "physicalWidth", physicalWidth, "physicalHeight", physicalHeight)
|
|
}
|
|
|
|
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()
|
|
}
|