- added a new API for switching between terminal and application mode
- removed unneeded imports to reduce the dumb amount of warnings from the compiler - added a bounds check in frame.rs to avoid a panic when a frame tries to render a character out of bounds, instead returning an error
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
|
||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||
use crate::{print, println};
|
||||
use crate::println;
|
||||
use super::gdt;
|
||||
use lazy_static::lazy_static;
|
||||
use spin;
|
||||
@@ -28,7 +28,7 @@ extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFr
|
||||
|
||||
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
||||
|
||||
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
|
||||
use pc_keyboard::{layouts, HandleControl, Keyboard, ScancodeSet1};
|
||||
use spin::Mutex;
|
||||
use x86_64::instructions::port::Port;
|
||||
|
||||
@@ -38,7 +38,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
|
||||
};
|
||||
}
|
||||
|
||||
let mut keyboard = KEYBOARD.lock();
|
||||
let keyboard = KEYBOARD.lock();
|
||||
let mut port = Port::new(0x60);
|
||||
let scancode: u8 = unsafe { port.read() };
|
||||
|
||||
|
||||
@@ -3,12 +3,8 @@ use lazy_static::lazy_static;
|
||||
use spin::Mutex;
|
||||
use volatile::Volatile;
|
||||
|
||||
use alloc::borrow::ToOwned;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
use crate::system::kernel::render::RenderError::InvalidRenderMode;
|
||||
use crate::serial_println;
|
||||
use crate::std::io::Screen;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -137,24 +133,14 @@ impl Renderer {
|
||||
self.internal_render();
|
||||
}
|
||||
|
||||
pub fn application_mode(&mut self) -> Result<(), RenderError> {
|
||||
if self.application_mode {
|
||||
return Err(InvalidRenderMode);
|
||||
} else {
|
||||
self.application_mode = true;
|
||||
self.internal_render();
|
||||
Ok(())
|
||||
}
|
||||
pub fn application_mode(&mut self) {
|
||||
self.application_mode = true;
|
||||
self.internal_render();
|
||||
}
|
||||
|
||||
pub fn terminal_mode(&mut self) -> Result<(), RenderError> {
|
||||
if !self.application_mode {
|
||||
return Err(InvalidRenderMode);
|
||||
} else {
|
||||
self.application_mode = false;
|
||||
self.internal_render();
|
||||
Ok(())
|
||||
}
|
||||
pub fn terminal_mode(&mut self) {
|
||||
self.application_mode = false;
|
||||
self.internal_render();
|
||||
}
|
||||
|
||||
pub fn mode_is_app(&self) -> bool {
|
||||
@@ -210,10 +196,10 @@ impl Renderer {
|
||||
|
||||
pub fn cursor_position(&mut self, x: u8, y: u8) -> Result<(), RenderError> {
|
||||
// check that x and y are within bounds
|
||||
if x >= 80 || x < 0 || y >= 25 || y < 0 {
|
||||
if x >= 80 || y >= 25 {
|
||||
return Err(RenderError::OutOfBounds(
|
||||
x >= 80 || x < 0,
|
||||
y >= 25 || y < 0
|
||||
x >= 80,
|
||||
y >= 25
|
||||
))
|
||||
}
|
||||
self.internal_set_cursor_position(x, y);
|
||||
|
||||
@@ -25,7 +25,6 @@ pub fn _serial_print(args: core::fmt::Arguments) {
|
||||
|
||||
}
|
||||
pub fn serial_reply(chr: char) -> char {
|
||||
use core::fmt::Write;
|
||||
use x86_64::instructions::interrupts;
|
||||
|
||||
let mut chr_return: char = 'X';
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::println;
|
||||
pub fn init() -> Result<(), ()> {
|
||||
Ok(())
|
||||
}
|
||||
@@ -5,7 +5,7 @@ use x86_64::instructions::interrupts;
|
||||
|
||||
use conquer_once::spin::OnceCell;
|
||||
use crossbeam_queue::ArrayQueue;
|
||||
use crate::{println, serial_println};
|
||||
use crate::println;
|
||||
|
||||
use core::{pin::Pin, task::{Poll, Context}};
|
||||
use futures_util::stream::Stream;
|
||||
|
||||
@@ -2,7 +2,7 @@ use alloc::string::String;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
use crate::system::kernel::render::{RENDERER, ScreenChar};
|
||||
use crate::std::io::{Color, Screen};
|
||||
use crate::std::io::Color;
|
||||
|
||||
/// TODO: get a working implementation for CLI apps
|
||||
/// elements can be created using their from_str() method
|
||||
@@ -135,8 +135,12 @@ impl Frame {
|
||||
pub fn dimensions(&self) -> Dimensions {
|
||||
self.dimensions
|
||||
}
|
||||
pub fn write(&mut self, position: Position, char: ColouredChar) {
|
||||
self.frame[position.y][position.x] = char
|
||||
pub fn write(&mut self, position: Position, char: ColouredChar) -> Result<(), RenderError> {
|
||||
if position.x >= self.dimensions.x || position.y >= self.dimensions.y {
|
||||
return Err(RenderError::OutOfBounds(true, true));
|
||||
}
|
||||
self.frame[position.y][position.x] = char;
|
||||
Ok(())
|
||||
}
|
||||
pub fn place_child_element(&mut self, other: &Frame) {
|
||||
for (i, row) in other.frame.iter().enumerate() {
|
||||
|
||||
+26
-4
@@ -48,13 +48,15 @@ pub enum Screen {
|
||||
Terminal,
|
||||
Application,
|
||||
}
|
||||
|
||||
/// DEPRECATED - STOP USING THIS SOON
|
||||
impl Screen {
|
||||
/// mode can be set for the kernel using this method
|
||||
pub fn set_mode(&self) -> Result<(), RenderError> {
|
||||
match self {
|
||||
Ok(match self {
|
||||
Screen::Terminal => RENDERER.lock().terminal_mode(),
|
||||
Screen::Application => RENDERER.lock().application_mode(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// returns the current display mode
|
||||
@@ -68,9 +70,9 @@ impl Screen {
|
||||
/// switches between modes
|
||||
pub fn switch(&self) {
|
||||
if RENDERER.lock().mode_is_app() == true {
|
||||
RENDERER.lock().terminal_mode().unwrap();
|
||||
RENDERER.lock().terminal_mode();
|
||||
} else {
|
||||
RENDERER.lock().application_mode().unwrap();
|
||||
RENDERER.lock().application_mode();
|
||||
}
|
||||
}
|
||||
pub fn clear() {
|
||||
@@ -78,6 +80,26 @@ impl Screen {
|
||||
}
|
||||
}
|
||||
|
||||
/// An interface that tells the kernel what rendering mode to use
|
||||
/// Creating an instance of this struct will enable application rendering mode
|
||||
/// Dropping the instance will return the display to focus on the terminal.
|
||||
pub struct Display;
|
||||
|
||||
impl Display {
|
||||
pub fn borrow() -> Display {
|
||||
RENDERER.lock().application_mode();
|
||||
Display
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Display {
|
||||
fn drop(&mut self) {
|
||||
RENDERER.lock().terminal_mode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! println_log {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use alloc::{string::{String, ToString}, vec::Vec};
|
||||
use core::ops::Index;
|
||||
use rand::{Rng, SeedableRng, rngs::SmallRng, RngCore};
|
||||
use rand::{SeedableRng, rngs::SmallRng, RngCore};
|
||||
use spin::Mutex;
|
||||
use lazy_static::lazy_static;
|
||||
use cmos_rtc::{ReadRTC, Time};
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
use core::time::Duration;
|
||||
use embedded_time::{Clock, Timer};
|
||||
use cmos_rtc::{ReadRTC, Time};
|
||||
use crate::println;
|
||||
use super::super::kernel::interrupts::GLOBALTIMER;
|
||||
use x86_64::instructions::interrupts;
|
||||
|
||||
Reference in New Issue
Block a user