Skip to content

Commit 641fecc

Browse files
authored
Merge pull request #529 from dgageot/fix-527
Fix #527
2 parents 9bff880 + af90878 commit 641fecc

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

pkg/app/app.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package app
33
import (
44
"context"
55
"os/exec"
6-
"strings"
76
"time"
87

98
tea "github.com/charmbracelet/bubbletea/v2"
@@ -54,14 +53,6 @@ func (a *App) Title() string {
5453
func (a *App) Run(ctx context.Context, cancel context.CancelFunc, message string) {
5554
a.cancel = cancel
5655
go func() {
57-
// Special shell command
58-
if strings.HasPrefix(message, "!") {
59-
out, _ := exec.CommandContext(ctx, "/bin/sh", "-c", message[1:]).CombinedOutput()
60-
a.events <- runtime.ShellOutput("$ " + message[1:] + "\n" + string(out))
61-
return
62-
}
63-
64-
// User message
6556
a.session.AddMessage(session.UserMessage(a.agentFilename, message))
6657
for event := range a.runtime.RunStream(ctx, a.session) {
6758
if ctx.Err() != nil {
@@ -72,6 +63,11 @@ func (a *App) Run(ctx context.Context, cancel context.CancelFunc, message string
7263
}()
7364
}
7465

66+
func (a *App) RunBangCommand(ctx context.Context, command string) {
67+
out, _ := exec.CommandContext(ctx, "/bin/sh", "-c", command).CombinedOutput()
68+
a.events <- runtime.ShellOutput("$ " + command + "\n" + string(out))
69+
}
70+
7571
func (a *App) Subscribe(ctx context.Context, program *tea.Program) {
7672
throttledChan := a.throttleEvents(ctx, a.events)
7773
for {

pkg/tui/page/chat/chat.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"strings"
78

89
"github.com/atotto/clipboard"
910
"github.com/charmbracelet/bubbles/v2/help"
@@ -439,7 +440,11 @@ func (p *chatPage) processMessage(content string) tea.Cmd {
439440
var ctx context.Context
440441
ctx, p.msgCancel = context.WithCancel(context.Background())
441442

442-
p.app.Run(ctx, p.msgCancel, content)
443+
if strings.HasPrefix(content, "!") {
444+
p.app.RunBangCommand(ctx, content[1:])
445+
} else {
446+
p.app.Run(ctx, p.msgCancel, content)
447+
}
443448

444449
return p.messages.ScrollToBottom()
445450
}

0 commit comments

Comments
 (0)