Skip to content

Commit

Permalink
v0.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
ksk001100 committed Mar 31, 2022
1 parent e76d36a commit 408b2a3
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "picterm"
version = "0.0.9"
version = "0.0.10"
authors = ["Keisuke Toyota <[email protected]>"]
edition = "2018"
repository = "https://github.com/ksk001100/picterm"
Expand Down
4 changes: 1 addition & 3 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ impl<'a> App<'a> {
self.is_loading
}

pub fn initialized(&mut self, mode: ImageMode) {
let args: Vec<String> = std::env::args().collect();
let path = if args[1..].is_empty() { "./" } else { &args[1] };
pub fn initialized(&mut self, path: &str, mode: ImageMode) {
self.actions = vec![
Action::Quit,
Action::Increment,
Expand Down
6 changes: 3 additions & 3 deletions src/io/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ impl<'a> IoAsyncHandler<'a> {

pub async fn handle_io_event(&mut self, io_event: IoEvent) {
let _ = match io_event {
IoEvent::Initialize(mode) => self.do_initialize(mode).await,
IoEvent::Initialize(path, mode) => self.do_initialize(&path, mode).await,
IoEvent::LoadImage => self.do_load_image().await,
};

let mut app = self.app.lock().await;
app.loaded();
}

async fn do_initialize(&mut self, mode: ImageMode) -> Result<()> {
async fn do_initialize(&mut self, path: &str, mode: ImageMode) -> Result<()> {
let mut app = self.app.lock().await;
app.initialized(mode);
app.initialized(path, mode);

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ use crate::image::ImageMode;

#[derive(Debug, Clone)]
pub enum IoEvent {
Initialize(ImageMode),
Initialize(String, ImageMode),
LoadImage,
}
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ use inputs::{events::Events, InputEvent};
use std::{io::stdout, sync::Arc, time::Duration};
use tui::{backend::CrosstermBackend, Terminal};

pub async fn start_ui<'a>(app: &Arc<tokio::sync::Mutex<App<'a>>>, mode: ImageMode) -> Result<()> {
pub async fn start_ui<'a>(
app: &Arc<tokio::sync::Mutex<App<'a>>>,
path: String,
mode: ImageMode,
) -> Result<()> {
let mut stdout = stdout();
enable_raw_mode()?;
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
Expand All @@ -33,7 +37,7 @@ pub async fn start_ui<'a>(app: &Arc<tokio::sync::Mutex<App<'a>>>, mode: ImageMod

{
let mut app = app.lock().await;
app.dispatch(IoEvent::Initialize(mode)).await;
app.dispatch(IoEvent::Initialize(path, mode)).await;
}

loop {
Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ fn tui_main(c: &Context) {
let app = Arc::new(tokio::sync::Mutex::new(App::new(sync_io_tx.clone())));
let app_ui = Arc::clone(&app);

let path = match c.args.len() {
1 => c.args[0].clone(),
_ => "./".to_string(),
};

let mode = if c.bool_flag("gray") {
ImageMode::GrayScale
} else {
Expand All @@ -70,6 +75,6 @@ fn tui_main(c: &Context) {
}
});

start_ui(&app_ui, mode).await.unwrap();
start_ui(&app_ui, path, mode).await.unwrap();
});
}

0 comments on commit 408b2a3

Please sign in to comment.