add basic script repl
This commit is contained in:
parent
0d1a12202f
commit
a2cca0be4e
15 changed files with 1041 additions and 61 deletions
|
@ -1,7 +1,7 @@
|
|||
use core::fmt;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use spin::Mutex;
|
||||
use spin::{Mutex, MutexGuard};
|
||||
|
||||
use crate::hard::vga::{self, Vga};
|
||||
|
||||
|
@ -17,12 +17,16 @@ macro_rules! println {
|
|||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref Out: Mutex<Console> = Mutex::new(Console::init());
|
||||
static ref OUT: Mutex<Console> = Mutex::new(Console::init());
|
||||
}
|
||||
|
||||
pub fn out<'r>() -> MutexGuard<'r, Console> {
|
||||
OUT.lock()
|
||||
}
|
||||
|
||||
pub struct Console {
|
||||
cursor: Cursor,
|
||||
vga: Vga,
|
||||
pub cursor: Cursor,
|
||||
pub vga: Vga,
|
||||
}
|
||||
|
||||
impl Console {
|
||||
|
@ -44,6 +48,11 @@ impl Console {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn correct(&mut self) {
|
||||
self.cursor.set_col((self.cursor.col().max(1) - 1));
|
||||
self.vga.write_at(self.cursor.pos(), ' ');
|
||||
}
|
||||
}
|
||||
|
||||
struct Cursor {
|
||||
|
@ -67,14 +76,6 @@ impl Cursor {
|
|||
(self.column, self.line)
|
||||
}
|
||||
|
||||
pub fn set_line(&mut self, line: usize) {
|
||||
self.line = line;
|
||||
}
|
||||
|
||||
pub fn set_col(&mut self, col: usize) {
|
||||
self.column = col;
|
||||
}
|
||||
|
||||
pub fn line(&self) -> usize {
|
||||
self.line
|
||||
}
|
||||
|
@ -83,6 +84,18 @@ impl Cursor {
|
|||
self.column
|
||||
}
|
||||
|
||||
pub fn set_pos(&mut self, pos: (usize, usize)) {
|
||||
(self.column, self.line) = pos;
|
||||
}
|
||||
|
||||
pub fn set_line(&mut self, line: usize) {
|
||||
self.line = line;
|
||||
}
|
||||
|
||||
pub fn set_col(&mut self, col: usize) {
|
||||
self.column = col;
|
||||
}
|
||||
|
||||
pub fn progress(&mut self) {
|
||||
self.column += 1;
|
||||
if self.column < self.width {
|
||||
|
@ -113,6 +126,6 @@ pub fn print_args(args: fmt::Arguments) {
|
|||
use core::fmt::Write;
|
||||
use x86_64::instructions::interrupts;
|
||||
interrupts::without_interrupts(|| {
|
||||
Out.lock().write_fmt(args).unwrap();
|
||||
OUT.lock().write_fmt(args).unwrap();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue