summaryrefslogtreecommitdiffhomepage
path: root/internal/tui/components/chat
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-05-28 15:36:31 -0500
committeradamdottv <[email protected]>2025-05-28 15:36:36 -0500
commit9d7c5efb9b0b60c62aef3777b65b458a31ebbc88 (patch)
tree0f5acb5b8093d872b30178ded53df719be40cf44 /internal/tui/components/chat
parent8863a499a9e311a48d6ab8bc05d267fb2a01f060 (diff)
downloadopencode-9d7c5efb9b0b60c62aef3777b65b458a31ebbc88.tar.gz
opencode-9d7c5efb9b0b60c62aef3777b65b458a31ebbc88.zip
wip: refactoring tui
Diffstat (limited to 'internal/tui/components/chat')
-rw-r--r--internal/tui/components/chat/editor.go26
-rw-r--r--internal/tui/components/chat/messages.go2
-rw-r--r--internal/tui/components/chat/sidebar.go178
3 files changed, 103 insertions, 103 deletions
diff --git a/internal/tui/components/chat/editor.go b/internal/tui/components/chat/editor.go
index 0858e22df..3b82c96d3 100644
--- a/internal/tui/components/chat/editor.go
+++ b/internal/tui/components/chat/editor.go
@@ -13,9 +13,9 @@ import (
"github.com/charmbracelet/bubbles/textarea"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
- "github.com/sst/opencode/internal/app"
"github.com/sst/opencode/internal/message"
"github.com/sst/opencode/internal/status"
+ "github.com/sst/opencode/internal/tui/app"
"github.com/sst/opencode/internal/tui/components/dialog"
"github.com/sst/opencode/internal/tui/image"
"github.com/sst/opencode/internal/tui/layout"
@@ -37,10 +37,10 @@ type editorCmp struct {
}
type EditorKeyMaps struct {
- Send key.Binding
- OpenEditor key.Binding
- Paste key.Binding
- HistoryUp key.Binding
+ Send key.Binding
+ OpenEditor key.Binding
+ Paste key.Binding
+ HistoryUp key.Binding
HistoryDown key.Binding
}
@@ -251,14 +251,14 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.textarea.Focused() && key.Matches(msg, editorMaps.HistoryUp) && !m.app.IsFilepickerOpen() && !m.app.IsCompletionDialogOpen() {
// Get the current line number
currentLine := m.textarea.Line()
-
+
// Only navigate history if we're at the first line
if currentLine == 0 && len(m.history) > 0 {
// Save current message if we're just starting to navigate
if m.historyIndex == len(m.history) {
m.currentMessage = m.textarea.Value()
}
-
+
// Go to previous message in history
if m.historyIndex > 0 {
m.historyIndex--
@@ -267,14 +267,14 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
}
}
-
+
if m.textarea.Focused() && key.Matches(msg, editorMaps.HistoryDown) && !m.app.IsFilepickerOpen() && !m.app.IsCompletionDialogOpen() {
// Get the current line number and total lines
currentLine := m.textarea.Line()
value := m.textarea.Value()
lines := strings.Split(value, "\n")
totalLines := len(lines)
-
+
// Only navigate history if we're at the last line
if currentLine == totalLines-1 {
if m.historyIndex < len(m.history)-1 {
@@ -403,10 +403,10 @@ func CreateTextArea(existing *textarea.Model) textarea.Model {
func NewEditorCmp(app *app.App) tea.Model {
ta := CreateTextArea(nil)
return &editorCmp{
- app: app,
- textarea: ta,
- history: []string{},
- historyIndex: 0,
+ app: app,
+ textarea: ta,
+ history: []string{},
+ historyIndex: 0,
currentMessage: "",
}
}
diff --git a/internal/tui/components/chat/messages.go b/internal/tui/components/chat/messages.go
index 668f0f6cd..ce02e2e07 100644
--- a/internal/tui/components/chat/messages.go
+++ b/internal/tui/components/chat/messages.go
@@ -12,11 +12,11 @@ import (
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
- "github.com/sst/opencode/internal/app"
"github.com/sst/opencode/internal/message"
"github.com/sst/opencode/internal/pubsub"
"github.com/sst/opencode/internal/session"
"github.com/sst/opencode/internal/status"
+ "github.com/sst/opencode/internal/tui/app"
"github.com/sst/opencode/internal/tui/components/dialog"
"github.com/sst/opencode/internal/tui/state"
"github.com/sst/opencode/internal/tui/styles"
diff --git a/internal/tui/components/chat/sidebar.go b/internal/tui/components/chat/sidebar.go
index c2b392c24..6676f9b09 100644
--- a/internal/tui/components/chat/sidebar.go
+++ b/internal/tui/components/chat/sidebar.go
@@ -8,8 +8,8 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
- "github.com/sst/opencode/internal/app"
"github.com/sst/opencode/internal/config"
+ "github.com/sst/opencode/internal/tui/app"
// "github.com/sst/opencode/internal/diff"
"github.com/sst/opencode/internal/history"
"github.com/sst/opencode/internal/pubsub"
@@ -216,17 +216,17 @@ func (m *sidebarCmp) loadModifiedFiles(ctx context.Context) {
// TODO: History service not implemented in API yet
return
/*
- // Get all latest files for this session
- latestFiles, err := m.app.History.ListLatestSessionFiles(ctx, m.app.CurrentSession.ID)
- if err != nil {
- return
- }
+ // Get all latest files for this session
+ latestFiles, err := m.app.History.ListLatestSessionFiles(ctx, m.app.CurrentSession.ID)
+ if err != nil {
+ return
+ }
- // Get all files for this session (to find initial versions)
- allFiles, err := m.app.History.ListBySession(ctx, m.app.CurrentSession.ID)
- if err != nil {
- return
- }
+ // Get all files for this session (to find initial versions)
+ allFiles, err := m.app.History.ListBySession(ctx, m.app.CurrentSession.ID)
+ if err != nil {
+ return
+ }
*/
// Clear the existing map to rebuild it
@@ -236,28 +236,75 @@ func (m *sidebarCmp) loadModifiedFiles(ctx context.Context) {
})
/*
- // Process each latest file
- for _, file := range latestFiles {
+ // Process each latest file
+ for _, file := range latestFiles {
+ // Skip if this is the initial version (no changes to show)
+ if file.Version == history.InitialVersion {
+ continue
+ }
+
+ // Find the initial version for this specific file
+ var initialVersion history.File
+ for _, v := range allFiles {
+ if v.Path == file.Path && v.Version == history.InitialVersion {
+ initialVersion = v
+ break
+ }
+ }
+
+ // Skip if we can't find the initial version
+ if initialVersion.ID == "" {
+ continue
+ }
+ if initialVersion.Content == file.Content {
+ continue
+ }
+
+ // Calculate diff between initial and latest version
+ _, additions, removals := diff.GenerateDiff(initialVersion.Content, file.Content, file.Path)
+
+ // Only add to modified files if there are changes
+ if additions > 0 || removals > 0 {
+ // Remove working directory prefix from file path
+ displayPath := file.Path
+ workingDir := config.WorkingDirectory()
+ displayPath = strings.TrimPrefix(displayPath, workingDir)
+ displayPath = strings.TrimPrefix(displayPath, "/")
+
+ m.modFiles[displayPath] = struct {
+ additions int
+ removals int
+ }{
+ additions: additions,
+ removals: removals,
+ }
+ }
+ }
+ */
+}
+
+func (m *sidebarCmp) processFileChanges(ctx context.Context, file history.File) {
+ // TODO: History service not implemented in API yet
+ return
+ /*
// Skip if this is the initial version (no changes to show)
if file.Version == history.InitialVersion {
- continue
+ return
}
- // Find the initial version for this specific file
- var initialVersion history.File
- for _, v := range allFiles {
- if v.Path == file.Path && v.Version == history.InitialVersion {
- initialVersion = v
- break
- }
+ // Find the initial version for this file
+ initialVersion, err := m.findInitialVersion(ctx, file.Path)
+ if err != nil || initialVersion.ID == "" {
+ return
}
- // Skip if we can't find the initial version
- if initialVersion.ID == "" {
- continue
- }
+ // Skip if content hasn't changed
if initialVersion.Content == file.Content {
- continue
+ // If this file was previously modified but now matches the initial version,
+ // remove it from the modified files list
+ displayPath := getDisplayPath(file.Path)
+ delete(m.modFiles, displayPath)
+ return
}
// Calculate diff between initial and latest version
@@ -265,12 +312,7 @@ func (m *sidebarCmp) loadModifiedFiles(ctx context.Context) {
// Only add to modified files if there are changes
if additions > 0 || removals > 0 {
- // Remove working directory prefix from file path
- displayPath := file.Path
- workingDir := config.WorkingDirectory()
- displayPath = strings.TrimPrefix(displayPath, workingDir)
- displayPath = strings.TrimPrefix(displayPath, "/")
-
+ displayPath := getDisplayPath(file.Path)
m.modFiles[displayPath] = struct {
additions int
removals int
@@ -278,53 +320,11 @@ func (m *sidebarCmp) loadModifiedFiles(ctx context.Context) {
additions: additions,
removals: removals,
}
+ } else {
+ // If no changes, remove from modified files
+ displayPath := getDisplayPath(file.Path)
+ delete(m.modFiles, displayPath)
}
- }
- */
-}
-
-func (m *sidebarCmp) processFileChanges(ctx context.Context, file history.File) {
- // TODO: History service not implemented in API yet
- return
- /*
- // Skip if this is the initial version (no changes to show)
- if file.Version == history.InitialVersion {
- return
- }
-
- // Find the initial version for this file
- initialVersion, err := m.findInitialVersion(ctx, file.Path)
- if err != nil || initialVersion.ID == "" {
- return
- }
-
- // Skip if content hasn't changed
- if initialVersion.Content == file.Content {
- // If this file was previously modified but now matches the initial version,
- // remove it from the modified files list
- displayPath := getDisplayPath(file.Path)
- delete(m.modFiles, displayPath)
- return
- }
-
- // Calculate diff between initial and latest version
- _, additions, removals := diff.GenerateDiff(initialVersion.Content, file.Content, file.Path)
-
- // Only add to modified files if there are changes
- if additions > 0 || removals > 0 {
- displayPath := getDisplayPath(file.Path)
- m.modFiles[displayPath] = struct {
- additions int
- removals int
- }{
- additions: additions,
- removals: removals,
- }
- } else {
- // If no changes, remove from modified files
- displayPath := getDisplayPath(file.Path)
- delete(m.modFiles, displayPath)
- }
*/
}
@@ -333,22 +333,22 @@ func (m *sidebarCmp) findInitialVersion(ctx context.Context, path string) (histo
// TODO: History service not implemented in API yet
return history.File{}, fmt.Errorf("history service not implemented")
/*
- // Get all versions of this file for the session
- fileVersions, err := m.app.History.ListBySession(ctx, m.app.CurrentSession.ID)
- if err != nil {
- return history.File{}, err
- }
+ // Get all versions of this file for the session
+ fileVersions, err := m.app.History.ListBySession(ctx, m.app.CurrentSession.ID)
+ if err != nil {
+ return history.File{}, err
+ }
*/
/*
- // Find the initial version
- for _, v := range fileVersions {
- if v.Path == path && v.Version == history.InitialVersion {
- return v, nil
+ // Find the initial version
+ for _, v := range fileVersions {
+ if v.Path == path && v.Version == history.InitialVersion {
+ return v, nil
+ }
}
- }
- return history.File{}, fmt.Errorf("initial version not found")
+ return history.File{}, fmt.Errorf("initial version not found")
*/
}