beta 1: remove framebuffer crate, replace with own code, small fixes/features added

added some kanji, docs
This commit is contained in:
stjet
2025-03-13 06:48:53 +00:00
parent 3b5c37520e
commit 8c0b85ae9f
75 changed files with 408 additions and 64 deletions

View File

@@ -215,6 +215,8 @@ impl AudioPlayer {
}
}
queue
} else if parts[1].ends_with(".mp3") {
vec![concat_paths(&self.base_directory, parts[1]).unwrap()]
} else {
get_all_files(PathBuf::from(new_path))
};

View File

@@ -138,6 +138,10 @@ impl WindowLike for FileExplorer {
let bytes_len = metadata.len();
instructions.push(DrawInstructions::Text([5, start_y], vec!["nimbus-roman".to_string()], format!("Size: {} mb ({} b)", bytes_len / (1024_u64).pow(2), bytes_len), theme_info.text, theme_info.background, None, None));
start_y += HEIGHT;
if let Ok(elapsed) = metadata.modified().unwrap().elapsed() {
//properly format months, days, hours, minutes, secs instead
instructions.push(DrawInstructions::Text([5, start_y], vec!["nimbus-roman".to_string()], format!("Last Modified: {} minutes ago", elapsed.as_secs() / 60), theme_info.text, theme_info.background, None, None));
}
//todo: other stuff
//
}

View File

@@ -6,7 +6,7 @@ use std::io::{ stdin, stdout, BufReader, BufRead, Write };
use std::process::exit;
use std::env;
use linux_framebuffer::Framebuffer;
use linux::fb::Framebuffer;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
use termion::{ clear, cursor };
@@ -162,7 +162,7 @@ fn init(framebuffer: Framebuffer, framebuffer_info: FramebufferInfo) {
}
fn main() {
let fb = Framebuffer::new("/dev/fb0").unwrap();
let fb = Framebuffer::open("/dev/fb0").unwrap();
let bytes_per_pixel = (fb.var_screen_info.bits_per_pixel as usize) / 8;
let fb_info = FramebufferInfo {
byte_len: (fb.var_screen_info.yres_virtual * fb.fix_screen_info.line_length) as usize,

View File

@@ -213,9 +213,9 @@ impl WindowLike for Malvim {
} else {
//how does this work again? no idea
if old_pos != 0 {
let found_index = current_file.content[current_file.line_pos].chars().rev().skip(current_length - old_pos + 1).position(|c| c == key_press.key);
let found_index = current_file.content[current_file.line_pos].chars().rev().skip(current_length - old_pos).position(|c| c == key_press.key);
if let Some(found_index) = found_index {
old_pos - found_index - 2
old_pos - found_index - 1
} else {
old_pos
}

View File

@@ -3,7 +3,7 @@ use std::vec;
use std::sync::mpsc::{ channel, Receiver, Sender };
use std::thread;
use std::process::{ Child, Stdio };
use std::io::{ BufReader, BufRead, Write };
use std::io::{ Read, Write };
use std::time::Duration;
use std::path::PathBuf;
use std::fmt;
@@ -79,7 +79,8 @@ pub struct Terminal {
current_stdin_input: String,
current_path: String,
running_process: Option<Child>,
pty_outerr_rx: Option<Receiver<String>>,
process_current_line: Vec<u8>, //bytes of line
pty_outerr_rx: Option<Receiver<u8>>,
pty_in_tx: Option<Sender<String>>,
last_command: Option<String>,
}
@@ -126,8 +127,17 @@ impl WindowLike for Terminal {
//update
let mut changed = false;
loop {
if let Ok(line) = self.pty_outerr_rx.as_mut().unwrap().recv_timeout(Duration::from_millis(5)) {
self.lines.push(strip_ansi_escape_codes(line));
if let Ok(ci) = self.pty_outerr_rx.as_mut().unwrap().recv_timeout(Duration::from_millis(5)) {
if char::from(ci) == '\n' {
let pcl_len = self.process_current_line.len();
self.lines.push(strip_ansi_escape_codes(String::from_utf8(self.process_current_line.clone()).unwrap_or("?".repeat(pcl_len))));
self.process_current_line = Vec::new();
} else if char::from(ci) == '\r' {
//for now, ignore
//
} else {
self.process_current_line.push(ci);
}
changed = true;
} else {
break;
@@ -138,6 +148,7 @@ impl WindowLike for Terminal {
//process exited
self.pty_outerr_rx = None;
self.mode = Mode::Input;
self.process_current_line = Vec::new();
changed = true;
} else {
if key_press.key == 'i' {
@@ -160,7 +171,10 @@ impl WindowLike for Terminal {
//enter
let _ = self.pty_in_tx.as_mut().unwrap().send(self.current_stdin_input.clone());
self.mode = Mode::Running;
let pcl_len = self.process_current_line.len();
self.lines.push(strip_ansi_escape_codes(String::from_utf8(self.process_current_line.clone()).unwrap_or("?".repeat(pcl_len))) + &self.current_stdin_input);
self.current_stdin_input = String::new();
self.process_current_line = Vec::new();
} else if key_press.key == '𐘁' {
//backspace
if self.current_stdin_input.len() > 0 {
@@ -285,11 +299,9 @@ impl Terminal {
self.running_process = Some(blocking::Command::new("sh").arg("-c").arg(&self.current_input).current_dir(&self.current_path).stdin(Stdio::piped()).spawn(pts).unwrap());
let (tx1, rx1) = channel();
thread::spawn(move || {
let reader = BufReader::new(pty);
for line in reader.lines() {
//panics too much
if let Ok(line) = line {
tx1.send(line.to_string()).unwrap();
for ci in pty.bytes() {
if let Ok(ci) = ci {
tx1.send(ci).unwrap();
} else {
//the process has exited. dead process = dead pty = os input/output error
break;
@@ -310,6 +322,7 @@ impl Terminal {
});
self.pty_outerr_rx = Some(rx1);
self.pty_in_tx = Some(tx2);
self.process_current_line = Vec::new();
Mode::Running
}
}
@@ -317,18 +330,20 @@ impl Terminal {
fn calc_actual_lines(&mut self) {
self.actual_lines = Vec::new();
let max_chars_per_line = (self.dimensions[0] - PADDING * 2) / MONO_WIDTH as usize;
let end = if self.mode != Mode::Running {
self.lines.len()
let lines_len = self.lines.len();
let end = if self.mode != Mode::Running || self.process_current_line.len() > 0 {
lines_len
} else {
self.lines.len() - 1
lines_len - 1
};
for line_num in 0..=end {
let mut working_line = if line_num == self.lines.len() {
let mut working_line = if line_num >= lines_len {
if self.mode == Mode::Input {
//must_add_current_line will be false
"$ ".to_string() + &self.current_input + ""
} else {
//Mode::Stdin
self.current_stdin_input.clone() + ""
let pcl_len = self.process_current_line.len();
strip_ansi_escape_codes(String::from_utf8(self.process_current_line.clone()).unwrap_or("?".repeat(pcl_len))) + &self.current_stdin_input.clone() + ""
}
} else {
self.lines[line_num].clone()