Skip to content

Commit

Permalink
feat(0.0.12)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsuu committed Aug 28, 2022
1 parent ef6c951 commit a1c8a6e
Show file tree
Hide file tree
Showing 18 changed files with 330 additions and 263 deletions.
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 10 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ panic = "abort"

[dependencies]
# fs
tempfile = "3.3.0"
#tempfile = "3.3.0"
walkdir = "2.3.2"
dirs-next = "2.0.0"

Expand All @@ -51,20 +51,12 @@ fast_image_resize = "1.0.0"
lexopt = "0.2.1"

# metadata
byteorder = "1.4.3"
miniserde = "0.1.27"
speedy = "0.8.2"
emeta = "0.1.1"
#emeta = {version="*",path="../emeta"}

# config
syn = { version = "1.0.99", features = ["full", "extra-traits"] }

# other
#rayon = "1.5.3"
tokio = { version = "1.20.1", features = ["full"] }
cfg-if = "1.0.0"

# debug
log = "0.4.17"
simple_logger = { version = "2.3.0", features = ["colors", "threads"] }
Expand All @@ -76,24 +68,23 @@ thiserror = "1.0.32"

# font
fontdue = "0.7.2"
#crossbeam = { version = "0.8.2", features = ["crossbeam-channel"] }
#futures = "0.3.23"
#io-uring = "0.5.3"

# async
tokio = { version = "1.20.1", features = ["full"] }

# other
#rayon = "1.5.3"
cfg-if = "1.0.0"

[dev-dependencies]
# bench
# benchmark
criterion = "0.3.6"
#orz = { version="1.6.1",git="https://github.com/richox/orz"}

[[bench]]
name = "bench_main"
harness = false

[features]
default = ["zip", "tar"]
tar = ["ex_tar"]
zip = ["ex_zip"]
#zstd = ["ex_zstd"]
#ex_zstd = []
default = ["ex_zip", "ex_tar"]
ex_zip = []
ex_tar = []
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ use std::env;
use std::path::PathBuf;

fn main() {
for_minifb();
}

fn for_minifb() {}
fn for_sdl2() {
let target = env::var("TARGET").unwrap();

// for windows
Expand Down
12 changes: 7 additions & 5 deletions docs/TODO.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
+ [] v0.1.0
+ [] v1.0.0
+ [] remove .unwrap()
+ [] more useful help messages
+ [] more tests
+ [] v0.0.12
+ [] display a bit metadata
+ [] bug fix
+ [] v0.0.13
+ [] display metadata
+ [x] v0.0.12
+ [x] bug fix
+ [x] auto change config path
+ [x] rgba8 to rgb8
+ [x] v0.0.11
+ [x] async support for move_down()
+ [x] async support for move_up()
Expand Down
35 changes: 35 additions & 0 deletions src/archive/dir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::utils::err::{MyErr, Res};
use log;
use std::{fs::OpenOptions, io::Read, path::Path};
use walkdir;

pub fn load_file(path: &Path, pos: usize) -> Res<Vec<u8>> {
for (idx, f) in walkdir::WalkDir::new(path).into_iter().enumerate() {
if pos == idx {
let mut buffer = Vec::new();
let mut f = OpenOptions::new()
.write(false)
.read(true)
.create(false)
.open(f.unwrap().path())
.unwrap();

f.read_to_end(&mut buffer).unwrap();

return Ok(buffer);
} else {
}
}

Err(MyErr::FoundNull)
}

pub fn get_file_list(path: &Path) -> Res<Vec<(String, usize)>> {
let mut list = Vec::new();

for (idx, f) in walkdir::WalkDir::new(path).into_iter().enumerate() {
list.push((f?.path().to_str().unwrap().to_string(), idx));
}

Ok(list)
}
70 changes: 54 additions & 16 deletions src/cli/parse.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use crate::{
color::format,
config::rsconf::Config,
img::size::Size,
utils::types::{MyError, SelfResult},
utils::{
err::Res,
types::{MyError, SelfResult},
},
};
use dirs_next;
use emeta::meta;
use lexopt::{self, prelude::*};
use std::process::exit;
use std::{fs::File, io::Write, path::PathBuf, process::exit};

#[derive(Debug)]
pub struct Args {
Expand Down Expand Up @@ -43,8 +48,7 @@ impl Args {
}
}

pub fn get_args() -> SelfResult<Self> {
let mut args = Args::new();
pub fn parse(&mut self) -> SelfResult<()> {
let mut parser = lexopt::Parser::from_env();

while let Some(arg) = parser.next()? {
Expand All @@ -54,10 +58,7 @@ impl Args {
}

Long("config") | Short('c') => {
if args.config_path.is_none() {
args.config_path = Some(parser.value()?.into_string()?);
} else {
}
self.config_path = Some(parser.value()?.into_string()?);
}

Long("size") | Short('s') => {
Expand All @@ -66,7 +67,7 @@ impl Args {

if let Ok(w) = size[0].parse::<usize>() {
if let Ok(h) = size[1].parse::<usize>() {
args.size = Some(Size::new(w, h));
self.size = Some(Size::new(w, h));
}
}
}
Expand All @@ -75,20 +76,20 @@ impl Args {
let is_rename = parser.value()?.into_string()?;

if is_rename.as_str() == "false" {
args.rename = false
self.rename = false
} else {
panic!("")
};
}

Long("pad") => {
let pad = parser.value()?.into_string()?;
args.rename_pad = pad.parse::<usize>()?;
self.rename_pad = pad.parse::<usize>()?;
}

Long("format") => {
let format = parser.value()?.into_string()?;
args.format = match format.as_str() {
self.format = match format.as_str() {
"rgb8" => Some(format::PixelFormat::Rgb8),
"rgba8" => Some(format::PixelFormat::Rgba8),
_ => None,
Expand All @@ -100,7 +101,7 @@ impl Args {

match sub.to_ascii_lowercase().as_str() {
"d" | "display" => {
args.meta_display = true;
self.meta_display = true;
}

"f" | "from" => {
Expand All @@ -119,18 +120,55 @@ impl Args {
}
}

Value(v) => args.file_path = Some(v.into_string()?),
Value(v) => self.file_path = Some(v.into_string()?),

_ => {
print_help();
}
}
}

Ok(args)
Ok(())
}

pub fn set_size(&mut self, config: &mut Config) {
if let Some(size) = self.size {
config.base.size = size;
} else {
// default
};
}

pub fn parse(&self) {}
pub fn set_config_path(&mut self) {
if self.config_path.is_none() {
let mut config_path = PathBuf::new();

if let Some(path) = dirs_next::config_dir() {
config_path.push(path.as_path());

if config_path.as_path().is_dir() {
} else {
std::fs::create_dir(config_path.as_path()).unwrap();
}

config_path.push("rmg/config.rs");

if config_path.as_path().is_file() {
} else {
let mut f = File::create(config_path.as_path()).unwrap();

f.write_all(include_bytes!("../config/default_config.rs"))
.unwrap();
}

self.config_path = Some(config_path.to_str().unwrap().to_string());

log::debug!("config_path == {:?}", config_path.as_path());
} else {
}
} else {
}
}
}

impl Default for Args {
Expand Down
17 changes: 17 additions & 0 deletions src/config/default_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
fn main() {
Base {
size: (900, 900),
font: "./tests/files/test.ttf",
format: "rgb8",
rename: true,
rename_pad: 6,
};

Keymap {
up: 'k',
down: 'j',
left: 'h',
right: 'l',
exit: 'q',
};
}
Loading

0 comments on commit a1c8a6e

Please sign in to comment.