simplification

master
able 2022-08-02 06:00:21 -05:00
parent b1dee8506b
commit 347975e4fa
4 changed files with 104 additions and 130 deletions

View File

@ -1,4 +1,4 @@
,-""""-. OS: $BLUE$AbleOS$RESET$
,-""""-. OS: \0BLUE\0 AbleOS \0RESET\0
,'\ _ _`. Host: ???
/ \)_)-)_)-\ Kernel: AKern-{}-v{}
: : Uptime: {}

View File

@ -6,7 +6,8 @@ user_processes = ["shell"]
enabled = true
level = "Trace"
log_to_serial = true
filter = ["ableos::vterm"]
filter = []
# "ableos::vterm"]
[tests]

View File

@ -16,6 +16,9 @@ use kernel::allocator::ALLOCATOR;
use spin::Lazy;
use x86_64::instructions::interrupts::{disable, enable};
pub const BANNER_WIDTH: &str =
"================================================================================";
// TODO: move to a better place
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct AcpiStruct {}
@ -60,6 +63,8 @@ pub fn scratchpad() {
// bruh();
// panic!(":>");
println!("\0RED\0OHNO\0RESET\0");
disable();
let tick_time = fetch_time();
@ -70,8 +75,22 @@ pub fn scratchpad() {
enable();
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,
BANNER_WIDTH,
RELEASE_TYPE,
KERNEL_VERSION,
tick_time,
@ -79,7 +98,8 @@ pub fn scratchpad() {
// "",
// mem
used,
size
size,
BANNER_WIDTH
);
real_shell();
@ -118,7 +138,7 @@ pub fn real_shell() {
match x86_64::instructions::interrupts::without_interrupts(|| KEYBUFF.lock().pop()) {
Some('\n') => {
// panic!();
// println!();
println!();
// match engine.eval_with_scope::<rhai::Dynamic>(&mut scope, &buf) {
// Ok(o) => println!("{o}"),
@ -129,7 +149,7 @@ pub fn real_shell() {
}
buf.clear();
print!("\n{}", prompt);
print!("{}", prompt);
}
Some('\u{0008}') => {
print!("\u{08}");

View File

@ -8,6 +8,7 @@ const CURSOR_COLOR: Color16 = Color16::Cyan;
#[derive(Debug)]
pub struct Term {
dirty: bool,
color: Color16,
term: [(char, Color16); 80 * 60],
x: u8,
}
@ -21,6 +22,7 @@ impl Term {
dirty: false,
x: 0,
term: [('\0', Color16::LightGrey); 80 * 60],
color: Color16::White,
}
}
pub fn is_dirty(&self) -> bool {
@ -32,70 +34,38 @@ impl Term {
}
pub fn print(&mut self, data: &str) {
for c in data.chars() {
if self.x == 79 {
self.move_up();
return;
}
let mut lex = Token::lexer(data);
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 {
match toke {
Token::Error =>
// unsafe { asm!("int 54") },
{}
Token::TBlack => color = Color16::Black,
Token::TBlue => {
color = Color16::Blue;
trace!("");
Token::Reset => {
self.color = Color16::White;
}
Token::Error => {}
Token::TBlack => self.color = Color16::Black,
Token::TBlue => self.color = Color16::Blue,
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) => {
for c in st.chars() {
if self.x == 79 {
if self.x == 80 {
self.move_up();
return;
}
match c {
@ -115,7 +85,8 @@ impl Term {
}
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;
}
}
@ -144,29 +115,6 @@ impl Term {
use Color16::*;
let mode = VGAE.lock();
mode.clear_screen(DarkGrey);
let mouse_coord = x86_64::instructions::interrupts::without_interrupts(|| {
let cursor = MOUSE.lock();
(cursor.get_x() as usize, cursor.get_y() as usize)
});
mode.draw_line(
(mouse_coord.0 as isize + 0, mouse_coord.1 as isize + 0),
(mouse_coord.0 as isize + 10, mouse_coord.1 as isize + 10),
CURSOR_COLOR,
);
mode.draw_line(
(mouse_coord.0 as isize + 0, mouse_coord.1 as isize + 0),
(mouse_coord.0 as isize + 5, mouse_coord.1 as isize + 0),
CURSOR_COLOR,
);
mode.draw_line(
(mouse_coord.0 as isize + 0, mouse_coord.1 as isize + 0),
(mouse_coord.0 as isize + 0, mouse_coord.1 as isize + 5),
CURSOR_COLOR,
);
let mut x = 0;
let mut y = 0;
@ -180,6 +128,30 @@ impl Term {
}
}
{
let mouse_coord = x86_64::instructions::interrupts::without_interrupts(|| {
let cursor = MOUSE.lock();
(cursor.get_x() as usize, cursor.get_y() as usize)
});
mode.draw_line(
(mouse_coord.0 as isize + 0, mouse_coord.1 as isize + 0),
(mouse_coord.0 as isize + 10, mouse_coord.1 as isize + 10),
CURSOR_COLOR,
);
mode.draw_line(
(mouse_coord.0 as isize + 0, mouse_coord.1 as isize + 0),
(mouse_coord.0 as isize + 5, mouse_coord.1 as isize + 0),
CURSOR_COLOR,
);
mode.draw_line(
(mouse_coord.0 as isize + 0, mouse_coord.1 as isize + 0),
(mouse_coord.0 as isize + 0, mouse_coord.1 as isize + 5),
CURSOR_COLOR,
);
}
self.set_dirty(false);
trace!("Finished drawing");
}
@ -188,72 +160,53 @@ impl Term {
#[derive(Logos, Debug, Clone, PartialEq)]
pub enum Token {
#[regex(r"[\t\n\f]+", logos::skip)]
#[regex(r"", logos::skip)]
#[error]
Error,
#[token("$BLACK$")]
#[token("\0RESET\0", priority = 10)]
Reset,
#[token("\0BLACK\0", priority = 10)]
TBlack,
#[token("$BLUE$")]
#[regex("\0BLUE\0", priority = 10)]
TBlue,
#[token("$GREEN$")]
#[token("\0GREEN\0", priority = 10)]
TGreen,
#[token("$CYAN$")]
#[token("\0CYAN\0", priority = 10)]
TCyan,
#[token("$RED$")]
#[token("\0RED\0", priority = 10)]
TRed,
#[token("$MAGENTA$")]
#[token("\0MAGENTA\0", priority = 10)]
TMagenta,
#[token("$BROWN$")]
#[token("\0BROWN\0", priority = 10)]
TBrown,
#[token("$LIGHTGREY$")]
#[token("\0LIGHTGREY\0", priority = 10)]
TLightGrey,
#[token("$DARKGREY$")]
#[token("\0DARKGREY\0", priority = 10)]
TDarkGrey,
#[token("$LIGHTBLUE$")]
#[token("\0LIGHTBLUE\0", priority = 10)]
TLightBlue,
#[token("$LIGHTGREEN$")]
#[token("\0LIGHTGREEN\0", priority = 10)]
TLightGreen,
#[token("$LIGHTCYAN$")]
#[token("\0LIGHTCYAN\0", priority = 10)]
TLightCyan,
#[token("$LIGHTRED$")]
#[token("\0LIGHTRED\0", priority = 10)]
TLightRed,
#[token("$PINK$")]
#[token("\0PINK\0", priority = 10)]
TPink,
#[token("$YELLOW$")]
#[token("\0YELLOW\0", priority = 10)]
TYellow,
#[token("$WHITE$")]
#[token("\0WHITE\0", priority = 10)]
TWhite,
#[regex("/[\x00-\x7F]/", text_lex)]
#[token(" ")]
Space,
#[regex("[\t\n!-~]+", text_lex, priority = 0)]
Text(String),
}
fn text_lex(lex: &mut Lexer<Token>) -> String {
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!(),
}
}
}