From cd7d3dfb78472ef5e8b0f9b24f30b5473191ff6b Mon Sep 17 00:00:00 2001 From: Eemeli Date: Fri, 16 Feb 2024 01:03:54 +0200 Subject: [PATCH] run hyperion-framebuffer logger in term --- Cargo.lock | 1 + crates/framebuffer/src/logger.rs | 27 +++++++++++-------- userspace/hyperion-term/Cargo.toml | 1 + userspace/hyperion-term/src/main.rs | 40 ++++++++++++++++++++++++----- userspace/hyperion-wm/src/main.rs | 6 ++--- userspace/std-test/Cargo.toml | 4 +-- userspace/std-test/src/main.rs | 36 +++++++++++++++++++++++++- 7 files changed, 92 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d50d728c..81b59d2c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1625,6 +1625,7 @@ name = "term" version = "0.3.0" dependencies = [ "hyperion-color", + "hyperion-framebuffer", "hyperion-syscall", "hyperion-windowing", ] diff --git a/crates/framebuffer/src/logger.rs b/crates/framebuffer/src/logger.rs index 26d6dec65..17a0af7fc 100644 --- a/crates/framebuffer/src/logger.rs +++ b/crates/framebuffer/src/logger.rs @@ -2,7 +2,7 @@ use core::fmt::{self, Arguments, Write}; use hyperion_color::Color; use hyperion_escape::decode::{DecodedPart, EscapeDecoder}; -use spin::{Mutex, MutexGuard}; +use spin::Mutex; use super::{font::FONT, framebuffer::Framebuffer}; @@ -12,16 +12,21 @@ pub fn _print(args: Arguments) { // TODO: without ints // without_interrupts(|| { if let Some(fbo) = Framebuffer::get() { - let fbo = fbo.lock(); - _ = WriterLock { - lock: WRITER.lock(), - fbo, - } - .write_fmt(args) + let mut fbo = fbo.lock(); + _print_to(args, &mut fbo) } // }); } +pub fn _print_to(args: Arguments, fbo: &mut Framebuffer) { + let mut writer = WRITER.lock(); + _ = WriterLock { + lock: &mut writer, + fbo, + } + .write_fmt(args) +} + // static WRITER: Mutex = Mutex::new(Writer::new()); @@ -36,9 +41,9 @@ struct Writer { escapes: EscapeDecoder, } -struct WriterLock { - lock: MutexGuard<'static, Writer>, - fbo: MutexGuard<'static, Framebuffer>, +struct WriterLock<'a> { + lock: &'a mut Writer, + fbo: &'a mut Framebuffer, } // @@ -134,7 +139,7 @@ impl Writer { } } -impl fmt::Write for WriterLock { +impl fmt::Write for WriterLock<'_> { fn write_str(&mut self, s: &str) -> fmt::Result { self.lock.write_bytes(s.as_bytes(), &mut self.fbo); Ok(()) diff --git a/userspace/hyperion-term/Cargo.toml b/userspace/hyperion-term/Cargo.toml index adfb8258d..c47615836 100644 --- a/userspace/hyperion-term/Cargo.toml +++ b/userspace/hyperion-term/Cargo.toml @@ -10,6 +10,7 @@ edition.workspace = true hyperion-syscall.path = "../../crates/syscall" hyperion-color.path = "../../crates/color" hyperion-windowing.path = "../hyperion-windowing" +hyperion-framebuffer.path = "../../crates/framebuffer" [lints] workspace = true diff --git a/userspace/hyperion-term/src/main.rs b/userspace/hyperion-term/src/main.rs index f5bc9e889..0e7708a35 100644 --- a/userspace/hyperion-term/src/main.rs +++ b/userspace/hyperion-term/src/main.rs @@ -1,4 +1,6 @@ -use hyperion_color::Color; +use core::slice; + +use hyperion_framebuffer::framebuffer::{Framebuffer, FramebufferInfo}; use hyperion_syscall::get_pid; use hyperion_windowing::{ client::Connection, @@ -12,12 +14,33 @@ fn main() { let mut window = wm.new_window().unwrap(); - let colors = [Color::RED, Color::GREEN, Color::BLUE]; let mut i = get_pid(); - // let mut t = timestamp().unwrap() as u64; + window.buf_base(); + + let slice = unsafe { + slice::from_raw_parts_mut( + window.buf_base().as_ptr().cast::(), + window.pitch * window.height * 4, + ) + }; + + let mut fbo = Framebuffer::new( + slice, + FramebufferInfo { + width: window.width, + height: window.height, + pitch: window.pitch * 4, + }, + ); + + hyperion_framebuffer::logger::_print_to(format_args!("Hello, world!\n"), &mut fbo); + hyperion_framebuffer::logger::_print_to(format_args!("I am PID:{i}\n"), &mut fbo); + + let mut t = hyperion_syscall::timestamp().unwrap() as u64; loop { - window.fill(colors[i % 3].as_u32()); + // let colors = [Color::RED, Color::GREEN, Color::BLUE]; + // window.fill(colors[i % 3].as_u32()); match wm.next_event() { Event::Keyboard { @@ -28,10 +51,15 @@ fn main() { code: 102 | 103, // down or right state: ElementState::Pressed, } => i = i.wrapping_sub(1), + Event::Text { ch } => { + hyperion_framebuffer::logger::_print_to(format_args!("{ch}"), &mut fbo); + } _ => {} } - // t += 16_666_667; - // nanosleep_until(t); + t += 16_666_667; + hyperion_syscall::nanosleep_until(t); + + // hyperion_syscall::yield_now(); } } diff --git a/userspace/hyperion-wm/src/main.rs b/userspace/hyperion-wm/src/main.rs index 61a2344b3..cb52f1a74 100644 --- a/userspace/hyperion-wm/src/main.rs +++ b/userspace/hyperion-wm/src/main.rs @@ -18,7 +18,7 @@ use std::{ use hyperion_color::Color; use hyperion_syscall::{ fs::{FileDesc, FileOpenFlags}, - get_tid, nanosleep_until, system, timestamp, + get_tid, system, timestamp, }; use hyperion_windowing::{ global::GlobalFb, @@ -174,9 +174,9 @@ fn blitter() { // println!("VSYNC"); next_sync += 16_666_667; - nanosleep_until(next_sync); + hyperion_syscall::nanosleep_until(next_sync); - // yield_now(); + // hyperion_syscall::yield_now(); global_fb.volatile_fill(c_x, c_y, 16, 16, Color::from_hex("#141414").unwrap()); } diff --git a/userspace/std-test/Cargo.toml b/userspace/std-test/Cargo.toml index fcb605d55..6cc4b8f7b 100644 --- a/userspace/std-test/Cargo.toml +++ b/userspace/std-test/Cargo.toml @@ -6,8 +6,8 @@ edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -# tracing = "0.1" -# tracing-subscriber = "0.3" +tracing = "0.1" +tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] } [lints] workspace = true diff --git a/userspace/std-test/src/main.rs b/userspace/std-test/src/main.rs index 78fde9834..f79417e9c 100644 --- a/userspace/std-test/src/main.rs +++ b/userspace/std-test/src/main.rs @@ -1,8 +1,42 @@ -use std::{collections::HashMap, fs::OpenOptions, io::Read, path::Path}; +use std::{ + collections::HashMap, + fs::OpenOptions, + io::{stdin, Read}, + path::Path, +}; // fn main() { + let stdin = stdin(); + + // let mut buf = [0u8; 0]; + // let n = stdin.read(&mut buf).unwrap(); + // let line = std::str::from_utf8(&buf[..n]); + // println!("{line:?}"); + + // let mut buf = [0u8; 0]; + // let n = stdin.read(&mut buf).unwrap(); + // let line = std::str::from_utf8(&buf[..n]); + // println!("{line:?}"); + + // let mut buf = Vec::new(); + // let n = stdin.read_to_end(&mut buf).unwrap(); + // let line = std::str::from_utf8(&buf[..n]); + // println!("{line:?}"); + + // for line in stdin.lines() { + // println!("{line:?}"); + // } + + let mut buf = String::new(); + let n = stdin.read_line(&mut buf).unwrap(); + let line = &buf[..n]; + println!("{line:?}"); + + // tracing_subscriber::fmt::init(); + // tracing::error!("test error"); + let path = Path::new("splash"); let mut file = OpenOptions::new().read(true).open(path).unwrap(); let mut buf = String::new();