use io_streams::BufReaderLineWriter;
use nameless::InteractiveTextStream;
use std::io::{BufRead, Read, Write};
use std::str;
const PROMPT: &str = "prompt> \u{34f}";
#[kommand::main]
fn main(io: InteractiveTextStream) -> anyhow::Result<()> {
let mut io = BufReaderLineWriter::new(io);
let mut v = [0_u8; PROMPT.len()];
let mut s = String::new();
io.read_exact(&mut v)?;
if str::from_utf8(&v).unwrap() != PROMPT {
panic!("missed prompt");
}
writeln!(io, "hello")?;
io.read_line(&mut s)?;
if s != "[received \"hello\"]\n" {
panic!("missed response: '{}'", s);
}
io.read_exact(&mut v)?;
if str::from_utf8(&v).unwrap() != PROMPT {
panic!("missed second prompt: {:?}", String::from_utf8_lossy(&v));
}
writeln!(io, "world")?;
s.clear();
io.read_line(&mut s)?;
if s != "[received \"world\"]\n" {
panic!("missed response: '{}'", s);
}
io.read_exact(&mut v)?;
if str::from_utf8(&v).unwrap() != PROMPT {
panic!("missed last prompt");
}
drop(io);
Ok(())
}