diff --git a/copypastes.txt b/copypastes.txt new file mode 100644 index 0000000..cdd29bf --- /dev/null +++ b/copypastes.txt @@ -0,0 +1,4 @@ +never gonna give you up + + + // "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128" diff --git a/rickroll.txt b/rickroll.txt deleted file mode 100644 index ac72c22..0000000 --- a/rickroll.txt +++ /dev/null @@ -1 +0,0 @@ -never gonna give you up diff --git a/src/system/std/application.rs b/src/system/std/application.rs index 9cc0ed9..9c37a2a 100644 --- a/src/system/std/application.rs +++ b/src/system/std/application.rs @@ -1,11 +1,13 @@ use async_trait::async_trait; use alloc::{string::String, vec::Vec, boxed::Box}; +use super::render::Window; + #[async_trait] pub trait Application { fn new() -> Self; - async fn run(&mut self, _: Vec) -> Result<(), Error> { + async fn run(&mut self, _window: Option, _args: Vec) -> Result<(), Error> { Ok(()) } } diff --git a/src/system/std/io.rs b/src/system/std/io.rs index 0b430a8..b8494c1 100644 --- a/src/system/std/io.rs +++ b/src/system/std/io.rs @@ -48,46 +48,10 @@ impl Serial { } } -/// enum with a terminal and application mode -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> { - // Ok(match self { - // Screen::Terminal => RENDERER.lock().terminal_mode(), - // Screen::Application => RENDERER.lock().application_mode(), - // }) - // } - - /// returns the current display mode - pub fn get_mode() -> Screen { - match RENDERER.lock().mode_is_app() { - true => Screen::Application, - false => Screen::Terminal, - } - } - - /// switches between modes - pub fn switch(&self) { - if RENDERER.lock().mode_is_app() == true { - RENDERER.lock().terminal_mode(); - } else { - RENDERER.lock().application_mode(); - } - } - pub fn clear() { - RENDERER.lock().clear(); - } -} - /// 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. +/// this will be deprecated in the near future !! pub struct Display; impl Display { @@ -99,6 +63,10 @@ impl Display { pub fn mv_cursor(&self, x: u8, y: u8) -> Result<(), RenderError> { RENDERER.lock().cursor_position(x, y) } + + pub fn clear() { + RENDERER.lock().clear(); + } } impl Drop for Display { diff --git a/src/system/std/render.rs b/src/system/std/render.rs index 7761dc2..3328d76 100644 --- a/src/system/std/render.rs +++ b/src/system/std/render.rs @@ -21,6 +21,53 @@ pub use crate::system::kernel::render::{ BUFFER_HEIGHT }; +pub struct Window { + width: u32, + height: u32, + x: u32, + y: u32, + bordered: bool, + open: bool, +} + +impl Window { + pub fn new() -> Window { + Window { + width: BUFFER_WIDTH as u32, + height: BUFFER_HEIGHT as u32, + x: 0, + y: 0, + bordered: true, + open: true + } + } + + pub fn open(&mut self) -> Result<(), RenderError> { + if self.open { + return Err(RenderError::InvalidRenderMode); + } + self.open = true; + + let mut frame: [[ScreenChar; BUFFER_WIDTH]; BUFFER_HEIGHT] = [[ScreenChar::null(); BUFFER_WIDTH]; BUFFER_HEIGHT]; + + + Ok(()) + } + + // pub fn render(&self, f: &Frame) -> Result<(), RenderError> { + // let mut frame: &[[ScreenChar; self.width]; self.height] = &[[ScreenChar::null(); self.width]; self.height]; + + + + // for (i, row) in f.frame.iter().enumerate() { + // for (j, col) in row.iter().enumerate() { + // frame[i + f.position.y][j + f.position.x] = col.as_screen_char(); + // }; + // } + // RENDERER.lock().render_frame(frame); + // Ok(()) + // } +} #[derive(Clone, Copy, Debug, PartialEq)] pub struct ColouredChar { @@ -117,6 +164,14 @@ impl Frame { }) } + pub fn from_window(window: &Window) -> Frame { + Frame { + dimensions: Dimensions::new(window.width as usize, window.height as usize), + position: Position::new(window.x as usize, window.y as usize), + frame: vec![vec![ColouredChar::null(); window.width as usize]; window.height as usize], + } + } + pub fn from_str(elemstr: String) -> Self { let mut element = Frame { frame: Vec::>::new(), dimensions: Dimensions::new(0, 0), position: Position::new(0, 0) }; @@ -141,6 +196,7 @@ impl Frame { self.frame.clone() } + /// DEPRECATED. Use Window::render(&Frame) instead !! pub fn write_to_screen(&self) -> Result<(), RenderError> { let mut frame: [[ScreenChar; BUFFER_WIDTH]; BUFFER_HEIGHT] = [[ScreenChar::null(); BUFFER_WIDTH]; BUFFER_HEIGHT]; for (i, row) in self.frame.iter().enumerate() { @@ -151,6 +207,7 @@ impl Frame { RENDERER.lock().render_frame(frame); Ok(()) } + pub fn get_position(&self) -> Position { self.position } diff --git a/src/user/bin/apps/calc/calc.rs b/src/user/bin/apps/calc/calc.rs index 767ce18..4edb46d 100755 --- a/src/user/bin/apps/calc/calc.rs +++ b/src/user/bin/apps/calc/calc.rs @@ -2,6 +2,7 @@ use core::fmt; use alloc::{boxed::Box, format, string::String, vec::Vec}; use alloc::string::ToString; use alloc::borrow::ToOwned; +use crate::std::render::Window; use crate::{println, print, mknode, std, serial_println}; use async_trait::async_trait; @@ -361,7 +362,7 @@ impl Application for Calculator { Self {} } - async fn run(&mut self, args: Vec) -> Result<(), ShellError> { + async fn run(&mut self, window: Option, args: Vec) -> Result<(), ShellError> { if args.len() == 0 { loop { print!("enter equation > "); diff --git a/src/user/bin/apps/editor.rs b/src/user/bin/apps/editor.rs index 9cbc97e..17d8539 100644 --- a/src/user/bin/apps/editor.rs +++ b/src/user/bin/apps/editor.rs @@ -1,7 +1,7 @@ use crate::{serial_println, std}; use crate::std::application::{self, Application}; use crate::std::io::{Color, ColorCode, Display, KeyStroke}; -use crate::std::render::{ColouredChar, Frame, Position, RenderError}; +use crate::std::render::{ColouredChar, Frame, Position, RenderError, Window}; use crate::user::lib::libgui::cg_core::CgComponent; @@ -169,7 +169,7 @@ impl Application for Editor { } } - async fn run(&mut self, _args: Vec) -> Result<(), application::Error> { + async fn run(&mut self, window: Option, _args: Vec) -> Result<(), application::Error> { // if let Some(s) = args.get(0) { // self.buffer = s.lines().map(|l| l.chars().collect()).collect::>>() diff --git a/src/user/bin/apps/grapher.rs b/src/user/bin/apps/grapher.rs index 6f1316e..8830ca5 100644 --- a/src/user/bin/apps/grapher.rs +++ b/src/user/bin/apps/grapher.rs @@ -5,7 +5,7 @@ use alloc::boxed::Box; use core::any::Any; use async_trait::async_trait; use crate::std::application::{Application, Error}; -use crate::std::render::{Frame, Position, Dimensions, ColouredChar, RenderError}; +use crate::std::render::{ColouredChar, Dimensions, Frame, Position, RenderError, Window}; use crate::std::io::{Display, KeyStroke, Stdin}; use crate::user::lib::libgui::{ @@ -49,7 +49,7 @@ impl Application for Grapher { frame: Frame::new(Position::new(1, 1), Dimensions::new(78, 22)).unwrap() } } - async fn run(&mut self, args: Vec) -> Result<(), Error> { + async fn run(&mut self, window: Option, args: Vec) -> Result<(), Error> { let _d = Display::borrow(); self.frame.frame = vec![vec![ColouredChar::new(' '); self.frame.dimensions.x]; self.frame.dimensions.y]; diff --git a/src/user/bin/apps/mod.rs b/src/user/bin/apps/mod.rs index dd51267..a2b3482 100644 --- a/src/user/bin/apps/mod.rs +++ b/src/user/bin/apps/mod.rs @@ -1,4 +1,5 @@ pub mod calc; pub mod editor; pub mod grapher; -pub mod tasks; \ No newline at end of file +pub mod tasks; +pub mod zxqsh; \ No newline at end of file diff --git a/src/user/bin/apps/tasks.rs b/src/user/bin/apps/tasks.rs index 3136e60..06bee49 100644 --- a/src/user/bin/apps/tasks.rs +++ b/src/user/bin/apps/tasks.rs @@ -4,6 +4,7 @@ use crate::std::application::{ Error }; use crate::println; +use crate::std::render::Window; use lazy_static::lazy_static; use spin::Mutex; use async_trait::async_trait; @@ -27,7 +28,7 @@ pub struct Tasks; impl Application for Tasks { fn new() -> Self { Self {} } - async fn run(&mut self, args: Vec) -> Result<(), Error> { + async fn run(&mut self, window: Option, args: Vec) -> Result<(), Error> { if args[0].clone() == String::from("add") { diff --git a/src/user/bin/apps/zxqsh.rs b/src/user/bin/apps/zxqsh.rs new file mode 100644 index 0000000..ae23ccf --- /dev/null +++ b/src/user/bin/apps/zxqsh.rs @@ -0,0 +1,50 @@ +use alloc::{string::String, vec::Vec, boxed::Box}; + +use crate::std::{application::{Application, Error}, render::Window}; + +use async_trait::async_trait; + +pub struct ZxqSH { + history: Vec, + idx: u32, + + window: Window, + +} + +#[async_trait] +impl Application for ZxqSH { + fn new() -> Self { + todo!() + } + + async fn run(&mut self, window: Option, _args: Vec) -> Result<(), Error> { + loop { + if let Ok(exit) = self.next().await { + if exit { return Ok(()) } + } + } + } +} + +impl ZxqSH { + async fn next(&mut self) -> Result { + + // update cycle for the shell + + // TOOD: prompt + + // TODO: exit if necessar + + // TODO: execute command + + // return + + Ok(false) + } + + + async fn execute(&self, command: String) -> Result<(), Error> { + Ok(()) + } +} \ No newline at end of file diff --git a/src/user/bin/games/asteroids.rs b/src/user/bin/games/asteroids.rs index 058455a..7f3448d 100644 --- a/src/user/bin/games/asteroids.rs +++ b/src/user/bin/games/asteroids.rs @@ -1,6 +1,6 @@ use crate::std::application::Error; use crate::std::application::Error::ApplicationError; -use crate::std::render::{ColouredChar, Dimensions, Frame, Position, RenderError}; +use crate::std::render::{ColouredChar, Dimensions, Frame, Position, RenderError, Window}; use crate::std::io::{Color, ColorCode, Display, KeyStroke, Stdin}; use crate::std::random::Random; use crate::system::std::application::Application; @@ -52,7 +52,7 @@ impl Application for Game { timer: GameTimer::new(), } } - async fn run(&mut self, _args: Vec) -> Result<(), Error> { + async fn run(&mut self, window: Option, _args: Vec) -> Result<(), Error> { let _d = Display::borrow(); let mut container_data = diff --git a/src/user/bin/games/connect4.rs b/src/user/bin/games/connect4.rs index 9b6a4e9..08e48c9 100644 --- a/src/user/bin/games/connect4.rs +++ b/src/user/bin/games/connect4.rs @@ -1,7 +1,7 @@ use alloc::{string::String, vec::Vec, boxed::Box}; use async_trait::async_trait; -use crate::{std::{application::{Application, Error}, io::{Color, Display, KeyStroke, Stdin}, random::Random, render::{ColorCode, ColouredChar, Dimensions, Frame, Position, RenderError}, time}, user::lib::libgui::cg_core::CgComponent}; +use crate::{std::{application::{Application, Error}, io::{Color, Display, KeyStroke, Stdin}, random::Random, render::{ColorCode, ColouredChar, Dimensions, Frame, Position, RenderError, Window}, time}, user::lib::libgui::cg_core::CgComponent}; pub struct Game { pub board: [[Cell; 7]; 6], @@ -31,7 +31,7 @@ impl Application for Game { } } - async fn run(&mut self, _: Vec) -> Result<(), Error> { + async fn run(&mut self, window: Option, _: Vec) -> Result<(), Error> { let _display = Display::borrow(); self.get_next_mode().await; diff --git a/src/user/bin/games/gameoflife.rs b/src/user/bin/games/gameoflife.rs index 2f31d8d..edf0310 100644 --- a/src/user/bin/games/gameoflife.rs +++ b/src/user/bin/games/gameoflife.rs @@ -4,7 +4,7 @@ use alloc::vec::Vec; use alloc::boxed::Box; use crate::std::application::{Application, Error}; use async_trait::async_trait; -use crate::std::render::{ColouredChar, Frame, Position, Dimensions, RenderError}; +use crate::std::render::{ColouredChar, Dimensions, Frame, Position, RenderError, Window}; use crate::std::io::{KeyStroke, Stdin, Color, ColorCode, Display}; use crate::std::time::wait; @@ -21,7 +21,7 @@ impl Application for GameOfLife { frame: Frame::new(Position::new(0, 0), Dimensions::new(80, 25)).unwrap() } } - async fn run(&mut self, _args: Vec) -> Result<(), Error> { + async fn run(&mut self, window: Option, _args: Vec) -> Result<(), Error> { // setup: let _d = Display::borrow(); diff --git a/src/user/bin/games/paper_rs/game.rs b/src/user/bin/games/paper_rs/game.rs index 98290d6..74c3a35 100644 --- a/src/user/bin/games/paper_rs/game.rs +++ b/src/user/bin/games/paper_rs/game.rs @@ -8,7 +8,7 @@ use crate::{ self, application::{Application, Error}, io::{Color, ColorCode, Display, KeyStroke, Stdin}, - render::{ColouredChar, Dimensions, Frame, Position, RenderError}, + render::{ColouredChar, Dimensions, Frame, Position, RenderError, Window}, time }, user::lib::libgui::cg_core::CgComponent @@ -49,7 +49,7 @@ impl Application for GameBoard { } } - async fn run(&mut self, _args: Vec) -> Result<(), Error> { + async fn run(&mut self, window: Option, _args: Vec) -> Result<(), Error> { let _display = Display::borrow(); 'outer: loop { diff --git a/src/user/bin/games/pong.rs b/src/user/bin/games/pong.rs index d5d3a54..2038736 100644 --- a/src/user/bin/games/pong.rs +++ b/src/user/bin/games/pong.rs @@ -4,7 +4,7 @@ use alloc::vec::Vec; use core::any::Any; use async_trait::async_trait; use crate::std::application::{Application, Error}; -use crate::std::render::{BUFFER_HEIGHT, BUFFER_WIDTH, ColorCode, ColouredChar, Dimensions, Frame, Position, RenderError}; +use crate::std::render::{ColorCode, ColouredChar, Dimensions, Frame, Position, RenderError, Window, BUFFER_HEIGHT, BUFFER_WIDTH}; use crate::std::io::{Color, Display, KeyStroke, Stdin}; use crate::std::time::Timer; use crate::user::lib::libgui::cg_core::CgComponent; @@ -25,7 +25,7 @@ impl Application for Game { } } - async fn run(&mut self, _: Vec) -> Result<(), Error> { + async fn run(&mut self, window: Option, _: Vec) -> Result<(), Error> { let _d = Display::borrow(); let mut update_time = Timer::new(0.1); diff --git a/src/user/bin/games/snake.rs b/src/user/bin/games/snake.rs index db7ea34..3962f6b 100644 --- a/src/user/bin/games/snake.rs +++ b/src/user/bin/games/snake.rs @@ -4,7 +4,7 @@ use async_trait::async_trait; use crate::std::io::{Color, Display, KeyStroke, Stdin}; use crate::std::time; use crate::std::application::{Application, Error}; -use crate::std::render::{ColouredChar, Dimensions, Frame, RenderError, ColorCode}; +use crate::std::render::{ColorCode, ColouredChar, Dimensions, Frame, RenderError, Window}; use crate::std::random::Random; use crate::system::std::render; use super::super::super::lib::geometry::{Position, Direction}; @@ -45,7 +45,7 @@ impl Application for Game { } } - async fn run(&mut self, args: Vec) -> Result<(), Error> { + async fn run(&mut self, window: Option, args: Vec) -> Result<(), Error> { let _settings = [0, 0, 0]; // ai_count, snake_len, poi_count diff --git a/src/user/bin/shell.rs b/src/user/bin/shell.rs index 1cb0be4..8150f5d 100644 --- a/src/user/bin/shell.rs +++ b/src/user/bin/shell.rs @@ -18,15 +18,9 @@ use crate::{ printerr, println, std::{ - application::{Application, Error, Exit}, - time::{timer}, - io::{Color, write, Screen, Stdin, Serial, KeyStroke, Display}, + application::{Application, Error, Exit}, io::{write, Color, Display, KeyStroke, Serial, Stdin}, render::Window, time::timer }, user::{ - lib::libgui::{ - cg_core::{CgComponent, CgKeyboardCapture}, - cg_widgets::CgDialog, - }, bin::{ apps::{ calc::Calculator, @@ -48,7 +42,10 @@ use crate::{ gigachad_detector::GigachadDetector, rickroll::Rickroll, }, - }, + }, lib::libgui::{ + cg_core::{CgComponent, CgKeyboardCapture}, + cg_widgets::CgDialog, + } }, }; @@ -67,11 +64,13 @@ pub async fn command_handler() { pub async fn eventloop() { println!("running!"); + let window = Window::new(); + let mut fetch = CrystalFetch::new(); let string = String::from(" "); let mut vec: Vec = Vec::new(); vec.push(string); - fetch.run(vec).await.unwrap(); + fetch.run(Some(window), vec).await.unwrap(); CMD.lock().prompt(); @@ -122,29 +121,31 @@ async fn exec() -> Result<(), Error> { } }; + let window = Window::new(); + match cmd.as_str() { "calculate" | "calc" | "solve" => { let mut cmd = Calculator::new(); - cmd.run(args).await?; + cmd.run(Some(window), args).await?; } "games/connect4" => { let mut cmd = Connect4Game::new(); - cmd.run(args).await?; + cmd.run(Some(window), args).await?; } "rickroll" => { let mut cmd = Rickroll::new(); - cmd.run(args).await?; + cmd.run(Some(window), args).await?; } "crystalfetch" => { let mut cmd = CrystalFetch::new(); - cmd.run(args).await?; + cmd.run(Some(window), args).await?; } "tasks" => { let mut cmd = Tasks::new(); - cmd.run(args).await?; + cmd.run(Some(window), args).await?; } "VGA" => { use vga::colors::Color16; @@ -156,21 +157,21 @@ async fn exec() -> Result<(), Error> { mode.draw_line((80, 60), (120, 420), Color16::Cyan); } "graph" => { - Grapher::new().run(args).await?; + Grapher::new().run(Some(window), args).await?; } "games/snake" => { - SnakeGame::new().run(args).await?; + SnakeGame::new().run(Some(window), args).await?; } "games/asteroids" => { let mut asteroid_game = AsteroidsGame::new(); - asteroid_game.run(args).await?; + asteroid_game.run(Some(window), args).await?; } "games/pong" => { - PongGame::new().run(args).await?; + PongGame::new().run(Some(window), args).await?; } "games/paper.rs" => { let mut game = GameBoard::new(); - game.run(args).await?; + game.run(Some(window), args).await?; } "serial" => { let c = Serial::reply_char('e'); @@ -178,7 +179,7 @@ async fn exec() -> Result<(), Error> { } "games/gameoflife" => { let mut game = GameOfLife::new(); - game.run(Vec::new()).await?; + game.run(Some(window), Vec::new()).await?; } "games/tetris" => { // let mut game = TetrisEngine::new(); @@ -187,12 +188,12 @@ async fn exec() -> Result<(), Error> { "gigachad?" => { let mut detector = GigachadDetector::new(); - detector.run(args).await?; + detector.run(Some(window), args).await?; } "editor" => { let mut editor = Editor::new(); - editor.run(args).await?; + editor.run(Some(window), args).await?; } // direct OS functions (not applications) @@ -208,7 +209,7 @@ async fn exec() -> Result<(), Error> { ) } "clear" => { - Screen::clear(); + Display::clear(); // not sure why this code was here but leaving it in case weird bugs happen so i remember to add it back if so //interrupts::without_interrupts(|| {}); } diff --git a/src/user/bin/utils/crystalfetch.rs b/src/user/bin/utils/crystalfetch.rs index 15cbaa2..003ca97 100644 --- a/src/user/bin/utils/crystalfetch.rs +++ b/src/user/bin/utils/crystalfetch.rs @@ -2,9 +2,7 @@ use async_trait::async_trait; use alloc::{boxed::Box, format, string::String, vec::Vec}; use crate::std::{ - os::OS, - io::{Color, write, Screen}, - application::{Application, Error}, + application::{Application, Error}, io::{write, Color, Display}, os::OS, render::Window }; use crate::println; @@ -55,12 +53,15 @@ impl Application for CrystalFetch { Self {} } - async fn run(&mut self, _args: Vec) -> Result<(), Error> { + async fn run(&mut self, window: Option, _args: Vec) -> Result<(), Error> { + + let ds = Display::borrow(); let os = OS.lock().os.clone(); let version = OS.lock().version.clone(); - Screen::clear(); + // clear screen + Display::clear(); let logo_string = ZXQ5_LOGO; let info_string = format!( diff --git a/src/user/bin/utils/gigachad_detector.rs b/src/user/bin/utils/gigachad_detector.rs index fcca659..2f76abf 100644 --- a/src/user/bin/utils/gigachad_detector.rs +++ b/src/user/bin/utils/gigachad_detector.rs @@ -3,10 +3,10 @@ use alloc::{boxed::Box, string::String, vec::Vec}; use crate::{ println, - std::application::{ + std::{application::{ Application, Error, - }, + }, render::Window}, }; const GIGACHAD: [&'static str; 3] = ["fantasypvp", "zxq5", "ZXQ5"]; @@ -19,7 +19,7 @@ impl Application for GigachadDetector { Self {} } - async fn run(&mut self, args: Vec) -> Result<(), Error> { + async fn run(&mut self, window: Option, args: Vec) -> Result<(), Error> { for arg in args { self.detect_gigachad_by_username(&arg) } diff --git a/src/user/bin/utils/rickroll.rs b/src/user/bin/utils/rickroll.rs index 63d564e..d9bf998 100644 --- a/src/user/bin/utils/rickroll.rs +++ b/src/user/bin/utils/rickroll.rs @@ -44,6 +44,7 @@ const RICKROLL2: &str = " `--'"; use crate::println; +use crate::std::render::Window; use alloc::{string::String, boxed::Box, vec::Vec}; @@ -55,7 +56,7 @@ impl Application for Rickroll { Self {} } - async fn run(&mut self, _args: Vec) -> Result<(), Error> { + async fn run(&mut self, window: Option, _args: Vec) -> Result<(), Error> { println!("{}", RICKROLL2); Ok(()) } diff --git a/src/user/lib/mod.rs b/src/user/lib/mod.rs index d95c15e..73020e6 100644 --- a/src/user/lib/mod.rs +++ b/src/user/lib/mod.rs @@ -1,3 +1,4 @@ // pub mod libgui_old_archive; pub mod geometry; pub mod libgui; +pub mod termui; \ No newline at end of file diff --git a/src/user/lib/termui/components.rs b/src/user/lib/termui/components.rs new file mode 100644 index 0000000..5d36870 --- /dev/null +++ b/src/user/lib/termui/components.rs @@ -0,0 +1,6 @@ + + + + + +pub async fn idk() {} \ No newline at end of file diff --git a/src/user/lib/termui/mod.rs b/src/user/lib/termui/mod.rs new file mode 100644 index 0000000..20cf8f7 --- /dev/null +++ b/src/user/lib/termui/mod.rs @@ -0,0 +1 @@ +pub mod components; \ No newline at end of file