MCPcopy
hub / github.com/c-bata/go-prompt / Run

Method Run

prompt.go:46–113  ·  view source on GitHub ↗

Run starts prompt.

()

Source from the content-addressed store, hash-verified

44
45// Run starts prompt.
46func (p *Prompt) Run() {
47 p.skipTearDown = false
48 defer debug.Teardown()
49 debug.Log("start prompt")
50 p.setUp()
51 defer p.tearDown()
52
53 if p.completion.showAtStart {
54 p.completion.Update(*p.buf.Document())
55 }
56
57 p.renderer.Render(p.buf, p.completion)
58
59 bufCh := make(chan []byte, 128)
60 stopReadBufCh := make(chan struct{})
61 go p.readBuffer(bufCh, stopReadBufCh)
62
63 exitCh := make(chan int)
64 winSizeCh := make(chan *WinSize)
65 stopHandleSignalCh := make(chan struct{})
66 go p.handleSignals(exitCh, winSizeCh, stopHandleSignalCh)
67
68 for {
69 select {
70 case b := <-bufCh:
71 if shouldExit, e := p.feed(b); shouldExit {
72 p.renderer.BreakLine(p.buf)
73 stopReadBufCh <- struct{}{}
74 stopHandleSignalCh <- struct{}{}
75 return
76 } else if e != nil {
77 // Stop goroutine to run readBuffer function
78 stopReadBufCh <- struct{}{}
79 stopHandleSignalCh <- struct{}{}
80
81 // Unset raw mode
82 // Reset to Blocking mode because returned EAGAIN when still set non-blocking mode.
83 debug.AssertNoError(p.in.TearDown())
84 p.executor(e.input)
85
86 p.completion.Update(*p.buf.Document())
87
88 p.renderer.Render(p.buf, p.completion)
89
90 if p.exitChecker != nil && p.exitChecker(e.input, true) {
91 p.skipTearDown = true
92 return
93 }
94 // Set raw mode
95 debug.AssertNoError(p.in.Setup())
96 go p.readBuffer(bufCh, stopReadBufCh)
97 go p.handleSignals(exitCh, winSizeCh, stopHandleSignalCh)
98 } else {
99 p.completion.Update(*p.buf.Document())
100 p.renderer.Render(p.buf, p.completion)
101 }
102 case w := <-winSizeCh:
103 p.renderer.UpdateWinSize(w)

Callers 8

TestPosixParserGetKeyFunction · 0.80
BenchmarkRightFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
executorFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80

Calls 15

setUpMethod · 0.95
tearDownMethod · 0.95
readBufferMethod · 0.95
handleSignalsMethod · 0.95
feedMethod · 0.95
TeardownFunction · 0.92
LogFunction · 0.92
AssertNoErrorFunction · 0.92
UpdateMethod · 0.80
DocumentMethod · 0.80
RenderMethod · 0.80
BreakLineMethod · 0.80

Tested by 2

TestPosixParserGetKeyFunction · 0.64
BenchmarkRightFunction · 0.64