1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use crate::{read_string, BoxResult, ReadData, ReadLine};



impl ReadLine for () {
	type Output = String;
	fn try_read_line(&self, mut read_data: ReadData<Self::Output>) -> BoxResult<Self::Output> {
		match (read_data.prompt, &read_data.default) {
			(Some(prompt), Some(default)) => print!("{prompt}(default: {default}) "),
			(None, Some(default)) => print!("(default: {default}) "),
			(Some(prompt), None) => print!("{prompt}"),
			(None, None) => {},
		}
		let output = read_string(&mut read_data.input)?;
		Ok(if output.is_empty() && let Some(default) = read_data.default {
			default
		} else {
			output
		})
	}
}