minor fix

This commit is contained in:
Guilleag01
2023-11-09 18:13:32 +01:00
parent 830dc5d9ac
commit 8a690d0082
1856 changed files with 4052 additions and 0 deletions

511
Cargo.lock generated Normal file
View File

@@ -0,0 +1,511 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "android-tzdata"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
[[package]]
name = "anstyle-parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bitflags"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
[[package]]
name = "bumpalo"
version = "3.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec"
[[package]]
name = "cc"
version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
dependencies = [
"libc",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"wasm-bindgen",
"windows-targets",
]
[[package]]
name = "clap"
version = "4.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "colored"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2674ec482fbc38012cf31e6c42ba0177b431a0cb6f15fe40efa5aab1bda516f6"
dependencies = [
"is-terminal",
"lazy_static",
"windows-sys",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "errno"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c18ee0ed65a5f1f81cac6b1d213b69c35fa47d4252ad41f1486dbd8226fe36e"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermit-abi"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
[[package]]
name = "iana-time-zone"
version = "0.1.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"windows-core",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]]
name = "is-terminal"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b"
dependencies = [
"hermit-abi",
"rustix",
"windows-sys",
]
[[package]]
name = "js-sys"
version = "0.3.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "linux-raw-sys"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829"
[[package]]
name = "log"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "lsplus"
version = "0.1.0"
dependencies = [
"chrono",
"clap",
"colored",
"term_size",
]
[[package]]
name = "num-traits"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c"
dependencies = [
"autocfg",
]
[[package]]
name = "once_cell"
version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "proc-macro2"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rustix"
version = "0.38.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3"
dependencies = [
"bitflags",
"errno",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "2.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "term_size"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "wasm-bindgen"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-core"
version = "0.51.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"

10
Cargo.toml Normal file
View File

@@ -0,0 +1,10 @@
[package]
name = "lsplus"
version = "0.1.0"
edition = "2021"
[dependencies]
chrono = "0.4.31"
clap = { version = "4.4.7", features = ["derive"] }
colored = "2.0.4"
term_size = "0.3.2"

0
src/config.json Normal file
View File

9
src/config.rs Normal file
View File

@@ -0,0 +1,9 @@
// use colored::Colorize;
// use crate::element::Element;
// pub struct Config {
// dir_config: Vec<usize>,
// }
// impl Config {}

110
src/element.rs Normal file
View File

@@ -0,0 +1,110 @@
use std::{fmt::Display, fs, os::unix::prelude::FileTypeExt, path::Path, time::SystemTime};
use crate::utils::get_icon_file_type;
#[derive(Copy, Clone)]
pub enum TypeOfFile {
File,
Dir,
Link,
Block,
Socket,
}
#[derive(Clone)]
pub struct Element {
path: String,
file_type: TypeOfFile,
name: String,
perms: fs::Permissions,
size: u64,
creation: SystemTime,
}
impl Element {
pub fn new(path_str: &str) -> Element {
let path_built = Path::new(path_str);
// println!("{:?}", path_built);
let metadata = fs::metadata(path_str).unwrap();
let symlink_metadata = fs::symlink_metadata(path_str).unwrap();
let t: TypeOfFile;
if symlink_metadata.is_symlink() {
t = TypeOfFile::Link;
} else if metadata.is_dir() {
t = TypeOfFile::Dir;
} else if metadata.is_file() {
t = TypeOfFile::File;
} else if metadata.file_type().is_block_device() {
t = TypeOfFile::Block;
} else if metadata.file_type().is_socket() {
t = TypeOfFile::Socket;
} else {
t = TypeOfFile::File;
}
Self {
path: path_str.to_string(),
file_type: t,
name: path_built
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string(),
perms: metadata.permissions(),
size: metadata.len(),
creation: metadata.created().unwrap(),
}
}
pub fn get_path_string(&self) -> String {
self.path.clone()
}
pub fn get_file_type(&self) -> TypeOfFile {
self.file_type
}
pub fn get_name(&self) -> String {
self.name.clone()
}
pub fn get_perms(&self) -> fs::Permissions {
self.perms.clone()
}
pub fn get_size(&self) -> u64 {
self.size
}
pub fn get_creation(&self) -> SystemTime {
self.creation
}
}
impl Display for Element {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let file_icon = get_icon_file_type(self.get_name());
let mut is_dir = false;
let icon = match self.file_type {
TypeOfFile::File => file_icon,
TypeOfFile::Dir => {
is_dir = true;
""
}
TypeOfFile::Link => " 󱅷 ",
TypeOfFile::Block => " 󰋊 ",
TypeOfFile::Socket => " 󰛳 ",
};
write!(
f,
"{}{}{} ",
icon,
self.name.as_str(),
if is_dir { "/" } else { "" }
)
}
}

4
src/lib.rs Normal file
View File

@@ -0,0 +1,4 @@
pub mod config;
pub mod element;
pub mod out;
pub mod utils;

42
src/main.rs Normal file
View File

@@ -0,0 +1,42 @@
use clap::Parser;
use lsplus::{
element::Element,
out::{default::default, list::list},
};
use std::fs;
// Needs to be defined in main
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Args {
/// Show hidden files
#[arg(short, long, default_value_t = false)]
all: bool,
/// Print as a list
#[arg(short, long, default_value_t = false)]
list: bool,
/// Path of the directory to list
#[arg(default_value_t = String::from("."))]
path: String,
}
fn main() {
let args = Args::parse();
let paths = fs::read_dir(args.path).unwrap();
let _max_width = 50;
let elements: Vec<Element> = paths
.map(|e| Element::new(e.unwrap().path().to_str().unwrap()))
.filter(|element| args.all || !element.get_name().starts_with('.'))
.collect();
if args.list {
list(elements);
} else {
default(elements);
}
}

50
src/out/default.rs Normal file
View File

@@ -0,0 +1,50 @@
use crate::element::Element;
use crate::utils::{get_string_length, pad_string};
pub fn default(mut elements: Vec<Element>) {
elements.sort_unstable_by_key(|a: &Element| a.get_name());
let width = term_size::dimensions().unwrap().0;
let mut i = 1;
let mut num_columns = 1;
let mut column_widths: Vec<usize> = Vec::new();
let mut total = std::usize::MAX;
while total >= width - 1 {
total = 0;
num_columns = (elements.len() as f32 / i as f32).ceil() as usize;
column_widths = vec![0; num_columns];
for j in 0..num_columns {
let mut max_len = 0;
for k in 0..i {
if i * j + k < elements.len() {
let space = get_string_length(&elements[i * j + k].to_string());
if space > max_len {
max_len = space;
}
}
}
// println!("Max len {}", max_len);
total += max_len;
column_widths[j] = max_len;
}
i += 1;
}
i -= 1;
for k in 0..i {
for j in 0..num_columns {
if i * j + k < elements.len() {
print!(
"{}",
pad_string(elements[i * j + k].to_string(), column_widths[j], true)
);
}
}
println!();
}
println!();
}

100
src/out/list.rs Normal file
View File

@@ -0,0 +1,100 @@
use crate::element::Element;
use crate::utils::{get_size_string, get_string_length, pad_string, system_time_to_string};
pub fn list(mut elements: Vec<Element>) {
elements.sort_unstable_by_key(|a: &Element| a.get_name());
let width = term_size::dimensions().unwrap().0;
// ╭──────────────╼ File name ╾──────────────┬─╼ Size ╾─┬──╼ Creation ╾──╮
// │ │ │ │
// ╰─────────────────────────────────────────┴──────────┴────────────────╯
let mut name_max_len = 0;
for e in &elements {
let length = get_string_length(e.to_string().as_str());
if length > name_max_len {
name_max_len = length;
}
}
let name_length = name_max_len
.max(14 + (elements.len() as f32).log10() as usize)
.max(13)
.min(width - 30);
print_header(name_length);
print_elements(&elements, name_length);
print_footer(&elements, name_length);
}
fn print_header(name_length: usize) {
print!("");
for _ in 0..((name_length - 13) as f32 / 2.0).floor() as usize {
print!("");
}
print!("╼ File name ╾");
for _ in 0..((name_length - 13) as f32 / 2.0).ceil() as usize {
print!("");
}
println!("┬─╼ Size ╾─┬──╼ Creation ╾──╮");
}
fn print_elements(elements: &Vec<Element>, name_length: usize) {
for e in elements {
let str_len = get_string_length(e.get_name().as_str());
print!("");
if get_string_length(e.to_string().as_str()) > name_length {
print!(
"{}",
pad_string(
e.to_string().as_str()[..=name_length].to_string(),
name_length,
true
)
);
print!("");
print!("{}", pad_string(get_size_string(e.get_size()), 10, false));
print!("");
print!(" {} ", system_time_to_string(e.get_creation()));
println!("");
for i in 1..(str_len / (name_length - 5) + 1) {
print!(
"{}",
pad_string(
e.get_name().as_str()
[((name_length - 5) * i)..((name_length - 5) * (i + 1)).min(str_len)]
.to_string(),
name_length - 3,
true
)
);
println!("│ │ │");
}
} else {
print!("{}", pad_string(e.to_string(), name_length, true));
print!("");
print!("{}", pad_string(get_size_string(e.get_size()), 10, false));
print!("");
print!(" {} ", system_time_to_string(e.get_creation()));
println!("");
}
}
}
fn print_footer(elements: &Vec<Element>, name_length: usize) {
let num_elements = elements.len();
let num_elements_len = (num_elements as f32).log10() as usize;
let name_length_fixed = name_length - (num_elements_len + 14);
print!("");
for _ in 0..((name_length_fixed) as f32 / 2.0).floor() as usize {
print!("");
}
print!("{} Elements ╾", num_elements);
for _ in 0..((name_length_fixed) as f32 / 2.0).ceil() as usize {
print!("");
}
// for _ in 0..(name_length - (num_elements_len + 15)) {
// print!("─");
// }
println!("┴──────────┴────────────────╯");
}

2
src/out/mod.rs Normal file
View File

@@ -0,0 +1,2 @@
pub mod default;
pub mod list;

67
src/utils.rs Normal file
View File

@@ -0,0 +1,67 @@
use std::time::SystemTime;
use chrono::offset::Utc;
use chrono::DateTime;
pub fn pad_string(s: String, pad: usize, after: bool) -> String {
let mut s2 = String::new();
if after {
s2.push_str(s.as_str());
for _ in 0..(pad - get_string_length(&s)) {
s2.push(' ');
}
} else {
for _ in 0..(pad - get_string_length(&s)) {
s2.push(' ');
}
s2.push_str(s.as_str());
}
s2
}
// Some characters like  counts for more than one
// character when using .len()
#[inline]
pub fn get_string_length(s: &str) -> usize {
s.chars().collect::<Vec<char>>().len();
s.chars().count()
}
pub fn get_size_string(bytes: u64) -> String {
if bytes == 0 {
return String::from("0.00 B ");
}
let bytes_f32 = bytes as f32;
let exp = bytes_f32.log(1024.0).floor();
// print!("\n{}", exp);
let divided_num = bytes_f32 / 1024.0_f32.powf(exp);
let unit = ['B', 'K', 'M', 'G', 'T', 'P', 'Y', 'E'][exp as usize];
format!("{:.2} {} ", divided_num, unit)
}
pub fn system_time_to_string(system_time: SystemTime) -> String {
let datetime: DateTime<Utc> = system_time.into();
datetime.format("%d-%m-%y %H:%M").to_string()
}
pub fn get_icon_file_type<'a>(filename: String) -> &'a str {
let extension = filename.split('.').collect::<Vec<&str>>()[1..].join(".");
match extension.to_lowercase().as_str() {
"zip" | "rar" | "7zip" | "tar" | "tar.gz" | "tgz" => " 󰗄 ",
"rs" => "",
"jpg" | "jpeg" | "png" | "bmp" | "gif" | "webp" | "svg" => " 󰋩 ",
"flv" | "avi" | "mp4" | "webm" | "mov" => "",
"exe" | "ini" | "bat" => "",
"py" => "",
"c" => "",
"cpp" => "",
"json" => "",
"pdf" => " 󰈦 ",
"java" | "jar" => "",
"js" => "",
"html" => "",
"css" => "",
"csv" => "",
_ => " 󰈔 ",
}
}

1
target/.rustc_info.json Normal file
View File

@@ -0,0 +1 @@
{"rustc_fingerprint":10383860293605188035,"outputs":{"16281851364911358784":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/guillermo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\nfeature=\"cargo-clippy\"\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.73.0 (cc66ad468 2023-10-03)\nbinary: rustc\ncommit-hash: cc66ad468955717ab92600c770da8c1601a4ff33\ncommit-date: 2023-10-03\nhost: x86_64-unknown-linux-gnu\nrelease: 1.73.0\nLLVM version: 17.0.2\n","stderr":""}},"successes":{}}

