Read character
()
| 379 | |
| 380 | // Read character |
| 381 | pub fn readchar() -> char |
| 382 | { |
| 383 | // Disable echo |
| 384 | echo_off(); |
| 385 | |
| 386 | // Enable raw |
| 387 | raw_on(); |
| 388 | |
| 389 | loop |
| 390 | { |
| 391 | crate::time::halt(); |
| 392 | let res = interrupts::without_interrupts(|| |
| 393 | { |
| 394 | let mut stdin = STDIN.lock(); |
| 395 | if !stdin.is_empty() |
| 396 | { |
| 397 | Some(stdin.remove(0)) |
| 398 | } |
| 399 | else |
| 400 | { |
| 401 | None |
| 402 | } |
| 403 | }); |
| 404 | |
| 405 | if let Some(c) = res |
| 406 | { |
| 407 | // Enable echo |
| 408 | crate::sys::console::echo_on(); |
| 409 | |
| 410 | // Disable raw |
| 411 | crate::sys::console::raw_off(); |
| 412 | return c; |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | |
| 418 | // Read line |