Skip to content

Commit

Permalink
WIP: Terminal: Implement status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
fruhland committed Feb 28, 2024
1 parent 4a9f951 commit 6a53b4d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
37 changes: 24 additions & 13 deletions os/kernel/src/device/lfb_terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct Character {

impl CursorState {
pub const fn new() -> Self {
Self { pos: (0, 0), saved_pos: (0, 0) }
Self { pos: (0, 1), saved_pos: (0, 1) }
}
}

Expand Down Expand Up @@ -117,7 +117,7 @@ impl CursorThread {
self.visible = !self.visible;

if sleep_counter >= 1000 {
LFBTerminal::print_time(&mut display);
LFBTerminal::draw_status_bar(&mut display);
sleep_counter = 0;
}
}
Expand Down Expand Up @@ -241,7 +241,13 @@ impl LFBTerminal {
&& display.lfb.direct_lfb().draw_char(pos.0 as u32 * lfb::CHAR_WIDTH, pos.1 as u32 * lfb::CHAR_HEIGHT, color.fg_color, color.bg_color, c)
}

fn print_time(display: &mut DisplayState) {
fn draw_status_bar(display: &mut DisplayState) {
for i in 0..display.size.0 as u32 * lfb::CHAR_WIDTH {
for j in 0..lfb::CHAR_HEIGHT {
display.lfb.lfb().draw_pixel(i, j, color::WHITE);
}
}

if let Some(efi_system_table) = efi_system_table() {
let system_table = efi_system_table.read();
let runtime_services = unsafe { system_table.runtime_services() };
Expand All @@ -252,11 +258,12 @@ impl LFBTerminal {

for c in date_str.chars().enumerate() {
let pos = (str_pos + c.0 as u16, 0u16);
display.lfb.lfb().draw_char(pos.0 as u32 * lfb::CHAR_WIDTH, pos.1 as u32 * lfb::CHAR_HEIGHT, color::WHITE, color::HHU_BLUE, c.1);
display.lfb.direct_lfb().draw_char(pos.0 as u32 * lfb::CHAR_WIDTH, pos.1 as u32 * lfb::CHAR_HEIGHT, color::WHITE, color::HHU_BLUE, c.1);
display.lfb.lfb().draw_char(pos.0 as u32 * lfb::CHAR_WIDTH, pos.1 as u32 * lfb::CHAR_HEIGHT, color::HHU_BLUE, color::WHITE, c.1);
}
}
}

display.lfb.flush_lines(0, lfb::CHAR_HEIGHT);
}

fn scroll_up(display: &mut DisplayState, color: &mut ColorState) {
Expand All @@ -277,12 +284,16 @@ impl LFBTerminal {
display.lfb.lfb().scroll_up(lfb::CHAR_HEIGHT);
display.lfb.lfb().fill_rect(0, (size.1 - 1) as u32 * lfb::CHAR_HEIGHT, size.0 as u32 * lfb::CHAR_WIDTH, lfb::CHAR_HEIGHT, color.bg_color);

LFBTerminal::print_time(display);
LFBTerminal::draw_status_bar(display);
display.lfb.flush();
}

fn position(display: &mut DisplayState, cursor: &mut CursorState, color: &mut ColorState, pos: (u16, u16)) {
cursor.pos = pos;
if pos.1 == 0 {
cursor.pos = (pos.0, 1);
} else {
cursor.pos = pos
}

while cursor.pos.1 >= display.size.1 {
cursor.pos.1 -= 1;
Expand Down Expand Up @@ -316,7 +327,7 @@ impl LFBTerminal {
item.bg_color = color.bg_color;
});

LFBTerminal::print_time(display);
LFBTerminal::draw_status_bar(display);
display.lfb.flush();
}

Expand All @@ -339,7 +350,7 @@ impl LFBTerminal {
item.1.bg_color = color.bg_color;
});

LFBTerminal::print_time(display);
LFBTerminal::draw_status_bar(display);
display.lfb.flush();
}

Expand All @@ -361,7 +372,7 @@ impl LFBTerminal {
item.bg_color = color.bg_color;
});

LFBTerminal::print_time(display);
LFBTerminal::draw_status_bar(display);
display.lfb.flush();
}

Expand All @@ -381,7 +392,7 @@ impl LFBTerminal {
});

if pos.1 == 0 {
LFBTerminal::print_time(display);
LFBTerminal::draw_status_bar(display);
}
display.lfb.flush();
}
Expand All @@ -403,7 +414,7 @@ impl LFBTerminal {
});

if pos.1 == 0 {
LFBTerminal::print_time(display);
LFBTerminal::draw_status_bar(display);
}
display.lfb.flush();
}
Expand All @@ -425,7 +436,7 @@ impl LFBTerminal {
});

if pos.1 == 0 {
LFBTerminal::print_time(display);
LFBTerminal::draw_status_bar(display);
}
display.lfb.flush();
}
Expand Down
4 changes: 3 additions & 1 deletion os/kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ pub fn init_serial_port() {
}

pub fn init_terminal(buffer: *mut u8, pitch: u32, width: u32, height: u32, bpp: u8) {
TERMINAL.call_once(|| LFBTerminal::new(buffer, pitch, width, height, bpp));
let terminal = LFBTerminal::new(buffer, pitch, width, height, bpp);
terminal.clear();
TERMINAL.call_once(|| terminal);

scheduler().ready(Thread::new_kernel_thread(Box::new(|| {
let mut cursor_thread = CursorThread::new(&TERMINAL.get().unwrap());
Expand Down
10 changes: 9 additions & 1 deletion os/library/graphic/src/buffered_lfb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ impl BufferedLFB {
&mut self.target_lfb
}

pub fn flush_lines(&mut self, start: u32, count: u32) {
let offset = (self.lfb.pitch() * start) as isize;
let bytes = (self.lfb().pitch() * count) as usize;

unsafe { self.target_lfb.buffer().offset(offset).copy_from(self.buffer.as_ptr().offset(offset), bytes); }
}

pub fn flush(&mut self) {
unsafe { self.target_lfb.buffer().copy_from(self.buffer.as_ptr(), (self.lfb.height() * self.lfb.pitch()) as usize); }
self.flush_lines(0, self.lfb.height());
// unsafe { self.target_lfb.buffer().copy_from(self.buffer.as_ptr(), (self.lfb.height() * self.lfb.pitch()) as usize); }
}
}

0 comments on commit 6a53b4d

Please sign in to comment.