MCPcopy
hub / github.com/charmbracelet/bubbletea / exec

Method exec

exec.go:102–129  ·  view source on GitHub ↗

exec runs an ExecCommand and delivers the results to the program as a Msg.

(c ExecCommand, fn ExecCallback)

Source from the content-addressed store, hash-verified

100
101// exec runs an ExecCommand and delivers the results to the program as a Msg.
102func (p *Program) exec(c ExecCommand, fn ExecCallback) {
103 if err := p.releaseTerminal(false); err != nil {
104 // If we can't release input, abort.
105 if fn != nil {
106 go p.Send(fn(err))
107 }
108 return
109 }
110
111 c.SetStdin(p.input)
112 c.SetStdout(p.output)
113 c.SetStderr(os.Stderr)
114
115 // Execute system command.
116 if err := c.Run(); err != nil {
117 _ = p.RestoreTerminal() // also try to restore the terminal.
118 if fn != nil {
119 go p.Send(fn(err))
120 }
121 return
122 }
123
124 // Have the program re-capture input.
125 err := p.RestoreTerminal()
126 if fn != nil {
127 go p.Send(fn(err))
128 }
129}

Callers 1

eventLoopMethod · 0.95

Calls 7

releaseTerminalMethod · 0.95
SendMethod · 0.95
RestoreTerminalMethod · 0.95
SetStdinMethod · 0.65
SetStdoutMethod · 0.65
SetStderrMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected