From 40c84071c0e372b343d1c4c0d90cc925111d2c9b Mon Sep 17 00:00:00 2001 From: Yu Chen Date: Sat, 7 May 2022 11:36:06 +0800 Subject: [PATCH] add usr app: getchar --- user/src/bin/getchar.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 user/src/bin/getchar.rs diff --git a/user/src/bin/getchar.rs b/user/src/bin/getchar.rs new file mode 100644 index 00000000..cd80e8b5 --- /dev/null +++ b/user/src/bin/getchar.rs @@ -0,0 +1,26 @@ +#![no_std] +#![no_main] + +extern crate alloc; + +#[macro_use] +extern crate user_lib; +use user_lib::console::getchar; + +const LF: u8 = 0x0au8; +const CR: u8 = 0x0du8; + +#[no_mangle] +pub fn main() -> i32 { + println!("getchar starting.... Press 'ENTER' will quit."); + + loop { + let c = getchar(); + + println!("Got Char {}", c); + if c == LF || c==CR { + println!("exit(0)"); + return 0; + } + } +} \ No newline at end of file