summaryrefslogtreecommitdiffhomepage
path: root/internal/tui/components/repl/editor.go
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-03-23 22:25:31 +0100
committerKujtim Hoxha <[email protected]>2025-03-23 22:25:31 +0100
commite7258e38aeb46281fda474b8b7fcc3eee35edd9f (patch)
tree0ae4a7558b3942519ff137aed7c3cd6a9b473bf5 /internal/tui/components/repl/editor.go
parent8daa6e774a6e02698c90392e7b2008542f789594 (diff)
downloadopencode-e7258e38aeb46281fda474b8b7fcc3eee35edd9f.tar.gz
opencode-e7258e38aeb46281fda474b8b7fcc3eee35edd9f.zip
initial agent setup
Diffstat (limited to 'internal/tui/components/repl/editor.go')
-rw-r--r--internal/tui/components/repl/editor.go52
1 files changed, 38 insertions, 14 deletions
diff --git a/internal/tui/components/repl/editor.go b/internal/tui/components/repl/editor.go
index 1de216bd0..8d795eb14 100644
--- a/internal/tui/components/repl/editor.go
+++ b/internal/tui/components/repl/editor.go
@@ -1,8 +1,11 @@
package repl
import (
+ "strings"
+
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
+ "github.com/cloudwego/eino/schema"
"github.com/kujtimiihoxha/termai/internal/app"
"github.com/kujtimiihoxha/termai/internal/tui/layout"
"github.com/kujtimiihoxha/vimtea"
@@ -13,6 +16,7 @@ type EditorCmp interface {
layout.Focusable
layout.Sizeable
layout.Bordered
+ layout.Bindings
}
type editorCmp struct {
@@ -25,12 +29,16 @@ type editorCmp struct {
height int
}
-type localKeyMap struct {
- SendMessage key.Binding
- SendMessageI key.Binding
+type editorKeyMap struct {
+ SendMessage key.Binding
+ SendMessageI key.Binding
+ InsertMode key.Binding
+ NormaMode key.Binding
+ VisualMode key.Binding
+ VisualLineMode key.Binding
}
-var keyMap = localKeyMap{
+var editorKeyMapValue = editorKeyMap{
SendMessage: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "send message normal mode"),
@@ -39,6 +47,22 @@ var keyMap = localKeyMap{
key.WithKeys("ctrl+s"),
key.WithHelp("ctrl+s", "send message insert mode"),
),
+ InsertMode: key.NewBinding(
+ key.WithKeys("i"),
+ key.WithHelp("i", "insert mode"),
+ ),
+ NormaMode: key.NewBinding(
+ key.WithKeys("esc"),
+ key.WithHelp("esc", "normal mode"),
+ ),
+ VisualMode: key.NewBinding(
+ key.WithKeys("v"),
+ key.WithHelp("v", "visual mode"),
+ ),
+ VisualLineMode: key.NewBinding(
+ key.WithKeys("V"),
+ key.WithHelp("V", "visual line mode"),
+ ),
}
func (m *editorCmp) Init() tea.Cmd {
@@ -58,11 +82,11 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch {
- case key.Matches(msg, keyMap.SendMessage):
+ case key.Matches(msg, editorKeyMapValue.SendMessage):
if m.editorMode == vimtea.ModeNormal {
return m, m.Send()
}
- case key.Matches(msg, keyMap.SendMessageI):
+ case key.Matches(msg, editorKeyMapValue.SendMessageI):
if m.editorMode == vimtea.ModeInsert {
return m, m.Send()
}
@@ -75,36 +99,30 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
}
-// Blur implements EditorCmp.
func (m *editorCmp) Blur() tea.Cmd {
m.focused = false
return nil
}
-// BorderText implements EditorCmp.
func (m *editorCmp) BorderText() map[layout.BorderPosition]string {
return map[layout.BorderPosition]string{
layout.TopLeftBorder: "New Message",
}
}
-// Focus implements EditorCmp.
func (m *editorCmp) Focus() tea.Cmd {
m.focused = true
return m.editor.Tick()
}
-// GetSize implements EditorCmp.
func (m *editorCmp) GetSize() (int, int) {
return m.width, m.height
}
-// IsFocused implements EditorCmp.
func (m *editorCmp) IsFocused() bool {
return m.focused
}
-// SetSize implements EditorCmp.
func (m *editorCmp) SetSize(width int, height int) {
m.width = width
m.height = height
@@ -113,8 +131,10 @@ func (m *editorCmp) SetSize(width int, height int) {
func (m *editorCmp) Send() tea.Cmd {
return func() tea.Msg {
- // TODO: Send message
- return nil
+ content := strings.Join(m.editor.GetBuffer().Lines(), "\n")
+ m.app.Messages.Create(m.sessionID, *schema.UserMessage(content))
+ m.app.LLM.SendRequest(m.sessionID, content)
+ return m.editor.Reset()
}
}
@@ -122,6 +142,10 @@ func (m *editorCmp) View() string {
return m.editor.View()
}
+func (m *editorCmp) BindingKeys() []key.Binding {
+ return layout.KeyMapToSlice(editorKeyMapValue)
+}
+
func NewEditorCmp(app *app.App) EditorCmp {
return &editorCmp{
app: app,