1
0
Fork 0
forked from AbleOS/ableos

colorify integrated into print

This commit is contained in:
Able 2021-12-28 02:56:29 -06:00
parent 914085fdf5
commit 353d759e94
13 changed files with 149 additions and 37 deletions

2
ableos/Cargo.lock generated
View file

@ -59,7 +59,7 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]]
name = "externc-libm"
version = "0.1.0"
source = "git+https://github.com/HaruxOS/externc-libm#597110801cbcbbfb5d4731746d13014494deb39f"
source = "git+https://github.com/HaruxOS/externc-libm#ad2865a706fd46d829550ed4cdfa4126f2c81e19"
dependencies = [
"libm",
]

View file

@ -92,6 +92,10 @@ impl Writer {
self.buffer.chars[row][col].write(blank);
}
}
pub fn backspace(&mut self) {
self.column_position -= 1;
}
}
impl fmt::Write for Writer {
fn write_str(&mut self, s: &str) -> fmt::Result {
@ -102,7 +106,7 @@ impl fmt::Write for Writer {
lazy_static! {
pub static ref WRITER: Mutex<Writer> = Mutex::new(Writer {
column_position: 0,
color_code: ColorCode::new(Color::Green, Color::Black),
color_code: ColorCode::new(Color::White, Color::Black),
buffer: unsafe { &mut *(0xb8000 as *mut Buffer) },
});
}
@ -111,6 +115,8 @@ use core::fmt;
use lazy_static::lazy_static;
use spin::Mutex;
use volatile::Volatile;
use crate::print;
#[macro_export]
macro_rules! kprint {
($($arg:tt)*) => ($crate::arch::drivers::vga::_kprint(format_args!($($arg)*)));

View file

@ -1,7 +1,7 @@
#![allow(clippy::print_literal)]
use {
super::{gdt, interrupts},
crate::{info, println},
crate::info,
};
pub fn init() {
@ -9,6 +9,5 @@ pub fn init() {
interrupts::init_idt();
unsafe { interrupts::PICS.lock().initialize() };
x86_64::instructions::interrupts::enable();
println!("Initialized");
info!("Initialized");
}

View file

@ -1,4 +1,7 @@
use crate::{arch::gdt, print, println};
use crate::{
arch::{drivers::vga::WRITER, gdt},
print, println,
};
use lazy_static::lazy_static;
use pic8259::ChainedPics;
use spin;
@ -81,8 +84,18 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
kind: DecodedKeyKind::Unicode,
value: character,
} => {
print!("{}", char::try_from(character).unwrap());
// serial_print!("{}", character);
match character {
// Backspace
8 => {
WRITER.lock().backspace();
print!(" ");
WRITER.lock().backspace();
}
_ => {
print!("{}", char::try_from(character).unwrap());
}
}
crate::kmain::key_entropy(character.try_into().unwrap());
}
DecodedKey {

View file

@ -1,4 +0,0 @@
#[no_mangle]
extern "C" fn __truncdfsf2(_x: f64) -> f32 {
0.0
}

View file

@ -1,4 +1,7 @@
use crate::arch::drivers::vga::{set_vga_color, Color};
use crate::{
arch::drivers::vga::{set_vga_color, Color},
kprint,
};
pub fn colorify(eval: &str) {
let y = eval.split("$");
@ -56,7 +59,7 @@ pub fn colorify(eval: &str) {
set_vga_color(Color::White, Color::Black);
}
elk => {
print!("{}", elk);
kprint!("{}", elk);
}
}
}

View file

@ -0,0 +1,69 @@
/*
clparse
* A simple command line parser for ableOS
*/
use std::collections::HashMap;
const CURRENT_PATH: &str = "file://test/";
#[derive(Debug)]
struct Command {
root_command: String,
arguments: HashMap<String, String>,
}
impl Command {
pub fn parse(command: String) -> Command {
let split_command = command.split("?");
let mut root = "".to_string();
let mut rootCount = 0;
let mut args = HashMap::<String, String>::new();
for subcommand in split_command {
match rootCount {
0 => root = subcommand.to_string(),
1 => {
for subarg in subcommand.split("&") {
let mut arg1 = "";
let mut arg2 = "";
let mut arg_count = 0;
for arg in subarg.split("=") {
if arg_count == 0 {
arg1 = arg;
} else {
arg2 = arg;
}
arg_count += 1;
}
args.insert(arg1.to_string(), arg2.to_string());
}
}
_ => {}
}
rootCount += 1;
}
Command {
root_command: root,
arguments: args,
}
}
}
fn main() {
let x = Command::parse("ls?path=".to_string());
let y = &x.arguments["path"];
parsePath(y.to_string());
}
fn parsePath(path: String) {
if path.len() == 0 {
println!("EMPTY PATH");
} else {
match &path[..1] {
"@" => println!("PARTIAL PATH: {}{}", CURRENT_PATH, path),
"/" => println!("FULL PATH: {}", path),
_ => {
println!("MALFORMED PATH: {}", path)
}
}
}
}

View file

@ -1,6 +1,7 @@
#![allow(clippy::empty_loop)]
use crate::experiments::absi::colorify;
use crate::log::LOG_STATE;
use {
crate::{
arch::{drivers::graphics::GraphicsBuffer, init, sloop},
@ -31,23 +32,23 @@ lazy_static! {
#[no_mangle]
pub fn kernel_main() -> ! {
init::init();
LOG_STATE.lock().log_to_screen = false;
let mut a_thread = Thread::new();
a_thread.new_task(test_fn);
a_thread.new_task(test_fn);
THREAD_LIST.lock().push(a_thread);
GraphicsBuffer::draw();
GraphicsBuffer::hide_cursor();
GraphicsBuffer::show_cursor();
crate::wasm::evaluate();
println!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
colorify("$PINK$Hi$RED$ from$GREEN$ able");
println!("$PINK$Hi$RED$ from$GREEN$ able!$RESET$");
println!("$RED$hi$RESET$");
// stack_overflow();
// crate::arch::shutdown();

View file

@ -31,7 +31,6 @@ pub mod print;
pub mod log;
pub mod allocator;
pub mod dirty_hacks;
pub mod driver_traits;
pub mod experiments;
pub mod keyboard;
@ -41,6 +40,5 @@ pub mod relib;
pub mod scheduler;
pub mod wasm;
extern crate alloc;
pub extern crate alloc;
pub extern crate externc_libm as libm;

View file

@ -5,6 +5,9 @@ pub trait Log {
fn trace(val: &str);
}
pub struct LogState {
pub log_to_serial: bool,
pub log_to_screen: bool,
pub debug: bool,
pub error: bool,
pub info: bool,
@ -12,36 +15,60 @@ pub struct LogState {
}
lazy_static::lazy_static! {
pub static ref LOG_STATE: LogState = LogState {
pub static ref LOG_STATE: Mutex<LogState> = spin::Mutex::new(LogState {
log_to_screen: true,
log_to_serial: true,
debug: true,
error: true,
info: true,
trace: true,
};
});
}
use crate::serial_print;
use crate::serial_println;
use lliw::{Fg, Reset};
use spin::Mutex;
pub struct ANSISerialLogger;
impl Log for ANSISerialLogger {
fn debug(val: &str) {
serial_print!("[{}Debug{}] {}\n", Fg::Blue, Reset, val);
if LOG_STATE.lock().log_to_serial {
serial_println!("[{}Debug{}] {}", Fg::Blue, Reset, val);
}
if LOG_STATE.lock().log_to_screen {
println!("[$BLUE$Debug$RESET$] {}", val);
}
}
fn error(val: &str) {
serial_print!("[{}Error{}] {}\n", Fg::Red, Reset, val);
if LOG_STATE.lock().log_to_serial {
serial_println!("[{}Error{}] {}", Fg::Red, Reset, val);
}
if LOG_STATE.lock().log_to_screen {
println!("[$RED$Error$RESET$] {}", val);
}
}
fn info(val: &str) {
serial_print!("[{}Info{}] {}\n", Fg::LightWhite, Reset, val);
if LOG_STATE.lock().log_to_serial {
serial_println!("[{}Info{}] {}", Fg::LightWhite, Reset, val);
}
if LOG_STATE.lock().log_to_screen {
println!("[$LIGHTGRAY$Info$RESET$] {}", val);
}
}
fn trace(val: &str) {
serial_print!("[{}Trace{}] {}\n", Fg::Yellow, Reset, val);
if LOG_STATE.lock().log_to_serial {
serial_println!("[{}Trace{}] {}", Fg::Yellow, Reset, val);
}
if LOG_STATE.lock().log_to_screen {
println!("[$YELLOW$Trace$RESET$] {}", val);
}
}
}
#[macro_export]
macro_rules! debug {
($($arg:tt)*) => ({
if $crate::log::LOG_STATE.debug{
if $crate::log::LOG_STATE.lock().debug{
use crate::log::Log;
let _ = &log::ANSISerialLogger::debug(&alloc::format!($($arg)*));
@ -52,7 +79,7 @@ macro_rules! debug {
#[macro_export]
macro_rules! error {
($($arg:tt)*) => ({
if $crate::log::LOG_STATE.error{
if $crate::log::LOG_STATE.lock().error{
use crate::log::Log;
crate::log::ANSISerialLogger::error(&alloc::format!($($arg)*));
}
@ -62,7 +89,7 @@ macro_rules! error {
#[macro_export]
macro_rules! info {
($($arg:tt)*) => ({
if $crate::log::LOG_STATE.info{
if $crate::log::LOG_STATE.lock().info{
use crate::log::Log;
crate::log::ANSISerialLogger::info(&alloc::format!($($arg)*));
}
@ -72,7 +99,7 @@ macro_rules! info {
#[macro_export]
macro_rules! trace {
($($arg:tt)*) => ({
if $crate::log::LOG_STATE.trace{
if $crate::log::LOG_STATE.lock().trace{
use crate::log::Log;
crate::log::ANSISerialLogger::trace(&alloc::format!($($arg)*));
}

View file

@ -16,9 +16,9 @@ impl core::fmt::Write for Stdout {
}
#[cfg(target_arch = "x86_64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
use crate::kprint;
// FIXME: causes issues
kprint!("{}", s);
use crate::experiments::absi::colorify;
colorify(s);
// kprint!("{}", s);
Ok(())
}
#[cfg(target_arch = "riscv64")]

View file

@ -60,7 +60,7 @@ impl Thread {
Some(last_thread) => final_threadid = last_thread.id + 1,
None => {}
}
debug!("New thread with ThreadID: {}", final_threadid);
debug!("New thread with $BLUE$ThreadID$RESET$: {}", final_threadid);
Self {
id: final_threadid,
tasks: vec![],

View file

@ -72,7 +72,7 @@ impl ModuleImportResolver for HostFunctions {
}
pub fn evaluate() {
let wasm_binary = include_bytes!("zig.wasm");
let wasm_binary = include_bytes!("rust.wasm");
// Load wasm binary and prepare it for instantiation.
let module = wasmi::Module::from_buffer(&wasm_binary).expect("failed to load wasm");