MCPcopy Create free account
hub / github.com/charmbracelet/bubbletea / exec

Method exec

exec.go:102–138  ·  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 // Blank the current view before releasing the terminal so the renderer's
104 // final flush doesn't write the last View() output to stdout. Without
105 // this, the view content leaks to the terminal and persists after the
106 // subprocess exits. Terminal mode flags such as AltScreen are preserved so
107 // the screen mode is restored correctly when the program resumes. See #431.
108 if p.renderer != nil {
109 p.renderer.clearView()
110 }
111
112 if err := p.releaseTerminal(false); err != nil {
113 // If we can't release input, abort.
114 if fn != nil {
115 go p.Send(fn(err))
116 }
117 return
118 }
119
120 c.SetStdin(p.input)
121 c.SetStdout(p.output)
122 c.SetStderr(os.Stderr)
123
124 // Execute system command.
125 if err := c.Run(); err != nil {
126 _ = p.RestoreTerminal() // also try to restore the terminal.
127 if fn != nil {
128 go p.Send(fn(err))
129 }
130 return
131 }
132
133 // Have the program re-capture input.
134 err := p.RestoreTerminal()
135 if fn != nil {
136 go p.Send(fn(err))
137 }
138}

Callers 1

eventLoopMethod · 0.95

Calls 8

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

Tested by

no test coverage detected