MCPcopy Index your code
hub / github.com/abiosoft/ishell / readLine

Method readLine

reader.go:63–99  ·  view source on GitHub ↗
(consumer chan lineString)

Source from the content-addressed store, hash-verified

61}
62
63func (s *shellReader) readLine(consumer chan lineString) {
64 s.Lock()
65 defer s.Unlock()
66
67 // already reading
68 if s.reading {
69 return
70 }
71 s.reading = true
72 // start reading
73
74 // detect if print is called to
75 // prevent readline lib from clearing line.
76 // use the last line as prompt.
77 // TODO find better way.
78 shellPrompt := s.prompt
79 prompt := s.rlPrompt()
80 if s.buf.Len() > 0 {
81 lines := strings.Split(s.buf.String(), "\n")
82 if p := lines[len(lines)-1]; strings.TrimSpace(p) != "" {
83 prompt = p
84 }
85 s.buf.Truncate(0)
86 }
87
88 // use printed statement as prompt
89 s.scanner.SetPrompt(prompt)
90
91 line, err := s.scanner.ReadlineWithDefault(s.defaultInput)
92
93 // reset prompt
94 s.scanner.SetPrompt(shellPrompt)
95
96 ls := lineString{string(line), err}
97 consumer <- ls
98 s.reading = false
99}

Callers

nothing calls this directly

Calls 3

rlPromptMethod · 0.95
LenMethod · 0.80
SetPromptMethod · 0.65

Tested by

no test coverage detected