MCPcopy Index your code
hub / github.com/coder/coder / readUntil

Function readUntil

cli/cliui/prompt.go:189–208  ·  view source on GitHub ↗

readUntil the first occurrence of delim in the input, returning a string containing the data up to and including the delimiter. Unlike `bufio`, it only reads until the delimiter and no further bytes. If readUntil encounters an error before finding a delimiter, it returns the data read before the err

(r io.Reader, delim byte)

Source from the content-addressed store, hash-verified

187// before the error and the error itself (often io.EOF). readUntil returns err != nil if and only if
188// the returned data does not end in delim.
189func readUntil(r io.Reader, delim byte) (string, error) {
190 var (
191 have []byte
192 b = make([]byte, 1)
193 )
194 for {
195 n, err := r.Read(b)
196 if n > 0 {
197 have = append(have, b[0])
198 if b[0] == delim {
199 // match `bufio` in that we only return non-nil if we didn't find the delimiter,
200 // regardless of whether we also erred.
201 return string(have), nil
202 }
203 }
204 if err != nil {
205 return string(have), err
206 }
207 }
208}
209
210// readSecretInput reads secret input from the terminal rune-by-rune,
211// masking each character with an asterisk.

Callers 2

PromptFunction · 0.85
promptJSONFunction · 0.85

Calls 1

ReadMethod · 0.65

Tested by

no test coverage detected