Skip to content

Commit

Permalink
v0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ksk001100 committed Mar 23, 2022
1 parent ea7ca4b commit ddad36d
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 51 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.4"
version = "0.0.5"
authors = ["Keisuke Toyota <[email protected]>"]
edition = "2018"
repository = "https://github.com/ksk001100/picterm"
Expand Down
9 changes: 5 additions & 4 deletions src/app/actions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::inputs::key::Key;
use std::collections::HashMap;
use std::fmt;
use std::fmt::Display;
use std::slice::Iter;
use std::{
collections::HashMap,
fmt::{self, Display},
slice::Iter,
};

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum Action {
Expand Down
14 changes: 8 additions & 6 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ pub mod actions;
pub mod state;
pub mod ui;

use self::actions::Actions;
use self::state::AppState;
use crate::app::actions::Action;

use crate::inputs::key::Key;
use crate::io::IoEvent;
use crate::{
app::{
actions::{Action, Actions},
state::AppState,
},
inputs::key::Key,
io::IoEvent,
};

#[derive(Debug, PartialEq, Eq)]
pub enum AppReturn {
Expand Down
23 changes: 10 additions & 13 deletions src/app/ui.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use crate::app::state::AppState;
use crate::app::Actions;
use crate::app::App;

use crate::app::{state::AppState, Actions, App};
use byte_unit::Byte;
use tui::backend::Backend;
use tui::layout::{Alignment, Constraint, Direction, Layout, Rect};
use tui::style::{Color, Style};
use tui::text::Span;
use tui::widgets::{
Block, BorderType, Borders, Cell, List, ListItem, ListState, Paragraph, Row, Table,
use tui::{
backend::Backend,
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Color, Style},
text::Span,
widgets::{Block, BorderType, Borders, Cell, List, ListItem, ListState, Paragraph, Row, Table},
Frame,
};
use tui::Frame;

pub fn draw<B>(rect: &mut Frame<B>, app: &mut App)
where
Expand All @@ -34,7 +31,7 @@ where

let info_chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(70), Constraint::Percentage(30)].as_ref())
.constraints([Constraint::Percentage(20), Constraint::Percentage(80)].as_ref())
.split(header_chunks[1]);

let help = draw_help(app.actions());
Expand Down Expand Up @@ -103,7 +100,7 @@ fn draw_info<'a>(state: &AppState) -> Table<'a> {
.borders(Borders::ALL)
.border_type(BorderType::Plain),
)
.widths(&[Constraint::Length(20), Constraint::Percentage(80)])
.widths(&[Constraint::Length(15), Constraint::Percentage(85)])
.column_spacing(1)
}

Expand Down
15 changes: 8 additions & 7 deletions src/inputs/events.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use super::key::Key;
use super::InputEvent;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
use super::{key::Key, InputEvent};
use std::{
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
time::Duration,
};

pub struct Events {
rx: tokio::sync::mpsc::Receiver<InputEvent>,
Expand Down Expand Up @@ -39,12 +42,10 @@ impl Events {
}
}

/// Attempts to read an event.
pub async fn next(&mut self) -> InputEvent {
self.rx.recv().await.unwrap_or(InputEvent::Tick)
}

/// Close
pub fn close(&mut self) {
self.stop_capture.store(true, Ordering::Relaxed)
}
Expand Down
2 changes: 1 addition & 1 deletion src/inputs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod events;
pub mod key;

use self::key::Key;
use crate::inputs::key::Key;

pub enum InputEvent {
Input(Key),
Expand Down
15 changes: 9 additions & 6 deletions src/io/handler.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use super::IoEvent;
use crate::app::state::ImageInfo;
use crate::app::App;
use crate::image::image_fit_size;
use crate::{
app::{state::ImageInfo, App},
image::image_fit_size,
io::IoEvent,
};
use eyre::Result;
use image::{GenericImageView, Rgba};
use std::sync::Arc;
use tui::style::{Color, Style};
use tui::text::{Span, Spans};
use tui::{
style::{Color, Style},
text::{Span, Spans},
};

pub struct IoAsyncHandler<'a> {
app: Arc<tokio::sync::Mutex<App<'a>>>,
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ pub mod inputs;
pub mod io;
pub mod utils;

use crate::app::ui;
use app::{App, AppReturn};
use crate::{
app::{ui, App, AppReturn},
io::IoEvent,
};
use crossterm::{
event::{DisableMouseCapture, EnableMouseCapture},
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
use eyre::Result;
use inputs::{events::Events, InputEvent};
use io::IoEvent;
use std::{io::stdout, sync::Arc, time::Duration};
use tui::{backend::CrosstermBackend, Terminal};

Expand Down
13 changes: 6 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use eyre::Result;
use picterm::app::App;
use picterm::io::handler::IoAsyncHandler;
use picterm::io::IoEvent;
use picterm::start_ui;
use picterm::{
app::App,
io::{handler::IoAsyncHandler, IoEvent},
start_ui,
};
use seahorse::{App as SeahorseApp, Context};
use std::env;
use std::path::Path;
use std::sync::Arc;
use std::{env, path::Path, sync::Arc};

fn main() -> Result<()> {
let args = env::args().collect();
Expand Down
3 changes: 1 addition & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::fs;
use std::path::PathBuf;
use std::{fs, path::PathBuf};

pub fn get_image_paths(path: &str) -> Vec<PathBuf> {
static FILE_TYPES: [&str; 6] = ["png", "jpg", "jpeg", "webp", "bmp", "gif"];
Expand Down

0 comments on commit ddad36d

Please sign in to comment.