-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
423 additions
and
507 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ workbench | |
pomaquet | ||
.idea/ | ||
assets | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package window | ||
|
||
import ( | ||
tea "github.com/charmbracelet/bubbletea" | ||
tui_pomodoro "github.com/padilo/pomaquet/pkg/pomodoro/tui" | ||
tui_task "github.com/padilo/pomaquet/pkg/task/tui" | ||
"github.com/padilo/pomaquet/pkg/task/tui/crud" | ||
) | ||
|
||
type LeftWindow int64 | ||
|
||
const ( | ||
Task LeftWindow = iota | ||
CrudTask | ||
) | ||
|
||
type model struct { | ||
pomodoroModel tea.Model | ||
taskModel tea.Model | ||
crudModel tea.Model | ||
leftWindow LeftWindow | ||
height int | ||
width int | ||
modeTaskCrud bool | ||
} | ||
|
||
func NewModel() model { | ||
m := model{ | ||
pomodoroModel: tui_pomodoro.NewModel(), | ||
taskModel: tui_task.NewModel(), | ||
crudModel: crud.NewModel(), | ||
modeTaskCrud: false, | ||
} | ||
return m | ||
} | ||
|
||
func (m model) Init() tea.Cmd { | ||
var cmds []tea.Cmd | ||
cmds = append(cmds, m.pomodoroModel.Init()) | ||
cmds = append(cmds, m.taskModel.Init()) | ||
cmds = append(cmds, m.crudModel.Init()) | ||
|
||
return tea.Batch(cmds...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package window | ||
|
||
import ( | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/padilo/pomaquet/pkg/pomodoro/app/core" | ||
) | ||
|
||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
var cmds []tea.Cmd | ||
|
||
switch msg := msg.(type) { | ||
case tea.WindowSizeMsg: | ||
m.height = msg.Height | ||
m.width = msg.Width | ||
dim := m.getDimensions() | ||
|
||
cmds = m.updateModels(msg) | ||
|
||
leftMsg := core.DimensionChangeMsg{ | ||
Dimension: dim.Left, | ||
ScreenSize: dim.Screen, | ||
} | ||
rightMsg := core.DimensionChangeMsg{ | ||
Dimension: dim.Right, | ||
ScreenSize: dim.Screen, | ||
} | ||
var cmd tea.Cmd | ||
m.crudModel, cmd = m.crudModel.Update(leftMsg) | ||
cmds = append(cmds, cmd) | ||
m.taskModel, cmd = m.taskModel.Update(leftMsg) | ||
cmds = append(cmds, cmd) | ||
m.pomodoroModel, cmd = m.pomodoroModel.Update(rightMsg) | ||
cmds = append(cmds, cmd) | ||
|
||
case core.SwitchToTaskCrudMsg: | ||
m.leftWindow = CrudTask | ||
|
||
case core.SwitchToTaskMsg: | ||
m.leftWindow = Task | ||
|
||
case core.CrudOkMsg, core.CrudCancelMsg: | ||
var cmd tea.Cmd | ||
m.taskModel, cmd = m.taskModel.Update(msg) | ||
cmds = append(cmds, cmd) | ||
|
||
case core.SetTaskMsg: | ||
var cmd tea.Cmd | ||
m.crudModel, cmd = m.crudModel.Update(msg) | ||
cmds = append(cmds, cmd) | ||
|
||
default: | ||
cmds = m.updateModels(msg) | ||
} | ||
|
||
return m, tea.Batch(cmds...) | ||
} | ||
|
||
func (m *model) updateModels(msg tea.Msg) []tea.Cmd { | ||
return []tea.Cmd{ | ||
m.updateLeft(msg), | ||
m.updateRight(msg), | ||
} | ||
} | ||
|
||
func (m *model) updateRight(msg tea.Msg) tea.Cmd { | ||
var cmd tea.Cmd | ||
m.pomodoroModel, cmd = m.pomodoroModel.Update(msg) | ||
return cmd | ||
} | ||
|
||
func (m *model) updateLeft(msg tea.Msg) tea.Cmd { | ||
var cmd tea.Cmd | ||
|
||
// TODO: Fix this, must be another way to do what I'm trying to do | ||
switch m.leftWindow { | ||
case Task: | ||
m.taskModel, cmd = m.taskModel.Update(msg) | ||
case CrudTask: | ||
m.crudModel, cmd = m.crudModel.Update(msg) | ||
} | ||
return cmd | ||
} | ||
|
||
func (m model) getLeftModel() tea.Model { | ||
switch m.leftWindow { | ||
case Task: | ||
return m.taskModel | ||
case CrudTask: | ||
return m.crudModel | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (m *model) getDimensions() core.Dimensions { | ||
return core.Dimensions{ | ||
Left: core.Dimension{ | ||
Top: 0, | ||
Left: 0, | ||
Right: m.width/2 - 1, | ||
Bottom: m.height - 1, | ||
}, | ||
Right: core.Dimension{ | ||
Top: 0, | ||
Left: m.width / 2, | ||
Right: m.width - 1, | ||
Bottom: m.height - 1, | ||
}, | ||
Screen: core.Dimension{ | ||
Top: 0, | ||
Left: 0, | ||
Right: m.width, | ||
Bottom: m.height, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,160 +1,9 @@ | ||
package window | ||
|
||
import ( | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/charmbracelet/lipgloss" | ||
"github.com/padilo/pomaquet/pkg/pomodoro/app/core" | ||
tui_pomodoro "github.com/padilo/pomaquet/pkg/pomodoro/tui" | ||
tui_task "github.com/padilo/pomaquet/pkg/task/tui" | ||
"github.com/padilo/pomaquet/pkg/task/tui/crud" | ||
) | ||
|
||
type LeftWindow int64 | ||
|
||
const ( | ||
Task LeftWindow = iota | ||
CrudTask | ||
) | ||
|
||
type model struct { | ||
pomodoroModel tea.Model | ||
taskModel tea.Model | ||
crudModel tea.Model | ||
leftWindow LeftWindow | ||
height int | ||
width int | ||
modeTaskCrud bool | ||
} | ||
|
||
func NewModel() model { | ||
m := model{ | ||
pomodoroModel: tui_pomodoro.NewModel(), | ||
taskModel: tui_task.NewModel(), | ||
crudModel: crud.NewModel(), | ||
modeTaskCrud: false, | ||
} | ||
return m | ||
} | ||
|
||
func (m model) Init() tea.Cmd { | ||
var cmds []tea.Cmd | ||
cmds = append(cmds, m.pomodoroModel.Init()) | ||
cmds = append(cmds, m.taskModel.Init()) | ||
cmds = append(cmds, m.crudModel.Init()) | ||
|
||
return tea.Batch(cmds...) | ||
} | ||
|
||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
var cmds []tea.Cmd | ||
|
||
switch msg := msg.(type) { | ||
case tea.WindowSizeMsg: | ||
m.height = msg.Height | ||
m.width = msg.Width | ||
dim := m.getDimensions() | ||
|
||
cmds = m.updateModels(msg) | ||
|
||
leftMsg := core.DimensionChangeMsg{ | ||
Dimension: dim.Left, | ||
ScreenSize: dim.Screen, | ||
} | ||
rightMsg := core.DimensionChangeMsg{ | ||
Dimension: dim.Right, | ||
ScreenSize: dim.Screen, | ||
} | ||
var cmd tea.Cmd | ||
m.crudModel, cmd = m.crudModel.Update(leftMsg) | ||
cmds = append(cmds, cmd) | ||
m.taskModel, cmd = m.taskModel.Update(leftMsg) | ||
cmds = append(cmds, cmd) | ||
m.pomodoroModel, cmd = m.pomodoroModel.Update(rightMsg) | ||
cmds = append(cmds, cmd) | ||
|
||
case core.SwitchToTaskCrudMsg: | ||
m.leftWindow = CrudTask | ||
|
||
case core.SwitchToTaskMsg: | ||
m.leftWindow = Task | ||
|
||
case core.CrudOkMsg, core.CrudCancelMsg: | ||
var cmd tea.Cmd | ||
m.taskModel, cmd = m.taskModel.Update(msg) | ||
cmds = append(cmds, cmd) | ||
|
||
case core.SetTaskMsg: | ||
var cmd tea.Cmd | ||
m.crudModel, cmd = m.crudModel.Update(msg) | ||
cmds = append(cmds, cmd) | ||
|
||
default: | ||
cmds = m.updateModels(msg) | ||
} | ||
|
||
return m, tea.Batch(cmds...) | ||
} | ||
|
||
func (m *model) updateModels(msg tea.Msg) []tea.Cmd { | ||
return []tea.Cmd{ | ||
m.updateLeft(msg), | ||
m.updateRight(msg), | ||
} | ||
} | ||
|
||
func (m *model) updateRight(msg tea.Msg) tea.Cmd { | ||
var cmd tea.Cmd | ||
m.pomodoroModel, cmd = m.pomodoroModel.Update(msg) | ||
return cmd | ||
} | ||
|
||
func (m *model) updateLeft(msg tea.Msg) tea.Cmd { | ||
var cmd tea.Cmd | ||
|
||
// TODO: Fix this, must be another way to do what I'm trying to do | ||
switch m.leftWindow { | ||
case Task: | ||
m.taskModel, cmd = m.taskModel.Update(msg) | ||
case CrudTask: | ||
m.crudModel, cmd = m.crudModel.Update(msg) | ||
} | ||
return cmd | ||
} | ||
|
||
func (m model) getLeftModel() tea.Model { | ||
switch m.leftWindow { | ||
case Task: | ||
return m.taskModel | ||
case CrudTask: | ||
return m.crudModel | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (m model) View() string { | ||
return lipgloss.JoinHorizontal(lipgloss.Top, m.getLeftModel().View(), m.pomodoroModel.View()) | ||
} | ||
|
||
func (m *model) getDimensions() core.Dimensions { | ||
return core.Dimensions{ | ||
Left: core.Dimension{ | ||
Top: 0, | ||
Left: 0, | ||
Right: m.width/2 - 1, | ||
Bottom: m.height - 1, | ||
}, | ||
Right: core.Dimension{ | ||
Top: 0, | ||
Left: m.width / 2, | ||
Right: m.width - 1, | ||
Bottom: m.height - 1, | ||
}, | ||
Screen: core.Dimension{ | ||
Top: 0, | ||
Left: 0, | ||
Right: m.width, | ||
Bottom: m.height, | ||
}, | ||
} | ||
} |
Oops, something went wrong.