MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / read_block

Function read_block

cli/src/repl.rs:64–82  ·  view source on GitHub ↗

Collect a multi-line block when the first line ends with `:`; an empty line closes it.

(rl: &mut DefaultEditor, first: String)

Source from the content-addressed store, hash-verified

62
63/// Collect a multi-line block when the first line ends with `:`; an empty line closes it.
64fn read_block(rl: &mut DefaultEditor, first: String) -> Result<BlockResult> {
65 if !first.trim_end().ends_with(':') {
66 return Ok(BlockResult::Done(first));
67 }
68 let mut block = first;
69 loop {
70 match rl.readline(CONT) {
71 Ok(line) if line.is_empty() => return Ok(BlockResult::Done(block)),
72 Ok(line) => {
73 let _ = rl.add_history_entry(line.as_str());
74 block.push('\n');
75 block.push_str(&line);
76 }
77 Err(ReadlineError::Interrupted) => return Ok(BlockResult::Exit), // Ctrl+C exits
78 Err(ReadlineError::Eof) => return Ok(BlockResult::Done(block)), // Ctrl+D submits the partial block
79 Err(e) => return Err(e.into()),
80 }
81 }
82}

Callers 1

runFunction · 0.85

Calls 3

pushMethod · 0.80
is_emptyMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected