diff --git a/filesystem/keymap.go b/filesystem/keymap.go index 9256beb..c3b1eaf 100644 --- a/filesystem/keymap.go +++ b/filesystem/keymap.go @@ -19,6 +19,8 @@ type KeyMap struct { EditDown string `json:"edit_down"` EditLeft string `json:"edit_left"` + EditInput string `json:"edit_input"` + Bank string `json:"bank"` AddBang string `json:"add_bang"` @@ -78,6 +80,8 @@ func NewDefaultAzertyKeyMap() KeyMap { EditDown: "ctrl+down", EditLeft: "ctrl+left", + EditInput: "<", + Bank: "tab", AddBang: "&", @@ -139,6 +143,8 @@ func NewDefaultAzertyMacKeyMap() KeyMap { EditDown: "ctrl+down", EditLeft: "ctrl+left", + EditInput: "<", + Bank: "tab", AddBang: "&", @@ -199,6 +205,8 @@ func NewDefaultQwertyKeyMap() KeyMap { EditDown: "ctrl+down", EditLeft: "ctrl+left", + EditInput: "e", + Bank: "tab", AddBang: "1", @@ -260,6 +268,8 @@ func NewDefaultQwertyMacKeyMap() KeyMap { EditDown: "ctrl+down", EditLeft: "ctrl+left", + EditInput: "e", + Bank: "tab", AddBang: "1", diff --git a/go.mod b/go.mod index 3e69b38..0292555 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( ) require ( + github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/charmbracelet/x/ansi v0.2.3 // indirect github.com/charmbracelet/x/term v0.2.0 // indirect diff --git a/go.sum b/go.sum index 94b07da..5bf71de 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= +github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE= diff --git a/ui/control.go b/ui/control.go index 22836b5..5daa8f1 100644 --- a/ui/control.go +++ b/ui/control.go @@ -44,7 +44,14 @@ func (m mainModel) renderControl() string { } var pane string - if m.edit { + if m.edit && m.input.Focused() { + pane = fmt.Sprintf( + "%s (%s) %s", + m.params[m.param].Name(), + m.params[m.param].Display(), + m.input.View(), + ) + } else if m.edit { pane = m.nodeEdit() } else { pane = m.gridInfo() diff --git a/ui/keymap.go b/ui/keymap.go index afe116e..96d8374 100644 --- a/ui/keymap.go +++ b/ui/keymap.go @@ -25,6 +25,8 @@ type keyMap struct { EditDown key.Binding EditLeft key.Binding + EditInput key.Binding + Bank key.Binding AddBang key.Binding @@ -75,7 +77,7 @@ func (k keyMap) ShortHelp() []key.Binding { func (k keyMap) FullHelp() [][]key.Binding { return [][]key.Binding{ {k.Bank, k.AddBang, k.AddEuclid, k.AddPass, k.AddSpread, k.AddCycle, k.AddDice, k.AddToll, k.AddZone, k.AddHole, k.RootNoteUp, k.RootNoteDown, k.ScaleUp, k.ScaleDown, k.Cancel, k.SelectMidiDevice, k.FitGridToWindow, k.Help, k.Quit}, - {k.Play, k.EditNode, k.RemoveNode, k.TriggerNode, k.MuteNode, k.MuteAllNode, k.Copy, k.Cut, k.Paste, k.Up, k.Right, k.Down, k.Left, k.SelectionUp, k.SelectionRight, k.SelectionDown, k.SelectionLeft, k.EditUp, k.EditDown, k.EditRight, k.EditLeft}, + {k.Play, k.EditNode, k.RemoveNode, k.TriggerNode, k.MuteNode, k.MuteAllNode, k.Copy, k.Cut, k.Paste, k.Up, k.Right, k.Down, k.Left, k.SelectionUp, k.SelectionRight, k.SelectionDown, k.SelectionLeft, k.EditUp, k.EditDown, k.EditRight, k.EditLeft, k.EditInput}, } } @@ -176,6 +178,10 @@ func newKeyMap(keys filesystem.KeyMap) keyMap { key.WithKeys(keys.EditLeft), key.WithHelp(keys.EditLeft, "decrease parameter mode value"), ), + EditInput: key.NewBinding( + key.WithKeys(keys.EditInput), + key.WithHelp(keys.EditInput, "input parameter"), + ), Bank: key.NewBinding( key.WithKeys(keys.Bank), key.WithHelp(keys.Bank, "show bank"), diff --git a/ui/ui.go b/ui/ui.go index 4a6054e..af10d28 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -2,6 +2,7 @@ package ui import ( "fmt" + "strconv" "time" "signls/core/common" @@ -13,6 +14,7 @@ import ( "github.com/charmbracelet/bubbles/help" "github.com/charmbracelet/bubbles/key" + "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" ) @@ -44,6 +46,7 @@ type mainModel struct { viewport viewport keymap keyMap help help.Model + input textinput.Model params []param.Param gridParams []param.Param bankClipboard filesystem.Grid @@ -63,11 +66,15 @@ type mainModel struct { // New creates a new mainModel that hols the ui state. It takes a new grid. // Check the core package. func New(config filesystem.Configuration, grid *field.Grid, bank *filesystem.Bank) tea.Model { + ti := textinput.New() + ti.CharLimit = 10 + ti.Width = 12 model := mainModel{ bank: bank, grid: grid, keymap: newKeyMap(config.KeyMap), help: help.New(), + input: ti, gridParams: param.NewParamsForGrid(grid), cursorX: 1, cursorY: 1, @@ -113,10 +120,38 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case blinkMsg: m.blink = !m.blink + m.input.Cursor.Blink = !m.input.Cursor.Blink return m, blink() case tea.KeyMsg: + if m.input.Focused() { + var cmd tea.Cmd + switch { + case key.Matches(msg, m.keymap.EditNode): + m.input.Blur() + val, err := strconv.Atoi(m.input.Value()) + if err != nil { + val = m.params[m.param].Value() + } + m.params[m.param].Set(val) + return m, nil + case key.Matches(msg, m.keymap.Cancel): + m.input.Blur() + return m, nil + default: + m.input, cmd = m.input.Update(msg) + return m, cmd + } + } + switch { + case key.Matches(msg, m.keymap.EditInput): + if !m.edit { + return m, nil + } + m.input.Focus() + m.input.Reset() + return m, nil case key.Matches(msg, m.keymap.Play): m.grid.TogglePlay() return m, nil