v1.2.2: text measuring improvements, minor code clean
fixed some clippy warnings, ignored many that I do not care about. also, added demo video and updated koxinga image
This commit is contained in:
@@ -152,11 +152,11 @@ impl WindowLike for AudioPlayer {
|
||||
let current = &queue[queue.len() - sink_len];
|
||||
let current_name = current.0.file_name().unwrap().to_string_lossy().into_owned();
|
||||
let fonts = ["nimbus-roman".to_string(), "shippori-mincho".to_string()];
|
||||
let cn_width = measure_text(&fonts, current_name.clone()).width;
|
||||
let cn_width = measure_text(&fonts, ¤t_name, None).width;
|
||||
instructions.push(DrawInstructions::Text([self.dimensions[0] / 2 - cn_width / 2, 2], fonts.to_vec(), current_name.clone(), theme_info.text, theme_info.background, Some(0), None));
|
||||
if let Some(artist) = ¤t.2 {
|
||||
let artist_string = "by ".to_string() + &artist;
|
||||
let as_width = measure_text(&fonts, artist_string.clone()).width;
|
||||
let as_width = measure_text(&fonts, &artist_string, None).width;
|
||||
instructions.push(DrawInstructions::Text([self.dimensions[0] / 2 - as_width / 2, LINE_HEIGHT + 2], fonts.to_vec(), artist_string, theme_info.text, theme_info.background, Some(0), None));
|
||||
}
|
||||
//in this case no chance of mincho so MONO_WIDTH method of calculating width is ok
|
||||
|
||||
@@ -241,9 +241,11 @@ impl WindowLike for Draw {
|
||||
|
||||
impl Draw {
|
||||
pub fn new() -> Self {
|
||||
let mut d: Self = Default::default();
|
||||
d.current_linewidth = 1;
|
||||
d
|
||||
//apparently this is legal. thanks clippy
|
||||
Self {
|
||||
current_linewidth: 1,
|
||||
..Default::default() //no comma here allowed though??
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,13 +111,12 @@ impl WindowLike for FileExplorer {
|
||||
self.metadata = Some(metadata(&selected_entry.path).unwrap());
|
||||
}
|
||||
WindowMessageResponse::JustRedraw
|
||||
} else if self.state == State::Info {
|
||||
//pressing any key to exit info mode
|
||||
self.state = State::List;
|
||||
WindowMessageResponse::JustRedraw
|
||||
} else {
|
||||
if self.state == State::Info {
|
||||
self.state = State::List;
|
||||
WindowMessageResponse::JustRedraw
|
||||
} else {
|
||||
WindowMessageResponse::DoNothing
|
||||
}
|
||||
WindowMessageResponse::DoNothing
|
||||
}
|
||||
},
|
||||
_ => WindowMessageResponse::DoNothing,
|
||||
@@ -128,7 +127,7 @@ impl WindowLike for FileExplorer {
|
||||
let mut instructions = Vec::new();
|
||||
if self.state == State::List {
|
||||
//top bar with path name
|
||||
instructions.push(DrawInstructions::Text([5, 0], vec!["nimbus-roman".to_string(), "shippori-mincho".to_string()], "Current: ".to_string() + &self.current_path.to_string_lossy().to_string(), theme_info.text, theme_info.background, None, None));
|
||||
instructions.push(DrawInstructions::Text([5, 0], vec!["nimbus-roman".to_string(), "shippori-mincho".to_string()], "Current: ".to_string() + self.current_path.to_string_lossy().as_ref(), theme_info.text, theme_info.background, None, None));
|
||||
//the actual files and directories
|
||||
let mut start_y = HEIGHT;
|
||||
let mut i = self.top_position;
|
||||
@@ -142,10 +141,10 @@ impl WindowLike for FileExplorer {
|
||||
}
|
||||
//unwrap_or not used because "Arguments passed to unwrap_or are eagerly evaluated", apparently
|
||||
let name = entry.override_name.clone();
|
||||
let name = if name.is_none() {
|
||||
entry.path.file_name().unwrap().to_os_string().into_string().unwrap()
|
||||
let name = if let Some(name) = name {
|
||||
name
|
||||
} else {
|
||||
name.unwrap()
|
||||
entry.path.file_name().unwrap().to_os_string().into_string().unwrap()
|
||||
};
|
||||
instructions.push(DrawInstructions::Text([5, start_y + 4], vec!["nimbus-roman".to_string(), "shippori-mincho".to_string()], name, if is_selected { theme_info.top_text } else { theme_info.text }, if is_selected { theme_info.top } else { theme_info.background }, None, None));
|
||||
start_y += HEIGHT;
|
||||
|
||||
@@ -138,8 +138,8 @@ impl WindowLike for Malvim {
|
||||
if key_press.is_enter() {
|
||||
let mut line: Vec<char> = line.chars().collect();
|
||||
let (left, right) = line.split_at_mut(current_file.cursor_pos);
|
||||
let left = left.into_iter().map(|c| c.to_string()).collect::<Vec<String>>().join("");
|
||||
let right = right.into_iter().map(|c| c.to_string()).collect::<Vec<String>>().join("");
|
||||
let left = left.iter_mut().map(|c| c.to_string()).collect::<Vec<String>>().join("");
|
||||
let right = right.iter_mut().map(|c| c.to_string()).collect::<Vec<String>>().join("");
|
||||
current_file.content[current_file.line_pos] = left.to_string();
|
||||
let spaces = Malvim::calc_spaces(self.autoindent, &left);
|
||||
current_file.content.insert(current_file.line_pos + 1, " ".repeat(spaces) + &right);
|
||||
@@ -495,7 +495,7 @@ impl WindowLike for Malvim {
|
||||
if i == 0 {
|
||||
//modify current line
|
||||
let line = ¤t_file.content[current_file.line_pos];
|
||||
current_file.content[current_file.line_pos] = line.substring(0, current_file.cursor_pos).to_string() + &cs + line.substring(current_file.cursor_pos, line.chars().count());
|
||||
current_file.content[current_file.line_pos] = line.substring(0, current_file.cursor_pos).to_string() + cs + line.substring(current_file.cursor_pos, line.chars().count());
|
||||
current_file.cursor_pos += copy_string.len();
|
||||
} else {
|
||||
//insert a new line
|
||||
@@ -750,7 +750,7 @@ impl Malvim {
|
||||
}
|
||||
} else if self.files.len() == 0 {
|
||||
self.bottom_message = Some("No files are open, so can only do :e(dit)".to_string());
|
||||
} else if first.starts_with("/") {
|
||||
} else if let Some(s_first) = first.strip_prefix("/") {
|
||||
let current_file = &mut self.files[self.current_file_index];
|
||||
if current_file.content.len() > 0 {
|
||||
let p1 = if arg == "" {
|
||||
@@ -764,7 +764,7 @@ impl Malvim {
|
||||
} else {
|
||||
" ".to_string() + &rest
|
||||
};
|
||||
let query = first[1..].to_string() + &p1 + &rest;
|
||||
let query = s_first.to_string() + &p1 + &rest;
|
||||
let mut lines = current_file.content.iter().skip(current_file.line_pos);
|
||||
for i in 0..(current_file.content.len() - current_file.line_pos) {
|
||||
let line = if i == 0 {
|
||||
|
||||
@@ -256,7 +256,7 @@ impl Minesweeper {
|
||||
self.random_seed as usize % 16
|
||||
}
|
||||
|
||||
pub fn on_adjacent_tiles(&self, x: usize, y: usize, mut action: impl FnMut(usize, usize) -> (), if_mine: bool) {
|
||||
pub fn on_adjacent_tiles(&self, x: usize, y: usize, mut action: impl FnMut(usize, usize), if_mine: bool) {
|
||||
if y > 0 {
|
||||
//above
|
||||
if self.tiles[y - 1][x].mine == if_mine {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::vec::Vec;
|
||||
use std::vec;
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use ming_wm_lib::window_manager_types::{ DrawInstructions, WindowLike, WindowLikeType };
|
||||
use ming_wm_lib::messages::{ WindowMessage, WindowMessageResponse };
|
||||
@@ -101,13 +102,11 @@ impl WindowLike for Reversi {
|
||||
}
|
||||
}
|
||||
}
|
||||
if white_tiles == black_tiles {
|
||||
self.state = State::Tie;
|
||||
} else if white_tiles > black_tiles {
|
||||
self.state = State::WhiteWin;
|
||||
} else {
|
||||
self.state = State::BlackWin;
|
||||
}
|
||||
self.state = match white_tiles.cmp(&black_tiles) {
|
||||
Ordering::Equal => State::Tie,
|
||||
Ordering::Greater => State::WhiteWin,
|
||||
Ordering::Less => State::BlackWin,
|
||||
};
|
||||
}
|
||||
}
|
||||
self.current_number = None;
|
||||
|
||||
@@ -149,27 +149,23 @@ impl WindowLike for Terminal {
|
||||
Mode::Running => {
|
||||
//update
|
||||
let mut changed = false;
|
||||
loop {
|
||||
if let Ok(ci) = self.pty_outerr_rx.as_mut().unwrap().recv_timeout(Duration::from_millis(5)) {
|
||||
if char::from(ci) == '\n' {
|
||||
let append_line = strip_ansi_escape_codes(bytes_to_string(self.process_current_line.clone()));
|
||||
self.output += &append_line;
|
||||
self.output += "\n";
|
||||
self.lines.push(append_line);
|
||||
self.process_current_line = Vec::new();
|
||||
} else if char::from(ci) == '\r' {
|
||||
//for now, ignore
|
||||
//
|
||||
} else if char::from(ci) == '\t' {
|
||||
//for now, interpret as space
|
||||
self.process_current_line.push(b' ');
|
||||
} else {
|
||||
self.process_current_line.push(ci);
|
||||
}
|
||||
changed = true;
|
||||
while let Ok(ci) = self.pty_outerr_rx.as_mut().unwrap().recv_timeout(Duration::from_millis(5)) {
|
||||
if char::from(ci) == '\n' {
|
||||
let append_line = strip_ansi_escape_codes(bytes_to_string(self.process_current_line.clone()));
|
||||
self.output += &append_line;
|
||||
self.output += "\n";
|
||||
self.lines.push(append_line);
|
||||
self.process_current_line = Vec::new();
|
||||
} else if char::from(ci) == '\r' {
|
||||
//for now, ignore
|
||||
//
|
||||
} else if char::from(ci) == '\t' {
|
||||
//for now, interpret as space
|
||||
self.process_current_line.push(b' ');
|
||||
} else {
|
||||
break;
|
||||
self.process_current_line.push(ci);
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
let running_process = self.running_process.as_mut().unwrap();
|
||||
if let Some(_status) = running_process.try_wait().unwrap() {
|
||||
@@ -377,13 +373,9 @@ impl Terminal {
|
||||
let mut stdin = self.running_process.as_mut().unwrap().stdin.take().unwrap();
|
||||
let (tx2, rx2) = channel();
|
||||
thread::spawn(move || {
|
||||
loop {
|
||||
if let Ok(write_line) = rx2.recv() {
|
||||
let write_line: String = write_line + "\n";
|
||||
stdin.write(write_line.as_bytes()).unwrap();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
while let Ok(write_line) = rx2.recv() {
|
||||
let write_line: String = write_line + "\n";
|
||||
stdin.write_all(write_line.as_bytes()).unwrap();
|
||||
}
|
||||
});
|
||||
self.pty_outerr_rx = Some(rx1);
|
||||
|
||||
Reference in New Issue
Block a user