addressing Martin's corrections

This commit is contained in:
Yehowshua Immanuel 2024-12-27 10:19:09 -05:00
parent fbe0a4f554
commit e4ac219bf9
5 changed files with 37 additions and 31 deletions

1
Cargo.lock generated
View file

@ -1823,6 +1823,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"gloo-file", "gloo-file",
"shared", "shared",
"unicode-segmentation",
"wasm-bindgen-test", "wasm-bindgen-test",
"web-sys", "web-sys",
"wellen", "wellen",

View file

@ -14,6 +14,7 @@ wasm-bindgen-test = "0.3.19"
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(FASTWAVE_PLATFORM)'] } unexpected_cfgs = { level = "allow", check-cfg = ['cfg(FASTWAVE_PLATFORM)'] }
[dependencies] [dependencies]
unicode-segmentation = "1.10"
zoon.workspace = true zoon.workspace = true
wellen.workspace = true wellen.workspace = true
shared = { path = "../shared", features = ["frontend"] } shared = { path = "../shared", features = ["frontend"] }

View file

@ -106,7 +106,6 @@ fn main() {
platform::listen_term_update(|down_msg| { platform::listen_term_update(|down_msg| {
term::TERMINAL_STATE.set(down_msg); term::TERMINAL_STATE.set(down_msg);
}).await; }).await;
zoon::println!("Printing on line 106");
}); });
} }

View file

@ -4,6 +4,7 @@ use chrono::format;
use zoon::*; use zoon::*;
use zoon::{println, eprintln, *}; use zoon::{println, eprintln, *};
use shared::term::{TerminalDownMsg, TerminalScreen, TerminalUpMsg}; use shared::term::{TerminalDownMsg, TerminalScreen, TerminalUpMsg};
use unicode_segmentation::UnicodeSegmentation;
// use tokio::time::timeout; // use tokio::time::timeout;
pub static TERM_OPEN: Lazy<Mutable<bool>> = Lazy::new(|| {false.into()}); pub static TERM_OPEN: Lazy<Mutable<bool>> = Lazy::new(|| {false.into()});
@ -16,7 +17,6 @@ pub static TERMINAL_STATE: Lazy<Mutable<TerminalDownMsg>> =
}); });
pub fn root() -> impl Element { pub fn root() -> impl Element {
term_request();
let terminal = let terminal =
El::new() El::new()
.s(Width::fill()) .s(Width::fill())
@ -61,10 +61,6 @@ pub fn root() -> impl Element {
root root
} }
// TODO : fill this out
fn term_request() {
}
fn send_char( fn send_char(
s : &str, s : &str,
has_control : bool, has_control : bool,
@ -82,18 +78,22 @@ fn send_char(
} }
fn make_grid_with_newlines(term : &TerminalScreen) -> String { fn make_grid_with_newlines(term: &TerminalScreen) -> String {
let mut formatted = String::new(); let mut formatted = String::with_capacity(term.content.len() + (term.content.len() / term.cols as usize));
for (i, c) in term.content.chars().enumerate() {
term.content.chars().enumerate().for_each(|(i, c)| {
formatted.push(c); formatted.push(c);
if ((i + 1) as u16) % term.cols == 0 { if (i + 1) as u16 % term.cols == 0 {
formatted.push('\n'); formatted.push('\n');
} }
} });
formatted formatted
} }
fn process_str(s: &str, has_ctrl : bool) -> Option<char> {
fn process_str(s: &str, has_ctrl: bool) -> Option<char> {
println!("process_str: {s}");
match s { match s {
"Enter" => {return Some('\n');} "Enter" => {return Some('\n');}
"Escape" => {return Some('\x1B');} "Escape" => {return Some('\x1B');}
@ -102,37 +102,40 @@ fn process_str(s: &str, has_ctrl : bool) -> Option<char> {
"ArrowDown" => {return Some('\x0E');} "ArrowDown" => {return Some('\x0E');}
"ArrowLeft" => {return Some('\x02');} "ArrowLeft" => {return Some('\x02');}
"ArrowRight" => {return Some('\x06');} "ArrowRight" => {return Some('\x06');}
"Control" => {return None;}
"Shift" => {return None;}
"Meta" => {return None;}
"Alt" => {return None;}
_ => {} _ => {}
} }
// Check if the string has exactly one character
if s.chars().count() == 1 { let mut graphemes = s.graphemes(true);
// Safe unwrap because we know the length is 1 let first = graphemes.next();
let c = s.chars().next().unwrap();
let c = process_for_ctrl_char(c, has_ctrl); if let Some(g) = first {
return Some(c); if g.len() == 1 {
if let Some(c) = g.chars().next() {
let c = process_for_ctrl_char(c, has_ctrl);
return Some(c);
}
}
} }
None None
} }
// Helper function to process control characters
fn is_lowercase_alpha(c: char) -> bool { fn is_lowercase_alpha(c: char) -> bool {
char_is_between_inclusive(c, 'a', 'z') char_is_between_inclusive(c, 'a', 'z')
} }
fn process_for_ctrl_char(c: char, has_ctrl : bool) -> char { fn process_for_ctrl_char(c: char, has_ctrl: bool) -> char {
let mut final_ctrl_char = c;
if has_ctrl { if has_ctrl {
if is_lowercase_alpha(c) { (c as u8 & 0x1F) as char
let c_u8 = (c as u8); } else {
let ctrl_char_u8 = c_u8 - 96; c
final_ctrl_char = (ctrl_char_u8 as char);
} else if char_is_between_inclusive(c, '[', '_') {
let c_u8 = (c as u8);
let ctrl_char_u8 = c_u8 - 90;
final_ctrl_char = (ctrl_char_u8 as char);
}
} }
return final_ctrl_char
} }
fn char_is_between_inclusive(c : char, lo_char : char, hi_char : char) -> bool { fn char_is_between_inclusive(c : char, lo_char : char, hi_char : char) -> bool {

2
src-tauri/f.txt Normal file
View file

@ -0,0 +1,2 @@
Hello, I'm typing a file in vim!!