1
5
mirror of https://github.com/vinc/moros.git synced 2024-06-26 02:47:03 +00:00
moros/src/usr/vga.rs
Vincent Ollivier 72f9baae6c
Refactor editor (#221)
* Replace sys::vga::clear_screen() by csi code

* Replace all remaining calls of vga functions by csi code

* Remove dead code

* Add some guard clauses

* Add TODO on partially implemented CSI codes

* Fix inverted params on cursor position

* Print newline char between lines

* Add a TODO to load a palette via ANSI OSC commands

* Move cursor after clear screen

* Simplify line insert

* Fix old bug when scrolling twice the screen width

* Simplify backspace code

* Disable interrupts when printing in serial

* Refactor status line

* Hide cursor during printing

* Avoid printing status line over saving status

* Use 1-indexed rows and cols in the user interface
2021-07-29 22:28:57 +02:00

50 lines
2.0 KiB
Rust

use crate::{api, sys, usr};
use crate::api::vga::palette;
use alloc::vec;
pub fn main(args: &[&str]) -> usr::shell::ExitCode {
if args.len() == 1 {
println!("Usage: vga <command>");
return usr::shell::ExitCode::CommandError;
}
match args[1] {
"set" => {
if args.len() == 4 && args[2] == "font" {
if let Some(mut file) = sys::fs::File::open(args[3]) {
let mut buf = vec![0; file.size()];
file.read(&mut buf);
if let Ok(font) = api::font::from_bytes(&buf) {
sys::vga::set_font(&font);
} else {
println!("Could not parse font file");
return usr::shell::ExitCode::CommandError;
}
}
} else if args.len() == 4 && args[2] == "palette" {
if let Some(mut file) = sys::fs::File::open(args[3]) {
if let Ok(palette) = palette::from_csv(&file.read_to_string()) {
sys::vga::set_palette(palette);
// TODO: Instead of calling a kernel function we could
// use the following ANSI OSC command to set a palette:
// for (i, r, g, b) in palette.colors {
// print!("\x1b]P{:x}{:x}{:x}{:x}", i, r, g, b);
// }
// And "ESC]R" to reset a palette.
} else {
println!("Could not parse palette file");
return usr::shell::ExitCode::CommandError;
}
}
} else {
println!("Invalid command");
return usr::shell::ExitCode::CommandError;
}
},
_ => {
println!("Invalid command");
return usr::shell::ExitCode::CommandError;
}
}
usr::shell::ExitCode::CommandSuccessful
}