MUSIC PLAYERgit diff --cached src/window_likes/malvim.rs! and fixes

This commit is contained in:
stjet
2024-10-21 05:21:59 +00:00
parent 4a972783a8
commit decf1d3b82
13 changed files with 288 additions and 54 deletions

View File

@@ -1,3 +1,4 @@
use std::path::PathBuf;
pub trait Substring {
fn substring(&self, start: usize, end: usize) -> &str;
@@ -67,4 +68,38 @@ pub fn calc_new_cursor_pos(cursor_pos: usize, new_length: usize) -> usize {
}
}
pub fn concat_paths(current_path: &str, add_path: &str) -> Result<PathBuf, ()> {
let mut new_path = PathBuf::from(current_path);
if add_path.starts_with("/") {
//absolute path
new_path = PathBuf::from(add_path);
} else {
//relative path
for part in add_path.split("/") {
if part == ".." {
if let Some(parent) = new_path.parent() {
new_path = parent.to_path_buf();
} else {
return Err(());
}
} else {
new_path.push(part);
}
}
}
Ok(new_path)
}
//go from seconds to minutes:seconds
pub fn format_seconds(seconds: u64) -> String {
let mut m = (seconds / 60).to_string(); //automatically rounds down
if m.len() == 1 {
m = "0".to_string() + &m;
}
let mut s = (seconds % 60).to_string();
if s.len() == 1 {
s = "0".to_string() + &s;
}
m + ":" + &s
}