Collect a multi-line block when the first line ends with `:`; an empty line closes it.
(rl: &mut DefaultEditor, first: String)
| 62 | |
| 63 | /// Collect a multi-line block when the first line ends with `:`; an empty line closes it. |
| 64 | fn 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 | } |