3
target/CACHEDIR.TAG Normal file
View File

@@ -0,0 +1,3 @@
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by cargo.
# For information about cache directory tags see https://bford.info/cachedir/

0
target/debug/.cargo-lock Normal file
View File

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
e2556e88d0c00f68

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"auto\", \"default\", \"wincon\"]","target":16157420304466204941,"profile":14473208297124147686,"path":17720566497556768124,"deps":[[2294077528697419694,"utf8parse",false,3550564280640951622],[5148538637882178987,"anstyle_parse",false,2782257590511135007],[5203015415326938158,"colorchoice",false,17674494573886959853],[5674652241715605352,"anstyle",false,16166500655965126597],[8275806767060717590,"anstyle_query",false,5373927525887949515]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/anstream-2b9ec96a0a1331ff/dep-lib-anstream"}}],"rustflags":[],"metadata":7500874485387469444,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
aa7e58fab2619fa9

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"auto\", \"default\", \"wincon\"]","target":16157420304466204941,"profile":644273664987288228,"path":17720566497556768124,"deps":[[2294077528697419694,"utf8parse",false,12953733348622972549],[5148538637882178987,"anstyle_parse",false,9162436412577759480],[5203015415326938158,"colorchoice",false,4616470882498720355],[5674652241715605352,"anstyle",false,13315987534734302752],[8275806767060717590,"anstyle_query",false,1021562443315111006]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/anstream-c42b4ab2c8560bc3/dep-lib-anstream"}}],"rustflags":[],"metadata":7500874485387469444,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
c5bfeb5bb1f25ae0

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"default\", \"std\"]","target":13663407036240438623,"profile":14473208297124147686,"path":243039031783566823,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/anstyle-14507fb3874042bb/dep-lib-anstyle"}}],"rustflags":[],"metadata":14064844656010464607,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
201e5e991ce4cbb8

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"default\", \"std\"]","target":13663407036240438623,"profile":644273664987288228,"path":243039031783566823,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/anstyle-b750deaea2cb80aa/dep-lib-anstyle"}}],"rustflags":[],"metadata":14064844656010464607,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
f840cd605f83277f

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"default\", \"utf8\"]","target":1993415851866499831,"profile":644273664987288228,"path":14774399117727090436,"deps":[[2294077528697419694,"utf8parse",false,12953733348622972549]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/anstyle-parse-68a33f945f8da244/dep-lib-anstyle-parse"}}],"rustflags":[],"metadata":9799137552285937175,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
1fe90c9c89909c26

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"default\", \"utf8\"]","target":1993415851866499831,"profile":14473208297124147686,"path":14774399117727090436,"deps":[[2294077528697419694,"utf8parse",false,3550564280640951622]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/anstyle-parse-d0a63460b843cf31/dep-lib-anstyle-parse"}}],"rustflags":[],"metadata":9799137552285937175,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
5e64ad35a1512d0e

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[]","target":8921697713841910856,"profile":644273664987288228,"path":16048863362366400656,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/anstyle-query-2735279d59cade24/dep-lib-anstyle-query"}}],"rustflags":[],"metadata":10674566383365303417,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
cbba3ecd9c06944a

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[]","target":8921697713841910856,"profile":14473208297124147686,"path":16048863362366400656,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/anstyle-query-922d6e449bf7df78/dep-lib-anstyle-query"}}],"rustflags":[],"metadata":10674566383365303417,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
c8e27f02743d2aea

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[]","target":14886237245231788030,"profile":13178609178403335023,"path":12727350889475611025,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/autocfg-f7f01ff82b876c9b/dep-lib-autocfg"}}],"rustflags":[],"metadata":13102859075309379048,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
5a8f752015180efc

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"std\"]","target":17263469766201294439,"profile":644273664987288228,"path":2434738069768914952,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/bitflags-1830df54dba8d609/dep-lib-bitflags"}}],"rustflags":[],"metadata":14564035643000669268,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
3310b36ca654c316

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"std\"]","target":17263469766201294439,"profile":14473208297124147686,"path":2434738069768914952,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/bitflags-1e46f62ecf28cccf/dep-lib-bitflags"}}],"rustflags":[],"metadata":14564035643000669268,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
25f0e33aa07fdc96

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[]","target":17263469766201294439,"profile":14473208297124147686,"path":2434738069768914952,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/bitflags-38ac3ae068149690/dep-lib-bitflags"}}],"rustflags":[],"metadata":14564035643000669268,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
08af5ace9e2bd9cf

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[]","target":10623512480563079566,"profile":14473208297124147686,"path":1671252947294517431,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/cfg-if-99a6221ed22cb7f5/dep-lib-cfg-if"}}],"rustflags":[],"metadata":8462187951337715540,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
0fb9a5accbc67907

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"android-tzdata\", \"clock\", \"default\", \"iana-time-zone\", \"js-sys\", \"oldtime\", \"std\", \"wasm-bindgen\", \"wasmbind\", \"winapi\", \"windows-targets\"]","target":11745563112108967737,"profile":644273664987288228,"path":17033200017480047949,"deps":[[1552112088561924514,"iana_time_zone",false,17372832464508804170],[11138931377059941435,"num_traits",false,1274800428829887313]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/chrono-7d049486d9b1f94e/dep-lib-chrono"}}],"rustflags":[],"metadata":9803565982372010724,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
bfd6922e4cf109ea

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"android-tzdata\", \"clock\", \"default\", \"iana-time-zone\", \"js-sys\", \"oldtime\", \"std\", \"wasm-bindgen\", \"wasmbind\", \"winapi\", \"windows-targets\"]","target":11745563112108967737,"profile":14473208297124147686,"path":17033200017480047949,"deps":[[1552112088561924514,"iana_time_zone",false,372654622441306309],[11138931377059941435,"num_traits",false,17553769385929127390]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/chrono-b4356d655f548d17/dep-lib-chrono"}}],"rustflags":[],"metadata":9803565982372010724,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
51e4dafcdd971da2

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"color\", \"default\", \"derive\", \"error-context\", \"help\", \"std\", \"suggestions\", \"usage\"]","target":11682353261401937188,"profile":14473208297124147686,"path":14193550754632741318,"deps":[[669219434892875006,"clap_builder",false,2605108546994178745],[6523682134114348055,"clap_derive",false,927837164682272077]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/clap-22230cc1409db05b/dep-lib-clap"}}],"rustflags":[],"metadata":13636260659328210681,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
9f27b6b240c08f19

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"color\", \"default\", \"derive\", \"error-context\", \"help\", \"std\", \"suggestions\", \"usage\"]","target":11682353261401937188,"profile":644273664987288228,"path":14193550754632741318,"deps":[[669219434892875006,"clap_builder",false,11257299873114340758],[6523682134114348055,"clap_derive",false,927837164682272077]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/clap-484ec362285e75d6/dep-lib-clap"}}],"rustflags":[],"metadata":13636260659328210681,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
21958432e312b4a0

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"color\", \"default\", \"error-context\", \"help\", \"std\", \"suggestions\", \"usage\"]","target":11682353261401937188,"profile":14473208297124147686,"path":14193550754632741318,"deps":[[669219434892875006,"clap_builder",false,2605108546994178745]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/clap-afd585d76b77a259/dep-lib-clap"}}],"rustflags":[],"metadata":13636260659328210681,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
b90aecc86b342724

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"color\", \"error-context\", \"help\", \"std\", \"suggestions\", \"usage\"]","target":4283070019788116899,"profile":14473208297124147686,"path":16884423338343921045,"deps":[[1384874791775932529,"clap_lex",false,1397767149517315711],[3684715375434759994,"strsim",false,10474191173879273303],[5674652241715605352,"anstyle",false,16166500655965126597],[14610966022413035824,"anstream",false,7498423906469828066]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/clap_builder-69e145bd84600105/dep-lib-clap_builder"}}],"rustflags":[],"metadata":13636260659328210681,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
96bd074397f6399c

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"color\", \"error-context\", \"help\", \"std\", \"suggestions\", \"usage\"]","target":4283070019788116899,"profile":644273664987288228,"path":16884423338343921045,"deps":[[1384874791775932529,"clap_lex",false,8411548522998875258],[3684715375434759994,"strsim",false,6100226360004499831],[5674652241715605352,"anstyle",false,13315987534734302752],[14610966022413035824,"anstream",false,12222595335038992042]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/clap_builder-bccfd23c6359e0ec/dep-lib-clap_builder"}}],"rustflags":[],"metadata":13636260659328210681,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

View File

@@ -0,0 +1 @@
4ddd4a42fc56e00c

View File

@@ -0,0 +1 @@
{"rustc":16895609601713598366,"features":"[\"default\"]","target":2857516309462705178,"profile":13178609178403335023,"path":335095978798641381,"deps":[[2050965530884542226,"proc_macro2",false,10677753698045739493],[9408694074551658551,"quote",false,4438516990082348694],[11709930968028960932,"heck",false,17227754038093149539],[12965137675303687879,"syn",false,17392064659996192050]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/clap_derive-2e3908ac6b5030f9/dep-lib-clap_derive"}}],"rustflags":[],"metadata":751742508315986310,"config":2202906307356721367,"compile_kind":0}

View File

@@ -0,0 +1 @@
This file has an mtime of when this was started.

Some files were not shown because too many files have changed in this diff Show More