Skip to content

Commit

Permalink
run hyperion-framebuffer logger in term
Browse files Browse the repository at this point in the history
  • Loading branch information
xor-bits committed Feb 15, 2024
1 parent 1e5b374 commit cd7d3df
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 16 additions & 11 deletions crates/framebuffer/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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<Writer> = Mutex::new(Writer::new());
Expand All @@ -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,
}

//
Expand Down Expand Up @@ -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(())
Expand Down
1 change: 1 addition & 0 deletions userspace/hyperion-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 34 additions & 6 deletions userspace/hyperion-term/src/main.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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::<u8>(),
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 {
Expand All @@ -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();
}
}
6 changes: 3 additions & 3 deletions userspace/hyperion-wm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions userspace/std-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 35 additions & 1 deletion userspace/std-test/src/main.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down

0 comments on commit cd7d3df

Please sign in to comment.