Add clear command

This commit is contained in:
Yash Karandikar 2021-09-17 20:50:57 -05:00
parent 9cef3e7732
commit c201ddd35a
Signed by: karx
GPG key ID: A794DA2529474BA5
2 changed files with 20 additions and 3 deletions

View file

@ -1,5 +1,6 @@
use crate::println; use crate::println;
use crate::print; use crate::print;
use crate::vga_buffer::ScreenChar;
use crate::vga_buffer::{change_color, Color}; use crate::vga_buffer::{change_color, Color};
use arrayvec::{ArrayVec, ArrayString}; use arrayvec::{ArrayVec, ArrayString};
@ -14,6 +15,7 @@ pub fn evaluate(command: &str) {
"info" => info, "info" => info,
"echo" => echo, "echo" => echo,
"shutdown" => shutdown, "shutdown" => shutdown,
"clear" => clear,
_ => default _ => default
}; };
selected(&parts[..]); selected(&parts[..]);
@ -67,3 +69,18 @@ fn shutdown(_arguments: &[&str]) {
shutdown_port.write(0x2000); shutdown_port.write(0x2000);
} }
} }
fn clear(_arguments: &[&str]) {
let mut writer = crate::vga_buffer::WRITER.lock();
for row in 0..crate::vga_buffer::BUFFER_HEIGHT {
for col in 0..crate::vga_buffer::BUFFER_WIDTH {
let blank = ScreenChar {
ascii_character: b' ',
color_code: crate::vga_buffer::ColorCode::new(crate::vga_buffer::Color::White, crate::vga_buffer::Color::Black)
};
writer.buffer.chars[row][col].write(blank);
}
}
}

View file

@ -28,10 +28,10 @@ pub enum Color {
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(transparent)] #[repr(transparent)]
struct ColorCode(u8); pub(crate) struct ColorCode(u8);
impl ColorCode { impl ColorCode {
fn new(foreground: Color, background: Color) -> ColorCode { pub fn new(foreground: Color, background: Color) -> ColorCode {
ColorCode((background as u8) << 4 | (foreground as u8)) ColorCode((background as u8) << 4 | (foreground as u8))
} }
} }
@ -40,7 +40,7 @@ impl ColorCode {
#[repr(C)] #[repr(C)]
pub struct ScreenChar { pub struct ScreenChar {
pub ascii_character: u8, pub ascii_character: u8,
color_code: ColorCode pub(crate) color_code: ColorCode
} }
pub(crate) const BUFFER_HEIGHT: usize = 25; pub(crate) const BUFFER_HEIGHT: usize = 25;