Typing in terminal is now supported in rust teton.

This commit is contained in:
Drew Galbraith 2024-08-13 19:55:44 -07:00
parent 18e512cf1f
commit f04e720811
15 changed files with 489 additions and 13 deletions

View file

@ -6,4 +6,5 @@ edition = "2021"
[dependencies]
mammoth = { path = "../../lib/mammoth" }
victoriafalls = { path = "../../lib/victoriafalls" }
voyageurs = { path = "../../lib/voyageurs" }
yellowstone = { path = "../../lib/yellowstone" }

View file

@ -4,15 +4,56 @@ use crate::psf::Psf;
pub struct Console {
framebuffer: Framebuffer,
psf: Psf,
row: u32,
col: u32,
}
impl Console {
pub fn new(framebuffer: Framebuffer, psf: Psf) -> Self {
Self { framebuffer, psf }
Self {
framebuffer,
psf,
row: 0,
col: 0,
}
}
pub fn write_char(&self, c: char) {
let glyph = self.psf.glyph(c as u32);
self.framebuffer.draw_glyph(glyph, 0, 0)
fn incr_cursor(&mut self) {
self.col += 1;
if self.col >= self.cols() {
self.col = 0;
self.row += 1;
}
if self.row >= self.rows() {
panic!("Scroll unimplemented")
}
}
pub fn write_char(&mut self, chr: char) {
if chr == '\x08' {
// Backspace.
if self.col > 1 {
self.col -= 1;
self.write_char(' ');
self.col -= 1;
}
return;
}
let glyph = self.psf.glyph(chr as u32);
self.framebuffer.draw_glyph(
glyph,
self.row * (self.psf.height() + 1),
self.col * (self.psf.width() + 1),
);
self.incr_cursor()
}
fn cols(&self) -> u32 {
self.framebuffer.width() / (self.psf.width() + 1)
}
fn rows(&self) -> u32 {
self.framebuffer.height() / (self.psf.height() + 1)
}
}

View file

@ -35,4 +35,12 @@ impl Framebuffer {
}
}
}
pub fn width(&self) -> u32 {
self.fb_info.width as u32
}
pub fn height(&self) -> u32 {
self.fb_info.height as u32
}
}

View file

@ -6,8 +6,13 @@ extern crate alloc;
mod console;
mod framebuffer;
mod psf;
mod terminal;
use core::cell::RefCell;
use alloc::rc::Rc;
use mammoth::{debug, define_entry, zion::z_err_t};
use voyageurs::listener::KeyboardListener;
define_entry!();
@ -33,18 +38,16 @@ extern "C" fn main() -> z_err_t {
.expect("Failed to create framebuffer");
let psf = psf::Psf::new("/default8x16.psfu").expect("Failed to open font file.");
let console = console::Console::new(framebuffer, psf);
let mut console = console::Console::new(framebuffer, psf);
console.write_char('>');
/*
let terminal = Rc::new(RefCell::new(terminal::Terminal::new(console)));
Terminal terminal(console);
terminal.Register();
let kb_listener = KeyboardListener::new(terminal).expect("Failed to create keyboard listener");
Thread lthread = terminal.Listen();
check(lthread.Join());
*/
kb_listener
.join()
.expect("Failed to wait on keyboard listener");
0
}

View file

@ -68,4 +68,12 @@ impl Psf {
let len: usize = self.header.bytes_per_glyph as usize;
&self.file.slice(offset, len)
}
pub fn width(&self) -> u32 {
self.header.width
}
pub fn height(&self) -> u32 {
self.header.height
}
}

View file

@ -0,0 +1,18 @@
use crate::console::Console;
use voyageurs::listener::KeyboardHandler;
pub struct Terminal {
console: Console,
}
impl KeyboardHandler for Terminal {
fn handle_char(&mut self, c: char) {
self.console.write_char(c)
}
}
impl Terminal {
pub fn new(console: Console) -> Self {
Self { console }
}
}