forked from koniifer/ableos
simplification
This commit is contained in:
parent
834287cdd6
commit
1ca1594f66
|
@ -1,4 +1,4 @@
|
||||||
,-""""-. OS: $BLUE$AbleOS$RESET$
|
,-""""-. OS: \0BLUE\0 AbleOS \0RESET\0
|
||||||
,'\ _ _`. Host: ???
|
,'\ _ _`. Host: ???
|
||||||
/ \)_)-)_)-\ Kernel: AKern-{}-v{}
|
/ \)_)-)_)-\ Kernel: AKern-{}-v{}
|
||||||
: : Uptime: {}
|
: : Uptime: {}
|
||||||
|
|
|
@ -6,7 +6,8 @@ user_processes = ["shell"]
|
||||||
enabled = true
|
enabled = true
|
||||||
level = "Trace"
|
level = "Trace"
|
||||||
log_to_serial = true
|
log_to_serial = true
|
||||||
filter = ["ableos::vterm"]
|
filter = []
|
||||||
|
# "ableos::vterm"]
|
||||||
|
|
||||||
|
|
||||||
[tests]
|
[tests]
|
||||||
|
|
|
@ -16,6 +16,9 @@ use kernel::allocator::ALLOCATOR;
|
||||||
use spin::Lazy;
|
use spin::Lazy;
|
||||||
use x86_64::instructions::interrupts::{disable, enable};
|
use x86_64::instructions::interrupts::{disable, enable};
|
||||||
|
|
||||||
|
pub const BANNER_WIDTH: &str =
|
||||||
|
"================================================================================";
|
||||||
|
|
||||||
// TODO: move to a better place
|
// TODO: move to a better place
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub struct AcpiStruct {}
|
pub struct AcpiStruct {}
|
||||||
|
@ -60,6 +63,8 @@ pub fn scratchpad() {
|
||||||
// bruh();
|
// bruh();
|
||||||
// panic!(":>");
|
// panic!(":>");
|
||||||
|
|
||||||
|
println!("\0RED\0OHNO\0RESET\0");
|
||||||
|
|
||||||
disable();
|
disable();
|
||||||
let tick_time = fetch_time();
|
let tick_time = fetch_time();
|
||||||
|
|
||||||
|
@ -70,8 +75,22 @@ pub fn scratchpad() {
|
||||||
enable();
|
enable();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
include_str!("../assets/balloon.txt"),
|
"{}
|
||||||
|
,-------. OS: \0BLUE\0AbleOS\0RESET\0
|
||||||
|
,'\\ _ _`. Host: None
|
||||||
|
/ \\)_)-)_)-\\ Kernel: \0RED\0AKern-{}-v{}\0RESET\0
|
||||||
|
: : Uptime: {}
|
||||||
|
\\ / Packages: None
|
||||||
|
\\ / Shell: BuiltinShell
|
||||||
|
`. ,' Resolution: 640x480
|
||||||
|
`. ,' Terminal: VGABuffer
|
||||||
|
`.,' CPU: {}
|
||||||
|
/\\`. ,-._ GPU: VGA Compatible
|
||||||
|
`-' Memory: {}/{}
|
||||||
|
{}",
|
||||||
|
// include_str!("../assets/balloon.txt"),
|
||||||
// kstate.hostname,
|
// kstate.hostname,
|
||||||
|
BANNER_WIDTH,
|
||||||
RELEASE_TYPE,
|
RELEASE_TYPE,
|
||||||
KERNEL_VERSION,
|
KERNEL_VERSION,
|
||||||
tick_time,
|
tick_time,
|
||||||
|
@ -79,7 +98,8 @@ pub fn scratchpad() {
|
||||||
// "",
|
// "",
|
||||||
// mem
|
// mem
|
||||||
used,
|
used,
|
||||||
size
|
size,
|
||||||
|
BANNER_WIDTH
|
||||||
);
|
);
|
||||||
|
|
||||||
real_shell();
|
real_shell();
|
||||||
|
@ -118,7 +138,7 @@ pub fn real_shell() {
|
||||||
match x86_64::instructions::interrupts::without_interrupts(|| KEYBUFF.lock().pop()) {
|
match x86_64::instructions::interrupts::without_interrupts(|| KEYBUFF.lock().pop()) {
|
||||||
Some('\n') => {
|
Some('\n') => {
|
||||||
// panic!();
|
// panic!();
|
||||||
// println!();
|
println!();
|
||||||
// match engine.eval_with_scope::<rhai::Dynamic>(&mut scope, &buf) {
|
// match engine.eval_with_scope::<rhai::Dynamic>(&mut scope, &buf) {
|
||||||
// Ok(o) => println!("{o}"),
|
// Ok(o) => println!("{o}"),
|
||||||
|
|
||||||
|
@ -129,7 +149,7 @@ pub fn real_shell() {
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.clear();
|
buf.clear();
|
||||||
print!("\n{}", prompt);
|
print!("{}", prompt);
|
||||||
}
|
}
|
||||||
Some('\u{0008}') => {
|
Some('\u{0008}') => {
|
||||||
print!("\u{08}");
|
print!("\u{08}");
|
||||||
|
|
|
@ -8,6 +8,7 @@ const CURSOR_COLOR: Color16 = Color16::Cyan;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Term {
|
pub struct Term {
|
||||||
dirty: bool,
|
dirty: bool,
|
||||||
|
color: Color16,
|
||||||
term: [(char, Color16); 80 * 60],
|
term: [(char, Color16); 80 * 60],
|
||||||
x: u8,
|
x: u8,
|
||||||
}
|
}
|
||||||
|
@ -21,6 +22,7 @@ impl Term {
|
||||||
dirty: false,
|
dirty: false,
|
||||||
x: 0,
|
x: 0,
|
||||||
term: [('\0', Color16::LightGrey); 80 * 60],
|
term: [('\0', Color16::LightGrey); 80 * 60],
|
||||||
|
color: Color16::White,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn is_dirty(&self) -> bool {
|
pub fn is_dirty(&self) -> bool {
|
||||||
|
@ -32,70 +34,38 @@ impl Term {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print(&mut self, data: &str) {
|
pub fn print(&mut self, data: &str) {
|
||||||
for c in data.chars() {
|
let mut lex = Token::lexer(data);
|
||||||
if self.x == 79 {
|
|
||||||
self.move_up();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
match c {
|
|
||||||
'\u{08}' => {
|
|
||||||
if self.x == 0 {
|
|
||||||
// trace!("IMPOSSIBLE BACKSPACE");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
trace!("BACKSPACE");
|
|
||||||
self.x -= 1;
|
|
||||||
self.term[TERM_MINUS_ONE_LINE + (self.x as usize)] = ('\0', Color16::LightGrey);
|
|
||||||
}
|
|
||||||
'\n' => {
|
|
||||||
self.move_up();
|
|
||||||
self.x = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
c => {
|
|
||||||
self.term[TERM_MINUS_ONE_LINE + (self.x as usize)] = (c, Color16::White);
|
|
||||||
self.x += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO:DEADLOCK: Fix this up
|
|
||||||
pub fn cprint(&mut self, data: &str) {
|
|
||||||
let lex = Token::lexer(data);
|
|
||||||
|
|
||||||
trace!("{:?}", lex);
|
|
||||||
|
|
||||||
let mut color = Color16::Red;
|
|
||||||
for toke in lex {
|
for toke in lex {
|
||||||
match toke {
|
match toke {
|
||||||
Token::Error =>
|
Token::Reset => {
|
||||||
// unsafe { asm!("int 54") },
|
self.color = Color16::White;
|
||||||
{}
|
}
|
||||||
Token::TBlack => color = Color16::Black,
|
Token::Error => {}
|
||||||
Token::TBlue => {
|
Token::TBlack => self.color = Color16::Black,
|
||||||
color = Color16::Blue;
|
Token::TBlue => self.color = Color16::Blue,
|
||||||
trace!("");
|
Token::TGreen => self.color = Color16::Green,
|
||||||
|
Token::TCyan => self.color = Color16::Cyan,
|
||||||
|
Token::TRed => self.color = Color16::Red,
|
||||||
|
Token::TMagenta => self.color = Color16::Magenta,
|
||||||
|
Token::TBrown => self.color = Color16::Brown,
|
||||||
|
Token::TLightGrey => self.color = Color16::LightGrey,
|
||||||
|
Token::TDarkGrey => self.color = Color16::DarkGrey,
|
||||||
|
Token::TLightBlue => self.color = Color16::LightBlue,
|
||||||
|
Token::TLightGreen => self.color = Color16::LightGreen,
|
||||||
|
Token::TLightCyan => self.color = Color16::LightCyan,
|
||||||
|
Token::TLightRed => self.color = Color16::LightRed,
|
||||||
|
Token::TPink => self.color = Color16::Pink,
|
||||||
|
Token::TYellow => self.color = Color16::Yellow,
|
||||||
|
Token::TWhite => self.color = Color16::White,
|
||||||
|
Token::Space => {
|
||||||
|
self.term[TERM_MINUS_ONE_LINE + (self.x as usize)] = (' ', self.color);
|
||||||
|
self.x += 1;
|
||||||
}
|
}
|
||||||
Token::TGreen => color = Color16::Green,
|
|
||||||
Token::TCyan => color = Color16::Cyan,
|
|
||||||
Token::TRed => color = Color16::Red,
|
|
||||||
Token::TMagenta => color = Color16::Magenta,
|
|
||||||
Token::TBrown => color = Color16::Brown,
|
|
||||||
Token::TLightGrey => color = Color16::LightGrey,
|
|
||||||
Token::TDarkGrey => color = Color16::DarkGrey,
|
|
||||||
Token::TLightBlue => color = Color16::LightBlue,
|
|
||||||
Token::TLightGreen => color = Color16::LightGreen,
|
|
||||||
Token::TLightCyan => color = Color16::LightCyan,
|
|
||||||
Token::TLightRed => color = Color16::LightRed,
|
|
||||||
Token::TPink => color = Color16::Pink,
|
|
||||||
Token::TYellow => color = Color16::Yellow,
|
|
||||||
Token::TWhite => color = Color16::White,
|
|
||||||
Token::Text(st) => {
|
Token::Text(st) => {
|
||||||
for c in st.chars() {
|
for c in st.chars() {
|
||||||
if self.x == 79 {
|
if self.x == 80 {
|
||||||
self.move_up();
|
self.move_up();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match c {
|
match c {
|
||||||
|
@ -115,7 +85,8 @@ impl Term {
|
||||||
}
|
}
|
||||||
|
|
||||||
c => {
|
c => {
|
||||||
self.term[TERM_MINUS_ONE_LINE + (self.x as usize)] = (c, color);
|
self.term[TERM_MINUS_ONE_LINE + (self.x as usize)] =
|
||||||
|
(c, self.color);
|
||||||
self.x += 1;
|
self.x += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,7 +115,20 @@ impl Term {
|
||||||
use Color16::*;
|
use Color16::*;
|
||||||
let mode = VGAE.lock();
|
let mode = VGAE.lock();
|
||||||
mode.clear_screen(DarkGrey);
|
mode.clear_screen(DarkGrey);
|
||||||
|
let mut x = 0;
|
||||||
|
let mut y = 0;
|
||||||
|
|
||||||
|
for c in self.term {
|
||||||
|
mode.draw_character(x * 8, y * 8, c.0, c.1);
|
||||||
|
if x == 79 {
|
||||||
|
y += 1;
|
||||||
|
x = 0;
|
||||||
|
} else {
|
||||||
|
x += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
let mouse_coord = x86_64::instructions::interrupts::without_interrupts(|| {
|
let mouse_coord = x86_64::instructions::interrupts::without_interrupts(|| {
|
||||||
let cursor = MOUSE.lock();
|
let cursor = MOUSE.lock();
|
||||||
|
|
||||||
|
@ -166,18 +150,6 @@ impl Term {
|
||||||
(mouse_coord.0 as isize + 0, mouse_coord.1 as isize + 5),
|
(mouse_coord.0 as isize + 0, mouse_coord.1 as isize + 5),
|
||||||
CURSOR_COLOR,
|
CURSOR_COLOR,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut x = 0;
|
|
||||||
let mut y = 0;
|
|
||||||
|
|
||||||
for c in self.term {
|
|
||||||
mode.draw_character(x * 8, y * 8, c.0, c.1);
|
|
||||||
if x == 79 {
|
|
||||||
y += 1;
|
|
||||||
x = 0;
|
|
||||||
} else {
|
|
||||||
x += 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.set_dirty(false);
|
self.set_dirty(false);
|
||||||
|
@ -188,72 +160,53 @@ impl Term {
|
||||||
|
|
||||||
#[derive(Logos, Debug, Clone, PartialEq)]
|
#[derive(Logos, Debug, Clone, PartialEq)]
|
||||||
pub enum Token {
|
pub enum Token {
|
||||||
#[regex(r"[\t\n\f]+", logos::skip)]
|
#[regex(r"", logos::skip)]
|
||||||
#[error]
|
#[error]
|
||||||
Error,
|
Error,
|
||||||
|
|
||||||
#[token("$BLACK$")]
|
#[token("\0RESET\0", priority = 10)]
|
||||||
|
Reset,
|
||||||
|
|
||||||
|
#[token("\0BLACK\0", priority = 10)]
|
||||||
TBlack,
|
TBlack,
|
||||||
#[token("$BLUE$")]
|
#[regex("\0BLUE\0", priority = 10)]
|
||||||
TBlue,
|
TBlue,
|
||||||
#[token("$GREEN$")]
|
#[token("\0GREEN\0", priority = 10)]
|
||||||
TGreen,
|
TGreen,
|
||||||
#[token("$CYAN$")]
|
#[token("\0CYAN\0", priority = 10)]
|
||||||
TCyan,
|
TCyan,
|
||||||
#[token("$RED$")]
|
#[token("\0RED\0", priority = 10)]
|
||||||
TRed,
|
TRed,
|
||||||
#[token("$MAGENTA$")]
|
#[token("\0MAGENTA\0", priority = 10)]
|
||||||
TMagenta,
|
TMagenta,
|
||||||
#[token("$BROWN$")]
|
#[token("\0BROWN\0", priority = 10)]
|
||||||
TBrown,
|
TBrown,
|
||||||
#[token("$LIGHTGREY$")]
|
#[token("\0LIGHTGREY\0", priority = 10)]
|
||||||
TLightGrey,
|
TLightGrey,
|
||||||
#[token("$DARKGREY$")]
|
#[token("\0DARKGREY\0", priority = 10)]
|
||||||
TDarkGrey,
|
TDarkGrey,
|
||||||
#[token("$LIGHTBLUE$")]
|
#[token("\0LIGHTBLUE\0", priority = 10)]
|
||||||
TLightBlue,
|
TLightBlue,
|
||||||
#[token("$LIGHTGREEN$")]
|
#[token("\0LIGHTGREEN\0", priority = 10)]
|
||||||
TLightGreen,
|
TLightGreen,
|
||||||
#[token("$LIGHTCYAN$")]
|
#[token("\0LIGHTCYAN\0", priority = 10)]
|
||||||
TLightCyan,
|
TLightCyan,
|
||||||
#[token("$LIGHTRED$")]
|
#[token("\0LIGHTRED\0", priority = 10)]
|
||||||
TLightRed,
|
TLightRed,
|
||||||
#[token("$PINK$")]
|
#[token("\0PINK\0", priority = 10)]
|
||||||
TPink,
|
TPink,
|
||||||
#[token("$YELLOW$")]
|
#[token("\0YELLOW\0", priority = 10)]
|
||||||
TYellow,
|
TYellow,
|
||||||
#[token("$WHITE$")]
|
#[token("\0WHITE\0", priority = 10)]
|
||||||
TWhite,
|
TWhite,
|
||||||
|
|
||||||
#[regex("/[\x00-\x7F]/", text_lex)]
|
#[token(" ")]
|
||||||
|
Space,
|
||||||
|
|
||||||
|
#[regex("[\t\n!-~]+", text_lex, priority = 0)]
|
||||||
Text(String),
|
Text(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn text_lex(lex: &mut Lexer<Token>) -> String {
|
fn text_lex(lex: &mut Lexer<Token>) -> String {
|
||||||
lex.slice().into()
|
lex.slice().into()
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<Color16> for Token {
|
|
||||||
fn into(self) -> Color16 {
|
|
||||||
match self {
|
|
||||||
Token::Error => todo!(),
|
|
||||||
Token::TBlack => Color16::Black,
|
|
||||||
Token::TBlue => Color16::Blue,
|
|
||||||
Token::TGreen => Color16::Green,
|
|
||||||
Token::TCyan => Color16::Cyan,
|
|
||||||
Token::TRed => Color16::Red,
|
|
||||||
Token::TMagenta => Color16::Magenta,
|
|
||||||
Token::TBrown => Color16::Brown,
|
|
||||||
Token::TLightGrey => Color16::LightGrey,
|
|
||||||
Token::TDarkGrey => Color16::DarkGrey,
|
|
||||||
Token::TLightBlue => Color16::LightBlue,
|
|
||||||
Token::TLightGreen => Color16::LightGreen,
|
|
||||||
Token::TLightCyan => Color16::LightCyan,
|
|
||||||
Token::TLightRed => Color16::LightRed,
|
|
||||||
Token::TPink => Color16::Pink,
|
|
||||||
Token::TYellow => Color16::Yellow,
|
|
||||||
Token::TWhite => Color16::White,
|
|
||||||
Token::Text(_) => todo!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue