Tear down everything
Fix config
This commit is contained in:
71
internal/common/common.go
Normal file
71
internal/common/common.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"tasksquire/internal/taskwarrior"
|
||||
"tasksquire/internal/timewarrior"
|
||||
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
type Common struct {
|
||||
Ctx context.Context
|
||||
TW taskwarrior.TaskWarrior
|
||||
TimeW timewarrior.TimeWarrior
|
||||
Keymap *Keymap
|
||||
Styles *Styles
|
||||
Udas []taskwarrior.Uda
|
||||
|
||||
pageStack *Stack[Component]
|
||||
width int
|
||||
height int
|
||||
}
|
||||
|
||||
func NewCommon(ctx context.Context, tw taskwarrior.TaskWarrior, timeW timewarrior.TimeWarrior) *Common {
|
||||
return &Common{
|
||||
Ctx: ctx,
|
||||
TW: tw,
|
||||
TimeW: timeW,
|
||||
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) {
|
||||
component, err := c.pageStack.Pop()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
component.SetSize(c.width, c.height)
|
||||
return component, nil
|
||||
}
|
||||
|
||||
func (c *Common) HasSubpages() bool {
|
||||
return !c.pageStack.IsEmpty()
|
||||
}
|
||||
Reference in New Issue
Block a user