ssm-browse: added cd command
Also came up with an approach for dealing with commands that will probably work with contexts
This commit is contained in:
parent
0b745a6dfa
commit
f6f06eb22d
13 changed files with 142 additions and 37 deletions
|
|
@ -2,6 +2,7 @@ package ui
|
|||
|
||||
import (
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/lmika/awstools/internal/common/ui/commandctrl"
|
||||
"github.com/lmika/awstools/internal/dynamo-browse/ui/teamodels/layout"
|
||||
"github.com/lmika/awstools/internal/dynamo-browse/ui/teamodels/statusandprompt"
|
||||
"github.com/lmika/awstools/internal/ssm-browse/controllers"
|
||||
|
|
@ -9,26 +10,29 @@ import (
|
|||
)
|
||||
|
||||
type Model struct {
|
||||
controller *controllers.SSMController
|
||||
cmdController *commandctrl.CommandController
|
||||
controller *controllers.SSMController
|
||||
statusAndPrompt *statusandprompt.StatusAndPrompt
|
||||
|
||||
root tea.Model
|
||||
root tea.Model
|
||||
ssmList *ssmlist.Model
|
||||
}
|
||||
|
||||
func NewModel(controller *controllers.SSMController) Model {
|
||||
func NewModel(controller *controllers.SSMController, cmdController *commandctrl.CommandController) Model {
|
||||
ssmList := ssmlist.New()
|
||||
root := layout.FullScreen(
|
||||
statusandprompt.New(ssmList, "Hello SSM"),
|
||||
)
|
||||
statusAndPrompt := statusandprompt.New(ssmList, "Hello SSM")
|
||||
|
||||
root := layout.FullScreen(statusAndPrompt)
|
||||
|
||||
return Model{
|
||||
controller: controller,
|
||||
root: root,
|
||||
ssmList: ssmList,
|
||||
controller: controller,
|
||||
cmdController: cmdController,
|
||||
root: root,
|
||||
statusAndPrompt: statusAndPrompt,
|
||||
ssmList: ssmList,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (m Model) Init() tea.Cmd {
|
||||
return m.controller.Fetch()
|
||||
}
|
||||
|
|
@ -36,11 +40,19 @@ func (m Model) Init() tea.Cmd {
|
|||
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case controllers.NewParameterListMsg:
|
||||
m.ssmList.SetPrefix(msg.Prefix)
|
||||
m.ssmList.SetParameters(msg.Parameters)
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "ctrl+c", "q":
|
||||
return m, tea.Quit
|
||||
if !m.statusAndPrompt.InPrompt() {
|
||||
switch msg.String() {
|
||||
// TEMP
|
||||
case ":":
|
||||
return m, m.cmdController.Prompt()
|
||||
// END TEMP
|
||||
|
||||
case "ctrl+c", "q":
|
||||
return m, tea.Quit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -52,4 +64,3 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
func (m Model) View() string {
|
||||
return m.root.View()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ type Model struct {
|
|||
}
|
||||
|
||||
func New() *Model {
|
||||
frameTitle := frame.NewFrameTitle("SSM", true)
|
||||
frameTitle := frame.NewFrameTitle("SSM: /", true)
|
||||
table := table.New([]string{"name", "type", "value"}, 0, 0)
|
||||
|
||||
return &Model{
|
||||
|
|
@ -28,6 +28,10 @@ func New() *Model {
|
|||
}
|
||||
}
|
||||
|
||||
func (m *Model) SetPrefix(newPrefix string) {
|
||||
m.frameTitle.SetTitle("SSM: " + newPrefix)
|
||||
}
|
||||
|
||||
func (m *Model) SetParameters(parameters *models.SSMParameters) {
|
||||
m.parameters = parameters
|
||||
cols := []string{"name", "type", "value"}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
table "github.com/calyptia/go-bubble-table"
|
||||
"github.com/lmika/awstools/internal/ssm-browse/models"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type itemTableRow struct {
|
||||
|
|
@ -12,7 +13,8 @@ type itemTableRow struct {
|
|||
}
|
||||
|
||||
func (mtr itemTableRow) Render(w io.Writer, model table.Model, index int) {
|
||||
line := fmt.Sprintf("%s\t%s\t%s", mtr.item.Name, "String", mtr.item.Value)
|
||||
firstLine := strings.SplitN(mtr.item.Value, "\n", 2)[0]
|
||||
line := fmt.Sprintf("%s\t%s\t%s", mtr.item.Name, "String", firstLine)
|
||||
|
||||
if index == model.Cursor() {
|
||||
fmt.Fprintln(w, model.Styles.SelectedRow.Render(line))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue