-
Notifications
You must be signed in to change notification settings - Fork 40
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
14 changed files
with
976 additions
and
557 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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/charmbracelet/bubbles/key" | ||
"github.com/charmbracelet/bubbles/list" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/charmbracelet/lipgloss" | ||
) | ||
|
||
var ( | ||
ActionStyle = lipgloss.NewStyle(). | ||
Width(30).Height(32). | ||
BorderStyle(lipgloss.NormalBorder()). | ||
BorderForeground(lipgloss.Color("63")) | ||
) | ||
|
||
type ActionModel struct { | ||
List list.Model | ||
} | ||
|
||
func (m *ActionModel) Init() tea.Cmd { return nil } | ||
|
||
func (m *ActionModel) Update(msg tea.Msg) (*ActionModel, tea.Cmd) { | ||
var cmd tea.Cmd | ||
switch msg := msg.(type) { | ||
case tea.KeyMsg: | ||
switch msg.String() { | ||
} | ||
m.List, cmd = m.List.Update(msg) | ||
return m, cmd | ||
case tea.WindowSizeMsg: | ||
} | ||
return m, cmd | ||
} | ||
func (m *ActionModel) View() string { | ||
return ActionStyle.Render(m.List.View()) | ||
} | ||
|
||
func NewAction(i item) *ActionModel { | ||
var ( | ||
appKeys = NewAppKeyMap() | ||
numItems = cap(i.actions) | ||
) | ||
// Make list of actions | ||
items := make([]list.Item, numItems) | ||
for j := 0; j < numItems; j++ { | ||
items[j] = i.actions[j] | ||
} | ||
actionList := list.New(items, list.NewDefaultDelegate(), 0, 32) | ||
actionList.Title = fmt.Sprintf("Actions for %s", i.clade) | ||
actionList.KeyMap = DefaultListKeyMap() | ||
actionList.AdditionalShortHelpKeys = func() []key.Binding { | ||
return []key.Binding{ | ||
appKeys.toggleFocus, | ||
} | ||
} | ||
actionList.AdditionalFullHelpKeys = func() []key.Binding { | ||
return []key.Binding{ | ||
appKeys.toggleFocus, | ||
} | ||
} | ||
actionList.SetShowPagination(false) | ||
actionList.SetShowHelp(false) | ||
actionList.SetShowStatusBar(false) | ||
actionList.SetFilteringEnabled(false) | ||
|
||
return &ActionModel{actionList} | ||
} | ||
|
||
type action struct { | ||
name string `json:"__action_name"` | ||
command []string `json:"__action_command"` | ||
description string `json:"__action_description"` | ||
} | ||
|
||
func (a action) Title() string { return a.name } | ||
func (a action) Description() string { return a.description } | ||
func (a action) FilterValue() string { return a.Title() } |
This file was deleted.
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
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,90 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/charmbracelet/bubbles/key" | ||
"github.com/charmbracelet/bubbles/list" | ||
) | ||
|
||
type AppKeyMap struct { | ||
toggleFocus key.Binding | ||
forceQuit key.Binding | ||
} | ||
|
||
func NewAppKeyMap() *AppKeyMap { | ||
return &AppKeyMap{ | ||
// Swiching focus. | ||
toggleFocus: key.NewBinding( | ||
key.WithKeys("tab"), | ||
key.WithHelp("⇥", "toggle focus"), | ||
), | ||
|
||
// Quitting. | ||
forceQuit: key.NewBinding(key.WithKeys("ctrl+c")), | ||
} | ||
} | ||
|
||
// DefaultListKeyMap returns a default set of keybindings. | ||
func DefaultListKeyMap() list.KeyMap { | ||
return list.KeyMap{ | ||
// Browsing. | ||
CursorUp: key.NewBinding( | ||
key.WithKeys("up"), | ||
key.WithHelp("↑", "up"), | ||
), | ||
CursorDown: key.NewBinding( | ||
key.WithKeys("down"), | ||
key.WithHelp("↓", "down"), | ||
), | ||
PrevPage: key.NewBinding( | ||
key.WithKeys("pgup"), | ||
key.WithHelp("pgup", "prev page"), | ||
), | ||
NextPage: key.NewBinding( | ||
key.WithKeys("pgdown"), | ||
key.WithHelp("pgdn", "next page"), | ||
), | ||
GoToStart: key.NewBinding( | ||
key.WithKeys("home"), | ||
key.WithHelp("home", "go to start"), | ||
), | ||
GoToEnd: key.NewBinding( | ||
key.WithKeys("end"), | ||
key.WithHelp("end", "go to end"), | ||
), | ||
Filter: key.NewBinding( | ||
key.WithKeys("/"), | ||
key.WithHelp("/", "filter"), | ||
), | ||
ClearFilter: key.NewBinding( | ||
key.WithKeys("esc"), | ||
key.WithHelp("esc", "clear filter"), | ||
), | ||
|
||
// Filtering. | ||
CancelWhileFiltering: key.NewBinding( | ||
key.WithKeys("esc"), | ||
key.WithHelp("esc", "cancel"), | ||
), | ||
AcceptWhileFiltering: key.NewBinding( | ||
key.WithKeys("enter", "tab", "up", "down"), | ||
key.WithHelp("enter", "apply filter"), | ||
), | ||
|
||
// Toggle help. | ||
ShowFullHelp: key.NewBinding( | ||
key.WithKeys("?"), | ||
key.WithHelp("?", "more"), | ||
), | ||
CloseFullHelp: key.NewBinding( | ||
key.WithKeys("?"), | ||
key.WithHelp("?", "close help"), | ||
), | ||
|
||
// Quitting. | ||
Quit: key.NewBinding( | ||
key.WithKeys("q"), | ||
key.WithHelp("q", "quit"), | ||
), | ||
ForceQuit: key.NewBinding(key.WithKeys("ctrl+c")), | ||
} | ||
} |
Oops, something went wrong.