Skip to content

Commit 09211c2

Browse files
committed
Improve post-create script output formatting
Indent script output with │ prefix, wrap in ╭─/╰─ brackets, and clear leftover agent UI before printing session-ended message.
1 parent c204eea commit 09211c2

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

cmd/root.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,17 @@ func runPostCreateScript(cfg *mob.Config, worktreePath string) error {
320320
if cfg.PostCreateScript == "" {
321321
return nil
322322
}
323-
p := mobProgress("Running post-create script...")
323+
dim := "\033[2m"
324+
reset := "\033[0m"
325+
mobStatus("Running post-create script...")
326+
fmt.Printf(" %s╭─%s\n", dim, reset)
324327
err := mob.RunPostCreateScript(cfg, worktreePath)
328+
fmt.Printf(" %s╰─%s\n", dim, reset)
325329
if err != nil {
326-
p.Done("Post-create script failed")
330+
mobStatus("Post-create script failed")
327331
return err
328332
}
329-
p.Done("Post-create script completed")
333+
mobStatus("Post-create script completed")
330334
return nil
331335
}
332336

@@ -903,6 +907,7 @@ func launchAgent(root, agent, workdir string, resume bool) error {
903907
}
904908
}
905909

910+
fmt.Print("\033[2K")
906911
mobStatus(fmt.Sprintf("Session ended - mob '%s'", filepath.Base(workdir)))
907912

908913
// Always check for queued action, regardless of how the agent exited

internal/mob/mob.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mob
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"fmt"
67
"os"
@@ -302,14 +303,43 @@ func RunPostCreateScript(cfg *Config, worktreePath string) error {
302303

303304
cmd := exec.Command(scriptPath)
304305
cmd.Dir = worktreePath
305-
cmd.Stdout = os.Stdout
306-
cmd.Stderr = os.Stderr
306+
cmd.Stdout = newPrefixWriter(os.Stdout, " │ ")
307+
cmd.Stderr = newPrefixWriter(os.Stderr, " │ ")
307308
if err := cmd.Run(); err != nil {
308309
return fmt.Errorf("post_create_script failed: %w", err)
309310
}
310311
return nil
311312
}
312313

314+
type prefixWriter struct {
315+
out *os.File
316+
prefix string
317+
atStart bool
318+
}
319+
320+
func newPrefixWriter(out *os.File, prefix string) *prefixWriter {
321+
return &prefixWriter{out: out, prefix: prefix, atStart: true}
322+
}
323+
324+
func (w *prefixWriter) Write(p []byte) (int, error) {
325+
total := len(p)
326+
for len(p) > 0 {
327+
if w.atStart {
328+
w.out.WriteString(w.prefix)
329+
w.atStart = false
330+
}
331+
nl := bytes.IndexByte(p, '\n')
332+
if nl == -1 {
333+
w.out.Write(p)
334+
break
335+
}
336+
w.out.Write(p[:nl+1])
337+
w.atStart = true
338+
p = p[nl+1:]
339+
}
340+
return total, nil
341+
}
342+
313343
// FindMob finds a mob by name.
314344
func FindMob(cfg *Config, name string) *Mob {
315345
for i := range cfg.Mobs {

0 commit comments

Comments
 (0)