From f804ad52e4a18616cb8311569bc097e7c96b4ba9 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 29 Sep 2016 12:25:43 -0600 Subject: [PATCH] Automatically get size of terminal --- Makefile | 9 +++++++-- drivers/vesad/src/main.rs | 19 +++++++++++++++++++ programs/login/src/main.rs | 14 +++++++++++--- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 1e25875..cefe29b 100644 --- a/Makefile +++ b/Makefile @@ -64,6 +64,11 @@ else ifneq ($(kvm),no) QEMUFLAGS+=-enable-kvm -cpu host endif + ifeq ($(storage),usb) + QEMUFLAGS+=-device usb-ehci,id=flash_bus -drive id=flash_drive,file=$(KBUILD)/harddrive.bin,format=raw,if=none -device usb-storage,drive=flash_drive,bus=flash_bus.0 + else + QEMUFLAGS+=-device ahci,id=ahci -drive id=disk,file=$(KBUILD)/harddrive.bin,format=raw,if=none -device ide-hd,drive=disk,bus=ahci.0 + endif ifeq ($(vga),no) QEMUFLAGS+=-nographic -vga none endif @@ -82,10 +87,10 @@ $(KBUILD)/harddrive.bin: $(KBUILD)/kernel $(BUILD)/filesystem.bin bootloader/$(A nasm -f bin -o $@ -D ARCH_$(ARCH) -ibootloader/$(ARCH)/ bootloader/$(ARCH)/harddrive.asm qemu: $(KBUILD)/harddrive.bin - $(QEMU) $(QEMUFLAGS) -drive file=$<,format=raw,index=0,media=disk + $(QEMU) $(QEMUFLAGS) qemu_no_build: - $(QEMU) $(QEMUFLAGS) -drive file=$(KBUILD)/harddrive.bin,format=raw,index=0,media=disk + $(QEMU) $(QEMUFLAGS) endif bochs: $(KBUILD)/harddrive.bin diff --git a/drivers/vesad/src/main.rs b/drivers/vesad/src/main.rs index 31cb84c..31f6e54 100644 --- a/drivers/vesad/src/main.rs +++ b/drivers/vesad/src/main.rs @@ -113,6 +113,25 @@ impl Scheme for DisplayScheme { } } + fn fpath(&self, id: usize, buf: &mut [u8]) -> Result { + let path_str = if id == 1 { + format!("display:input") + } else { + let console = self.console.borrow(); + format!("display:{}/{}", console.w, console.h) + }; + + let path = path_str.as_bytes(); + + let mut i = 0; + while i < buf.len() && i < path.len() { + buf[i] = path[i]; + i += 1; + } + + Ok(i) + } + fn close(&self, _id: usize) -> Result { Ok(0) } diff --git a/programs/login/src/main.rs b/programs/login/src/main.rs index 156c04e..5865c14 100644 --- a/programs/login/src/main.rs +++ b/programs/login/src/main.rs @@ -9,7 +9,7 @@ use octavo::octavo_digest::sha3::Sha512; use std::fs::File; use std::io::{Read, Write}; use std::process::Command; -use std::{env, io, thread}; +use std::{env, io, str, thread}; use termion::input::TermRead; pub struct Passwd<'a> { @@ -61,9 +61,17 @@ pub fn main() { env::set_current_dir("file:").unwrap(); - env::set_var("COLUMNS", "80"); - env::set_var("LINES", "30"); env::set_var("TTY", &tty); + { + let mut path = [0; 4096]; + if let Ok(count) = syscall::fpath(0, &mut path) { + let path_str = str::from_utf8(&path[..count]).unwrap_or(""); + let reference = path_str.split(':').nth(1).unwrap_or(""); + let mut parts = reference.split('/'); + env::set_var("COLUMNS", parts.next().unwrap_or("80")); + env::set_var("LINES", parts.next().unwrap_or("30")); + } + } thread::spawn(move || { let stdin = io::stdin();