blob: 5da00fe2784428aa2f5e6685d5db49e56afedc75 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#![forbid(unsafe_code)]
use crate::error::Result;
use line_input::{Input, Terminal};
use std::process;
use tokio::io::{self, AsyncWriteExt};
pub mod error;
#[tokio::main]
async fn main() -> Result<()> {
let result = repl().await;
process::exit(match result {
Ok(()) => 0,
Err(ref e) => {
eprintln!("{}", e);
1
}
})
}
async fn repl() -> Result<()> {
println!("Hello, terminal!");
let mut terminal = Terminal::init(io::stdin())?;
loop {
prompt().await?;
let input = terminal.handle_input().await?;
match input {
Input::String(string) => {
println!("{:?} {}", string, string.len());
execute(&string).await?
},
Input::End => break,
}
break;
}
terminal.cleanup()?;
Ok(())
}
async fn prompt() -> Result<()> {
let mut stdout = io::stdout();
stdout.write_all("\n$ ".as_bytes()).await?;
stdout.flush().await?;
Ok(())
}
async fn execute(_input: &str) -> Result<()> {
Ok(())
}
|