Skip to main content

ralph_workflow/io/
terminal.rs

1//! Terminal I/O boundary module.
2//!
3//! Handles terminal input/output operations. This is a boundary module
4//! where mutation and imperative code are allowed.
5
6use std::io::{Read, Write};
7
8pub trait BannerOutput: Write + Send {}
9impl<W: Write + Send> BannerOutput for W {}
10
11pub trait TerminalOutput: Write + Send {}
12impl<W: Write + Send> TerminalOutput for W {}
13
14pub trait TerminalInput: Read + Send {}
15impl<R: Read + Send> TerminalInput for R {}
16
17pub fn write_banner_to<W: BannerOutput>(mut output: W, content: &str) -> std::io::Result<()> {
18    output.write_all(content.as_bytes())
19}
20
21pub fn pause_for_enter_with<T: TerminalInput, W: TerminalOutput>(
22    mut input: T,
23    mut output: W,
24) -> std::io::Result<()> {
25    output.write_all(b"\nPress Enter to close... ")?;
26    let mut buf = String::new();
27    input.read_to_string(&mut buf)?;
28    Ok(())
29}