-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1096 from stlankes/shell
add option to start a simple shell as async task
- Loading branch information
Showing
8 changed files
with
131 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use hermit_sync::Lazy; | ||
use simple_shell::*; | ||
|
||
use crate::arch::kernel::COM1; | ||
use crate::interrupts::print_statistics; | ||
|
||
fn read() -> Option<u8> { | ||
COM1.lock().as_mut().map(|s| s.read())? | ||
} | ||
|
||
static mut SHELL: Lazy<Shell<'_>> = Lazy::new(|| { | ||
let (print, read) = (|s: &str| print!("{}", s), read); | ||
let mut shell = Shell::new(print, read); | ||
|
||
shell.commands.insert( | ||
"help", | ||
ShellCommand { | ||
help: "Print this help message", | ||
func: |_, shell| { | ||
shell.print_help_screen(); | ||
Ok(()) | ||
}, | ||
aliases: &["?", "h"], | ||
}, | ||
); | ||
shell.commands.insert( | ||
"interrupts", | ||
ShellCommand { | ||
help: "Shows the number of received interrupts", | ||
func: |_, shell| { | ||
print_statistics(); | ||
Ok(()) | ||
}, | ||
aliases: &["i"], | ||
}, | ||
); | ||
shell.commands.insert( | ||
"shutdown", | ||
ShellCommand { | ||
help: "Shutdown HermitOS", | ||
func: |_, shell| { | ||
crate::__sys_shutdown(0); | ||
Ok(()) | ||
}, | ||
aliases: &["s"], | ||
}, | ||
); | ||
|
||
shell | ||
}); | ||
|
||
pub(crate) fn init() { | ||
// Also supports async | ||
crate::executor::spawn(unsafe { SHELL.run_async() }); | ||
} |