Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor editor #221

Merged
merged 18 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 0 additions & 67 deletions src/sys/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,73 +32,6 @@ pub fn has_cursor() -> bool {
cfg!(feature = "video")
}

pub fn clear_row_after(x: usize) {
if cfg!(feature = "video") {
sys::vga::clear_row_after(x);
} else {
sys::serial::print_fmt(format_args!("\r")); // Move cursor to begining of line
sys::serial::print_fmt(format_args!("\x1b[{}C", x)); // Move cursor forward to position
sys::serial::print_fmt(format_args!("\x1b[K")); // Clear line after position
}
}

pub fn clear_row() {
clear_row_after(0);
}

pub fn clear_screen() {
if cfg!(feature = "video") {
sys::vga::clear_screen();
} else {
sys::serial::print_fmt(format_args!("\x1b[2J"));
}
}

pub fn cursor_position() -> (usize, usize) {
if cfg!(feature = "video") {
sys::vga::cursor_position()
} else {
sys::serial::print_fmt(format_args!("\x1b[6n")); // Ask cursor position
get_char(); // ESC
get_char(); // [
let mut x = String::new();
let mut y = String::new();
loop {
let c = get_char();
if c == ';' {
break;
} else {
y.push(c);
}
}
loop {
let c = get_char();
if c == 'R' {
break;
} else {
x.push(c);
}
}
(x.parse().unwrap_or(1), y.parse().unwrap_or(1))
}
}

pub fn set_cursor_position(x: usize, y: usize) {
if cfg!(feature = "video") {
sys::vga::set_cursor_position(x, y);
} else {
sys::serial::print_fmt(format_args!("\x1b[{};{}H", y + 1, x + 1));
}
}

pub fn set_writer_position(x: usize, y: usize) {
if cfg!(feature = "video") {
sys::vga::set_writer_position(x, y);
} else {
sys::serial::print_fmt(format_args!("\x1b[{};{}H", y + 1, x + 1));
}
}

pub fn disable_echo() {
let mut echo = ECHO.lock();
*echo = false;
Expand Down
5 changes: 4 additions & 1 deletion src/sys/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use core::fmt::Write;
use lazy_static::lazy_static;
use spin::Mutex;
use uart_16550::SerialPort;
use x86_64::instructions::interrupts;

lazy_static! {
pub static ref SERIAL: Mutex<Serial> = Mutex::new(Serial::new(0x3F8));
Expand Down Expand Up @@ -36,7 +37,9 @@ impl fmt::Write for Serial {

#[doc(hidden)]
pub fn print_fmt(args: fmt::Arguments) {
SERIAL.lock().write_fmt(args).expect("Could not print to serial");
interrupts::without_interrupts(|| {
SERIAL.lock().write_fmt(args).expect("Could not print to serial");
})
}

pub fn init() {
Expand Down
Loading