-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
17 changed files
with
689 additions
and
221 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
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,13 +1,17 @@ | ||
package tui | ||
|
||
//go:generate stringer -type=Kind | ||
|
||
type Kind int | ||
|
||
const ( | ||
ModuleListKind Kind = iota | ||
ModuleKind | ||
WorkspaceListKind | ||
WorkspaceKind | ||
RunListKind | ||
TaskListKind | ||
RunKind | ||
TaskListKind | ||
TaskKind | ||
LogsKind | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,94 @@ | ||
package module | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/charmbracelet/bubbles/key" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/leg100/pug/internal/module" | ||
"github.com/leg100/pug/internal/resource" | ||
"github.com/leg100/pug/internal/run" | ||
"github.com/leg100/pug/internal/tui" | ||
"github.com/leg100/pug/internal/tui/keys" | ||
runtui "github.com/leg100/pug/internal/tui/run" | ||
tasktui "github.com/leg100/pug/internal/tui/task" | ||
workspacetui "github.com/leg100/pug/internal/tui/workspace" | ||
"github.com/leg100/pug/internal/workspace" | ||
) | ||
|
||
// Maker makes module models. | ||
type Maker struct { | ||
ModuleService *module.Service | ||
WorkspaceService *workspace.Service | ||
RunService *run.Service | ||
|
||
WorkspaceListMaker *workspacetui.ListMaker | ||
RunListMaker *runtui.ListMaker | ||
TaskListMaker *tasktui.ListMaker | ||
} | ||
|
||
func (mm *Maker) Make(mr resource.Resource, width, height int) (tui.Model, error) { | ||
mod, err := mm.ModuleService.Get(mr.ID()) | ||
if err != nil { | ||
return model{}, err | ||
} | ||
|
||
tabs := tui.NewTabSet(width, height) | ||
if _, err := tabs.AddTab(mm.WorkspaceListMaker, mr, "workspaces"); err != nil { | ||
return nil, fmt.Errorf("adding workspaces tab: %w", err) | ||
} | ||
if _, err := tabs.AddTab(mm.RunListMaker, mr, "runs"); err != nil { | ||
return nil, fmt.Errorf("adding runs tab: %w", err) | ||
} | ||
if _, err := tabs.AddTab(mm.TaskListMaker, mr, "tasks"); err != nil { | ||
return nil, fmt.Errorf("adding tasks tab: %w", err) | ||
} | ||
|
||
m := model{ | ||
module: mod, | ||
tabs: tabs, | ||
} | ||
return m, nil | ||
} | ||
|
||
type model struct { | ||
module *module.Module | ||
tabs tui.TabSet | ||
} | ||
|
||
func (m model) Init() tea.Cmd { | ||
return m.tabs.Init() | ||
} | ||
|
||
func (m model) Update(msg tea.Msg) (tui.Model, tea.Cmd) { | ||
var cmds []tea.Cmd | ||
|
||
switch msg := msg.(type) { | ||
case resource.Event[*module.Module]: | ||
if msg.Payload.ID() == m.module.ID() { | ||
m.module = msg.Payload | ||
} | ||
} | ||
// Update tabs | ||
updated, cmd := m.tabs.Update(msg) | ||
cmds = append(cmds, cmd) | ||
m.tabs = updated | ||
|
||
return m, tea.Batch(cmds...) | ||
} | ||
|
||
func (m model) Title() string { | ||
return tui.Breadcrumbs("Module", m.module.Resource) | ||
} | ||
|
||
func (m model) View() string { | ||
return m.tabs.View() | ||
} | ||
|
||
func (m model) Pagination() string { | ||
return "" | ||
} | ||
|
||
func (m model) HelpBindings() (bindings []key.Binding) { | ||
return keys.KeyMapToSlice(workspacetui.Keys) | ||
} |
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
Oops, something went wrong.