mirror of https://github.com/vinc/moros.git
Add env vars to customize screen size (#585)
This commit is contained in:
parent
fa1fbcd29c
commit
d9e3702df0
|
@ -1,4 +1,6 @@
|
|||
use crate::sys;
|
||||
|
||||
use alloc::string::ToString;
|
||||
use core::fmt;
|
||||
|
||||
pub use crate::sys::console::{EOT_KEY, ETX_KEY};
|
||||
|
@ -105,3 +107,15 @@ pub fn is_printable(c: char) -> bool {
|
|||
true // TODO
|
||||
}
|
||||
}
|
||||
|
||||
// The size of the screen in VGA Text Mode is 80x25
|
||||
|
||||
pub fn cols() -> usize {
|
||||
let n = 80; // chars
|
||||
sys::process::env("COLS").unwrap_or(n.to_string()).parse().unwrap_or(n)
|
||||
}
|
||||
|
||||
pub fn rows() -> usize {
|
||||
let n = 25; // lines
|
||||
sys::process::env("ROWS").unwrap_or(n.to_string()).parse().unwrap_or(n)
|
||||
}
|
||||
|
|
|
@ -59,22 +59,6 @@ impl FileIO for Console {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn cols() -> usize {
|
||||
if cfg!(feature = "video") {
|
||||
sys::vga::cols()
|
||||
} else {
|
||||
80
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rows() -> usize {
|
||||
if cfg!(feature = "video") {
|
||||
sys::vga::rows()
|
||||
} else {
|
||||
25
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_cursor() -> bool {
|
||||
cfg!(feature = "video")
|
||||
}
|
||||
|
|
|
@ -457,14 +457,6 @@ pub fn print_fmt(args: fmt::Arguments) {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn cols() -> usize {
|
||||
BUFFER_WIDTH
|
||||
}
|
||||
|
||||
pub fn rows() -> usize {
|
||||
BUFFER_HEIGHT
|
||||
}
|
||||
|
||||
pub fn color() -> (Color, Color) {
|
||||
interrupts::without_interrupts(||
|
||||
WRITER.lock().color()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::api::console::Style;
|
||||
use crate::api::process::ExitCode;
|
||||
use crate::api::{console, fs, io};
|
||||
use crate::sys;
|
||||
use crate::api;
|
||||
|
||||
use alloc::format;
|
||||
use alloc::string::{String, ToString};
|
||||
|
@ -581,11 +581,11 @@ impl Editor {
|
|||
}
|
||||
|
||||
fn rows(&self) -> usize {
|
||||
sys::console::rows() - 1 // Leave out one line for status line
|
||||
api::console::rows() - 1 // Leave out one line for status line
|
||||
}
|
||||
|
||||
fn cols(&self) -> usize {
|
||||
sys::console::cols()
|
||||
api::console::cols()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::{api, sys};
|
||||
use crate::api::console::Style;
|
||||
use crate::api::fs;
|
||||
use crate::api::process::ExitCode;
|
||||
use crate::api::random;
|
||||
use crate::sys;
|
||||
use crate::sys::console;
|
||||
|
||||
use alloc::collections::BTreeSet;
|
||||
|
@ -13,8 +13,8 @@ use alloc::vec::Vec;
|
|||
use core::fmt;
|
||||
|
||||
struct Game {
|
||||
cols: i64,
|
||||
rows: i64,
|
||||
cols: usize,
|
||||
rows: usize,
|
||||
grid: BTreeSet<(i64, i64)>,
|
||||
step: usize,
|
||||
speed: f64,
|
||||
|
@ -24,7 +24,7 @@ struct Game {
|
|||
}
|
||||
|
||||
impl Game {
|
||||
pub fn new(cols: i64, rows: i64) -> Self {
|
||||
pub fn new(cols: usize, rows: usize) -> Self {
|
||||
Self {
|
||||
cols,
|
||||
rows,
|
||||
|
@ -74,7 +74,7 @@ impl Game {
|
|||
let mut cells_to_remove = vec![];
|
||||
for x in 0..self.cols {
|
||||
for y in 0..self.rows {
|
||||
let cell = (x, y);
|
||||
let cell = (x as i64, y as i64);
|
||||
let n = neighboors(&cell).iter().fold(0, |s, c|
|
||||
s + self.grid.contains(c) as u8
|
||||
);
|
||||
|
@ -144,7 +144,7 @@ impl fmt::Display for Game {
|
|||
let mut out = String::new();
|
||||
for y in 0..self.rows {
|
||||
for x in 0..self.cols {
|
||||
out.push(if self.grid.contains(&(x, y)) {
|
||||
out.push(if self.grid.contains(&(x as i64, y as i64)) {
|
||||
'#'
|
||||
} else {
|
||||
' '
|
||||
|
@ -170,7 +170,7 @@ impl fmt::Display for Game {
|
|||
}
|
||||
|
||||
pub fn main(args: &[&str]) -> Result<(), ExitCode> {
|
||||
let mut game = Game::new(80, 24);
|
||||
let mut game = Game::new(api::console::cols(), api::console::rows() - 1);
|
||||
let mut i = 0;
|
||||
let n = args.len();
|
||||
while i < n {
|
||||
|
|
Loading…
Reference in New Issue