summary refs log tree commit diff
path: root/src/main.rs
blob: 9d8ed496b8828787043117faa3d43f0d5f1cbbbe (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
64
65
#![forbid(unsafe_code)]
use crate::result::Result;
use crate::terminal::{Input, Terminal};

use std::process;
use tokio::io::{self, AsyncWriteExt};

pub mod error;
pub mod result;
pub mod terminal;


#[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(())
}