v1.0.3: mostly malvim improvements

malvim: search, d$, %. fix w and m in mono font. apply some clippy lint suggestions
This commit is contained in:
stjet
2025-04-17 00:53:31 +00:00
parent 11af21ee6d
commit d32b82a2bb
19 changed files with 233 additions and 93 deletions

View File

@@ -58,22 +58,22 @@ pub fn listen(mut window_like: impl WindowLike) {
let arg = &parts.collect::<Vec<&str>>().join(" ");
let output = match method {
"handle_message" => {
format!("{}", &window_like.handle_message(WindowMessage::deserialize(arg).unwrap()).serialize())
window_like.handle_message(WindowMessage::deserialize(arg).unwrap()).serialize().to_string()
},
"draw" => {
format!("{}", &window_like.draw(&ThemeInfo::deserialize(arg).unwrap()).serialize().replace("\n", ""))
window_like.draw(&ThemeInfo::deserialize(arg).unwrap()).serialize().replace("\n", "").to_string()
},
"title" => {
format!("{}", window_like.title())
window_like.title().to_string()
},
"resizable" => {
format!("{}", window_like.resizable())
window_like.resizable().to_string()
},
"subtype" => {
format!("{}", &window_like.subtype().serialize())
window_like.subtype().serialize().to_string()
},
"ideal_dimensions" => {
format!("{}", &window_like.ideal_dimensions(Dimensions::deserialize(arg).unwrap()).serialize())
window_like.ideal_dimensions(Dimensions::deserialize(arg).unwrap()).serialize().to_string()
},
_ => String::new(),
};

View File

@@ -39,10 +39,10 @@ fn option_to_string<T: Display>(option: &Option<T>) -> String {
fn get_color(serialized: &str) -> Result<[u8; 3], ()> {
let rgb = serialized.split("\x1F");
let mut color = [0; 3];
let mut c_i = 0;
//won't return error if rgb is 0, 1, or 2 elements.
//I guess that's okay, since it doesn't panic either
for c in rgb {
//c_i is the loop counter. enumerate(), you are awesome
for (c_i, c) in rgb.enumerate() {
if c_i == 3 {
return Err(());
}
@@ -51,7 +51,6 @@ fn get_color(serialized: &str) -> Result<[u8; 3], ()> {
} else {
return Err(());
}
c_i += 1;
}
Ok(color)
}
@@ -68,7 +67,7 @@ fn get_two_array(serialized: &str) -> Result<[usize; 2], ()> {
}
return Err(());
}
return Ok(a);
Ok(a)
}
pub trait Serializable {
@@ -87,9 +86,8 @@ impl Serializable for ThemeInfo {
let serialized = if serialized.ends_with("\n") { &serialized[..serialized.len() - 1] } else { serialized };
let mut theme_info: ThemeInfo = Default::default();
let arrays = serialized.split(":");
let mut a_i = 0;
//won't error or panic if less than 9... rest will just be black by default I guess
for a in arrays {
for (a_i, a) in arrays.enumerate() {
if a_i == 9 {
return Err(());
}
@@ -127,7 +125,6 @@ impl Serializable for ThemeInfo {
if a_i == 8 {
return Ok(theme_info);
}
a_i += 1;
}
Err(())
}
@@ -220,7 +217,7 @@ impl Serializable for DrawInstructions {
match self {
//use \x1E (record separator) because it won't be in strings. it better fucking not be at least
DrawInstructions::Rect(p, d, c) => format!("Rect/{}\x1E{}\x1E{}", array_to_string(p), array_to_string(d), array_to_string(c)),
DrawInstructions::Text(p, vs, s, c1, c2, ou1, ou2) => format!("Text/{}\x1E{}\x1E{}\x1E{}\x1E{}\x1E{}\x1E{}", array_to_string(p), array_to_string(&vs), s, array_to_string(c1), array_to_string(c2), option_to_string(ou1), option_to_string(ou2)),
DrawInstructions::Text(p, vs, s, c1, c2, ou1, ou2) => format!("Text/{}\x1E{}\x1E{}\x1E{}\x1E{}\x1E{}\x1E{}", array_to_string(p), array_to_string(vs), s, array_to_string(c1), array_to_string(c2), option_to_string(ou1), option_to_string(ou2)),
DrawInstructions::Gradient(p, d, c1, c2, u) => format!("Gradient/{}\x1E{}\x1E{}\x1E{}\x1E{}", array_to_string(p), array_to_string(d), array_to_string(c1), array_to_string(c2), u),
DrawInstructions::Bmp(p, s, b) => format!("Bmp/{}\x1E{}\x1E{}", array_to_string(p), s, b),
DrawInstructions::Circle(p, u, c) => format!("Circle/{}\x1E{}\x1E{}", array_to_string(p), u, array_to_string(c)),
@@ -674,8 +671,7 @@ impl Serializable for WindowMessage {
}
let mut w_tuple: (usize, String) = Default::default();
let mut w_vec = Vec::new();
let mut i = 0;
for a in arg2.unwrap().split("\x1F") {
for (i, a) in arg2.unwrap().split("\x1F").enumerate() {
if i % 2 == 0 {
if let Ok(n) = a.parse() {
w_tuple.0 = n;
@@ -684,7 +680,6 @@ impl Serializable for WindowMessage {
w_tuple.1 = a.to_string();
w_vec.push(w_tuple.clone());
}
i += 1;
}
let arg2 = parts2.next();
if arg2.is_none() {

View File

@@ -104,6 +104,6 @@ pub fn get_theme_info(theme: &Themes) -> Option<ThemeInfo> {
return Some(pair.1);
}
}
return None;
None
}

View File

@@ -11,6 +11,7 @@ pub trait Substring {
fn substring(&self, start: usize, end: usize) -> &str;
fn remove(&self, index: usize, len: usize) -> String;
fn remove_last(&self) -> String;
fn find_substring(&self, substr: &str) -> Option<usize>;
}
impl Substring for String {
@@ -29,6 +30,14 @@ impl Substring for String {
byte_end += char_length;
}
&self[byte_start..byte_end]
/*
let mut result = String::new();
let mut chars = self.chars().skip(start);
for _i in 0..(end - start) {
result += &chars.next().unwrap().to_string();
}
result
*/
}
fn remove(&self, index: usize, len: usize) -> String {
@@ -38,13 +47,26 @@ impl Substring for String {
fn remove_last(&self) -> String {
self.substring(0, self.chars().count() - 1).to_string()
}
fn find_substring(&self, substr: &str) -> Option<usize> {
//slightly inefficient
let substr_len = substr.chars().count();
let self_len = self.chars().count();
if substr_len <= self_len {
for start in 0..=(self_len - substr_len) {
if self.substring(start, start + substr_len) == substr {
return Some(start);
}
}
}
None
}
}
//the tuple is first, line #, actual line
pub fn calc_actual_lines<'a>(lines: impl Iterator<Item = &'a String>, max_chars_per_line: usize, one_extra: bool) -> Vec<(bool, usize, String)> {
let mut actual_lines = Vec::new();
let mut line_num = 0;
for real_line in lines {
for (line_num, real_line) in lines.enumerate() {
let mut line = real_line.to_string() + if one_extra { " " } else { "" };
let mut first = true;
loop {
@@ -62,7 +84,6 @@ pub fn calc_actual_lines<'a>(lines: impl Iterator<Item = &'a String>, max_chars_
}
first = false;
}
line_num += 1;
}
actual_lines
}
@@ -132,7 +153,7 @@ pub fn hex_to_u8(c1: char, c2: char) -> u8 {
}
pub fn is_hex(c: char) -> bool {
HEX_CHARS.iter().position(|hc| hc == &c).is_some()
HEX_CHARS.iter().any(|hc| hc == &c)
}
pub fn point_inside(point: Point, top_left: Point, size: Dimensions) -> bool {
@@ -193,4 +214,3 @@ pub fn path_autocomplete(current_path: &str, partial_path: &str) -> Option<Strin
None
}
}