prelim work on VGA

master
able 2022-08-05 01:14:13 -05:00
parent 9b993f3412
commit 558b98a1d8
6 changed files with 78 additions and 25 deletions

5
Cargo.lock generated
View File

@ -726,12 +726,15 @@ dependencies = [
[[package]]
name = "vga"
version = "0.2.7"
source = "git+https://git.ablecorp.us/able/vga.git#9e72fa603927983e359c8a7c56cb110a81eb161e"
source = "git+https://git.ablecorp.us/able/vga.git#fd41943bb05ca90414e84cff3def1ffe72a62efe"
dependencies = [
"ab_glyph",
"bitflags",
"conquer-once",
"font8x8",
"log",
"num-traits",
"spin 0.9.4",
"spinning_top",
"x86_64",
]

View File

@ -144,3 +144,4 @@ x86_64 = "0.14.8"
pc-beeper = { git = "https://github.com/AbleOS/pc-beeper" }
acpi = "4.1.0"
vga = { git = "https://git.ablecorp.us:443/able/vga.git" }
# vga = { path = "../../vga" }

View File

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

View File

@ -52,7 +52,7 @@ impl log::Log for SimpleLogger {
if KERNEL_CONF.logging.log_to_serial {
serial_println!(
"[{}{}{}][{}{}{}][{}{}@{}{}] {}",
"[{}{:05}{}][{}{}{}][{}{}@{}{}] {}",
color.0,
record.level(),
Fg::Reset,

View File

@ -4,7 +4,7 @@ use crate::image::mono_bitmap::bruh;
use crate::systeminfo::{KERNEL_VERSION, RELEASE_TYPE};
use crate::time::fetch_time;
use crate::{
arch::shutdown, filesystem::FILE_SYSTEM, rhai_shell::KEYBUFF, vterm::Term,
arch::shutdown, filesystem::FILE_SYSTEM, rhai_shell::KEYBUFF, vterm::VTerm,
wasm_jumploader::run_program,
};
@ -38,7 +38,7 @@ impl acpi::AcpiHandler for AcpiStruct {
}
}
pub static TERM: Lazy<spin::Mutex<Term>> = Lazy::new(|| spin::Mutex::new(Term::new()));
pub static TERM: Lazy<spin::Mutex<VTerm>> = Lazy::new(|| spin::Mutex::new(VTerm::new()));
#[derive(Debug)]
pub struct Path {
@ -66,6 +66,10 @@ pub fn scratchpad() {
println!("\0RED\0OHNO\0RESET\0");
// for c in 0..144_697 {
// trace!("{:?}", char::from_u32(c));
// }
// bruh();
disable();
@ -82,7 +86,7 @@ pub fn scratchpad() {
,-------. OS: \0BLUE\0AbleOS\0RESET\0
,'\\ _ _`. Host: None
/ \\)_)-)_)-\\ Kernel: \0RED\0AKern-{}-v{}\0RESET\0
: : Uptime: {}
: : Uptime: \0GREEN\0{}\0RESET\0
\\ / Packages: None
\\ / Shell: BuiltinShell
`. ,' Resolution: 640x480
@ -156,7 +160,7 @@ pub fn real_shell() {
}
Some('\u{8}') => {
print!("\u{8}");
trace!("");
buf.pop();
}

View File

@ -1,19 +1,31 @@
/*
* Copyright (c) 2022, Able <able@ablecorp.us>
*
* SPDX-License-Identifier: MPL-2.0
*/
#![deny(missing_docs)]
//! The VTerm is a terminal with nice
use crate::{hardware::MOUSE, vga_e::VGAE};
use ab_glyph::{Font, FontRef, Glyph};
use logos::{Lexer, Logos};
use spin::Lazy;
use vga::{colors::Color16, writers::GraphicsWriter};
const TERM_MINUS_ONE_LINE: usize = 4720;
const CURSOR_COLOR: Color16 = Color16::Cyan;
#[derive(Debug)]
pub struct Term {
/// A VTerm
pub struct VTerm {
dirty: bool,
color: Color16,
term: [(char, Color16); 80 * 60],
back_buffer: [u8; 640 * 480],
x: u8,
}
impl Term {
impl VTerm {
/// Construct a new VTerm
pub fn new() -> Self {
let mode = VGAE.lock();
mode.set_mode();
@ -24,18 +36,21 @@ impl Term {
dirty: false,
x: 0,
back_buffer: [0; 640 * 480],
term: [('\0', Color16::LightGrey); 80 * 60],
term: [('\0', Color16::DarkGrey); 80 * 60],
color: Color16::White,
}
}
/// Check the dirty state of the VTerm
pub fn is_dirty(&self) -> bool {
self.dirty
}
/// Set the dirty state of the VTerm
pub fn set_dirty(&mut self, dirty: bool) {
self.dirty = dirty
}
/// Append a &str to the VTerm
pub fn print(&mut self, data: &str) {
let mut lex = Token::lexer(data);
@ -61,23 +76,29 @@ impl Term {
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::Space => {
// self.term[TERM_MINUS_ONE_LINE + (self.x as usize)] = (' ', self.color);
// self.x += 1;
// }
Token::Text(st) => {
for c in st.chars() {
if self.x == 80 {
// trace!("X too big moving up");
self.move_up();
}
// trace!("C");
match c {
'\0' => {
self.term[TERM_MINUS_ONE_LINE + (self.x as usize)] =
(c, self.color);
self.x += 1;
}
'\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);
@ -99,19 +120,16 @@ impl Term {
}
}
/// Move the VTerm up by one line
pub fn move_up(&mut self) {
self.term.rotate_left(80);
for x in 0..80 {
self.term[TERM_MINUS_ONE_LINE + x] = ('\0', Color16::LightGrey);
self.term[TERM_MINUS_ONE_LINE + x] = ('\0', Color16::DarkGrey);
}
self.x = 0;
}
// pub fn initialize(&self) {
// let mode = VGAE.lock();
// mode.set_mode();
// drop(mode);
// }
/// Redraw the VTerm to the VGA buffer
pub fn draw_term(&mut self) {
if self.is_dirty() {
// trace!("Redrawing");
@ -123,8 +141,10 @@ impl Term {
for c in self.term {
mode.draw_character(x * 8, y * 8, c.0, c.1);
// mode.draw_unicode_char(x, y, c.0, c.1);
if x == 79 {
y += 1;
x = 0;
} else {
x += 1
@ -155,6 +175,30 @@ impl Term {
);
}
drop(mode);
/*
let mut x = 0;
let mut y = 0;
for c in ['b'; 80 * 60]
// "abcdefghijklmnopqrstuvwxyzabcdefghijk\nabcd jkjhgkjhgkjhgefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz12"
// .chars()
{
if c == '\n' {
y += 1;
x = 0;
continue;
}
self.draw_char(x, y, c, Color16::Red);
if x == 80 {
y += 1;
x = 1;
} else {
x += 1;
}
}
*/
self.set_dirty(false);
// trace!("Finished drawing");
}
@ -162,7 +206,7 @@ impl Term {
}
#[derive(Logos, Debug, Clone, PartialEq)]
pub enum Token {
enum Token {
#[regex(r"", logos::skip)]
#[error]
Error,
@ -203,10 +247,11 @@ pub enum Token {
#[token("\0WHITE\0", priority = 10)]
TWhite,
#[token(" ")]
Space,
// #[token(" ")]
#[regex("[\t\n\u{8}█!-~]+", text_lex, priority = 0)]
// Space,
#[regex("[\t\n\u{8}█!-\u{10FFFF} ]+", text_lex, priority = 0)]
/// A printable string
Text(String),
}