1package commands
2
3import (
4 tea "github.com/charmbracelet/bubbletea/v2"
5 "github.com/charmbracelet/lipgloss/v2"
6 "github.com/opencode-ai/opencode/internal/tui/components/dialogs"
7 "github.com/opencode-ai/opencode/internal/tui/styles"
8 "github.com/opencode-ai/opencode/internal/tui/theme"
9)
10
11const (
12 argumentsDialogID dialogs.DialogID = "arguments"
13)
14
15// ShowArgumentsDialogMsg is a message that is sent to show the arguments dialog.
16type ShowArgumentsDialogMsg struct {
17 CommandID string
18 Content string
19 ArgNames []string
20}
21
22// CloseArgumentsDialogMsg is a message that is sent when the arguments dialog is closed.
23type CloseArgumentsDialogMsg struct {
24 Submit bool
25 CommandID string
26 Content string
27 Args map[string]string
28}
29
30// CommandArgumentsDialog represents the commands dialog.
31type CommandArgumentsDialog interface {
32 dialogs.DialogModel
33}
34
35type commandArgumentsDialogCmp struct {
36 width int
37 wWidth int // Width of the terminal window
38 wHeight int // Height of the terminal window
39}
40
41func NewCommandArgumentsDialog() CommandArgumentsDialog {
42 return &commandArgumentsDialogCmp{}
43}
44
45// Init implements CommandArgumentsDialog.
46func (c *commandArgumentsDialogCmp) Init() tea.Cmd {
47 return nil
48}
49
50// Update implements CommandArgumentsDialog.
51func (c *commandArgumentsDialogCmp) Update(tea.Msg) (tea.Model, tea.Cmd) {
52 return c, nil
53}
54
55// View implements CommandArgumentsDialog.
56func (c *commandArgumentsDialogCmp) View() tea.View {
57 return tea.NewView("")
58}
59
60func (c *commandArgumentsDialogCmp) moveCursor(cursor *tea.Cursor) *tea.Cursor {
61 offset := 10 + 1
62 cursor.Y += offset
63 _, col := c.Position()
64 cursor.X = cursor.X + col + 2
65 return cursor
66}
67
68func (c *commandArgumentsDialogCmp) style() lipgloss.Style {
69 t := theme.CurrentTheme()
70 return styles.BaseStyle().
71 Width(c.width).
72 Padding(1).
73 Border(lipgloss.RoundedBorder()).
74 BorderBackground(t.Background()).
75 BorderForeground(t.TextMuted())
76}
77
78func (q *commandArgumentsDialogCmp) Position() (int, int) {
79 row := 10
80 col := q.wWidth / 2
81 col -= q.width / 2
82 return row, col
83}
84
85// ID implements CommandArgumentsDialog.
86func (c *commandArgumentsDialogCmp) ID() dialogs.DialogID {
87 return argumentsDialogID
88}