summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-12-11 21:07:13 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-12-11 21:07:13 -0500
commit916d72c42cfc7bcb8fc560e17cb3bd75c00757da (patch)
treea8024fc9bd9a48065cd6b65375109482ac9b7983 /src
parentbf9c102a4cfb85a9fd910195e6372dcd1d062c16 (diff)
add a view for showing worker progress
Diffstat (limited to 'src')
-rw-r--r--src/commands/key_command.rs4
-rw-r--r--src/commands/mod.rs1
-rw-r--r--src/commands/search.rs4
-rw-r--r--src/commands/show_workers.rs14
-rw-r--r--src/commands/tab_ops.rs2
-rw-r--r--src/context/context.rs27
-rw-r--r--src/context/tab_context.rs6
-rw-r--r--src/fs/entry.rs41
-rw-r--r--src/fs/metadata.rs23
-rw-r--r--src/io/io_observer.rs48
-rw-r--r--src/io/io_worker.rs111
-rw-r--r--src/run.rs3
-rw-r--r--src/ui/mod.rs1
-rw-r--r--src/ui/tui_backend.rs4
-rw-r--r--src/ui/views/mod.rs7
-rw-r--r--src/ui/views/tui_folder_view.rs (renamed from src/ui/widgets/tui_folder_view.rs)2
-rw-r--r--src/ui/views/tui_progress_view.rs (renamed from src/ui/widgets/tui_progress_view.rs)0
-rw-r--r--src/ui/views/tui_view.rs (renamed from src/ui/widgets/tui_view.rs)2
-rw-r--r--src/ui/views/tui_worker_view.rs55
-rw-r--r--src/ui/widgets/mod.rs8
-rw-r--r--src/ui/widgets/tui_dirlist_detailed.rs2
-rw-r--r--src/ui/widgets/tui_menu.rs4
-rw-r--r--src/ui/widgets/tui_prompt.rs5
-rw-r--r--src/ui/widgets/tui_textfield.rs19
-rw-r--r--src/ui/widgets/tui_worker.rs94
-rw-r--r--src/ui/widgets/tui_worker_view.rs79
-rw-r--r--src/util/format.rs5
-rw-r--r--src/util/worker.rs38
28 files changed, 365 insertions, 244 deletions
diff --git a/src/commands/key_command.rs b/src/commands/key_command.rs
index e5a2514..1c32470 100644
--- a/src/commands/key_command.rs
+++ b/src/commands/key_command.rs
@@ -51,6 +51,7 @@ pub enum KeyCommand {
SelectFiles { toggle: bool, all: bool },
SetMode,
ShellCommand(Vec<String>),
+ ShowWorkers,
ToggleHiddenFiles,
@@ -105,6 +106,7 @@ impl KeyCommand {
Self::SelectFiles { toggle: _, all: _ } => "select",
Self::SetMode => "set_mode",
Self::ShellCommand(_) => "shell",
+ Self::ShowWorkers => "show_workers",
Self::ToggleHiddenFiles => "toggle_hidden",
@@ -263,6 +265,7 @@ impl KeyCommand {
format!("{}: {}", arg, e),
)),
},
+ "show_workers" => Ok(Self::ShowWorkers),
"sort" => match arg {
"reverse" => Ok(Self::SortReverse),
arg => match SortType::parse(arg) {
@@ -341,6 +344,7 @@ impl JoshutoRunnable for KeyCommand {
Self::SelectFiles { toggle, all } => selection::select_files(context, *toggle, *all),
Self::SetMode => set_mode::set_mode(context, backend),
Self::ShellCommand(v) => shell::shell(context, backend, v.as_slice()),
+ Self::ShowWorkers => show_workers::show_workers(context, backend),
Self::ToggleHiddenFiles => show_hidden::toggle_hidden(context),
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 18b7579..eba4b99 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -16,6 +16,7 @@ pub mod selection;
pub mod set_mode;
pub mod shell;
pub mod show_hidden;
+pub mod show_workers;
pub mod sort;
pub mod tab_ops;
diff --git a/src/commands/search.rs b/src/commands/search.rs
index eba9650..168153e 100644
--- a/src/commands/search.rs
+++ b/src/commands/search.rs
@@ -38,7 +38,7 @@ pub fn _search_rev(curr_tab: &JoshutoTab, pattern: &str) -> Option<usize> {
pub fn search(context: &mut JoshutoContext, pattern: &str) -> JoshutoResult<()> {
let index = _search(context.tab_context_ref().curr_tab_ref(), pattern);
if let Some(index) = index {
- cursor_move::cursor_move(index, context);
+ let _ = cursor_move::cursor_move(index, context);
}
context.set_search_state(pattern.to_string());
Ok(())
@@ -51,7 +51,7 @@ fn search_with_func(
if let Some(s) = context.get_search_state() {
let index = search_func(context.tab_context_ref().curr_tab_ref(), s);
if let Some(index) = index {
- cursor_move::cursor_move(index, context);
+ let _ = cursor_move::cursor_move(index, context);
}
}
}
diff --git a/src/commands/show_workers.rs b/src/commands/show_workers.rs
new file mode 100644
index 0000000..04e6b84
--- /dev/null
+++ b/src/commands/show_workers.rs
@@ -0,0 +1,14 @@
+use crate::commands::KeyCommand;
+use crate::context::JoshutoContext;
+use crate::error::JoshutoResult;
+
+use crate::ui::views::TuiWorkerView;
+use crate::ui::TuiBackend;
+
+use super::JoshutoRunnable;
+
+pub fn show_workers(context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ let view = TuiWorkerView::new();
+ view.display(context, backend);
+ Ok(())
+}
diff --git a/src/commands/tab_ops.rs b/src/commands/tab_ops.rs
index 4bf415e..a5789cf 100644
--- a/src/commands/tab_ops.rs
+++ b/src/commands/tab_ops.rs
@@ -20,7 +20,7 @@ fn _tab_switch(new_index: usize, context: &mut JoshutoContext) -> std::io::Resul
.tab_context_mut()
.curr_tab_mut()
.history_mut()
- .create_or_soft_update(path.as_path(), &options);
+ .create_or_soft_update(path.as_path(), &options)?;
Ok(())
}
diff --git a/src/context/context.rs b/src/context/context.rs
index 904d18d..00fe233 100644
--- a/src/context/context.rs
+++ b/src/context/context.rs
@@ -1,10 +1,11 @@
+use std::collections::vec_deque::Iter;
use std::collections::VecDeque;
use std::sync::mpsc;
use std::thread;
use crate::config;
use crate::context::{LocalStateContext, TabContext};
-use crate::io::{IOWorkerObserver, IOWorkerThread};
+use crate::io::{IOWorkerObserver, IOWorkerProgress, IOWorkerThread};
use crate::util::event::{Event, Events};
pub struct JoshutoContext {
@@ -88,15 +89,27 @@ impl JoshutoContext {
pub fn worker_is_busy(&self) -> bool {
self.worker.is_some()
}
- pub fn worker_len(&self) -> usize {
- self.worker_queue.len()
- }
pub fn worker_is_empty(&self) -> bool {
self.worker_queue.is_empty()
}
- pub fn set_worker_msg(&mut self, msg: String) {
+
+ pub fn worker_iter(&self) -> Iter<IOWorkerThread> {
+ self.worker_queue.iter()
+ }
+
+ pub fn worker_ref(&self) -> Option<&IOWorkerObserver> {
+ self.worker.as_ref()
+ }
+
+ pub fn set_worker_progress(&mut self, res: IOWorkerProgress) {
+ if let Some(s) = self.worker.as_mut() {
+ s.set_progress(res);
+ }
+ }
+
+ pub fn update_worker_msg(&mut self) {
if let Some(s) = self.worker.as_mut() {
- s.set_msg(msg);
+ s.update_msg();
}
}
pub fn worker_msg(&self) -> Option<&str> {
@@ -116,7 +129,7 @@ impl JoshutoContext {
let worker_handle = thread::spawn(move || worker.start(wtx));
// relay worker info to event loop
while let Ok(progress) = wrx.recv() {
- tx.send(Event::IOWorkerProgress(progress));
+ let _ = tx.send(Event::IOWorkerProgress(progress));
}
let result = worker_handle.join();
diff --git a/src/context/tab_context.rs b/src/context/tab_context.rs
index 272e356..f199d4a 100644
--- a/src/context/tab_context.rs
+++ b/src/context/tab_context.rs
@@ -33,12 +33,6 @@ impl TabContext {
self.tabs.len()
}
- pub fn tab_ref(&self, i: usize) -> Option<&JoshutoTab> {
- if i >= self.tabs.len() {
- return None;
- }
- Some(&self.tabs[i])
- }
pub fn tab_mut(&mut self, i: usize) -> Option<&mut JoshutoTab> {
if i >= self.tabs.len() {
return None;
diff --git a/src/fs/entry.rs b/src/fs/entry.rs
index f39082a..4e06c0c 100644
--- a/src/fs/entry.rs
+++ b/src/fs/entry.rs
@@ -99,15 +99,12 @@ impl JoshutoDirEntry {
}
pub fn get_modifier(&self) -> Modifier {
- let metadata = &self.metadata;
- let filetype = &metadata.file_type;
+ let filetype = &self.metadata.file_type;
- if filetype.is_dir() {
- THEME_T.directory.modifier
- } else if filetype.is_symlink() {
- THEME_T.link.modifier
- } else {
- match self.file_path().extension() {
+ match filetype {
+ FileType::Directory => THEME_T.directory.modifier,
+ FileType::Symlink(_) => THEME_T.link.modifier,
+ _ => match self.file_path().extension() {
None => Modifier::empty(),
Some(os_str) => match os_str.to_str() {
None => Modifier::empty(),
@@ -116,7 +113,7 @@ impl JoshutoDirEntry {
Some(t) => t.modifier,
},
},
- }
+ },
}
}
@@ -124,28 +121,24 @@ impl JoshutoDirEntry {
let metadata = &self.metadata;
let filetype = &metadata.file_type;
- if self.is_selected() {
- Style::default()
+ match filetype {
+ _ if self.is_selected() => Style::default()
.fg(THEME_T.selection.fg)
.bg(THEME_T.selection.bg)
- .add_modifier(THEME_T.selection.modifier)
- } else if filetype.is_dir() {
- Style::default()
+ .add_modifier(THEME_T.selection.modifier),
+ FileType::Directory => Style::default()
.fg(THEME_T.directory.fg)
.bg(THEME_T.directory.bg)
- .add_modifier(THEME_T.directory.modifier)
- } else if filetype.is_symlink() {
- Style::default()
+ .add_modifier(THEME_T.directory.modifier),
+ FileType::Symlink(_) => Style::default()
.fg(THEME_T.link.fg)
.bg(THEME_T.link.bg)
- .add_modifier(THEME_T.link.modifier)
- } else if unix::is_executable(metadata.mode) {
- Style::default()
+ .add_modifier(THEME_T.link.modifier),
+ _ if unix::is_executable(metadata.mode) => Style::default()
.fg(THEME_T.executable.fg)
.bg(THEME_T.executable.bg)
- .add_modifier(THEME_T.executable.modifier)
- } else {
- match self.file_path().extension() {
+ .add_modifier(THEME_T.executable.modifier),
+ _ => match self.file_path().extension() {
None => Style::default(),
Some(os_str) => match os_str.to_str() {
None => Style::default(),
@@ -154,7 +147,7 @@ impl JoshutoDirEntry {
Some(t) => Style::default().fg(t.fg).bg(t.bg).add_modifier(t.modifier),
},
},
- }
+ },
}
}
}
diff --git a/src/fs/metadata.rs b/src/fs/metadata.rs
index 9a3fb60..e71f793 100644
--- a/src/fs/metadata.rs
+++ b/src/fs/metadata.rs
@@ -7,29 +7,6 @@ pub enum FileType {
File,
}
-impl FileType {
- pub fn is_dir(&self) -> bool {
- match *self {
- Self::Directory => true,
- _ => false,
- }
- }
-
- pub fn is_symlink(&self) -> bool {
- match *self {
- Self::Symlink(_) => true,
- _ => false,
- }
- }
-
- pub fn is_file(&self) -> bool {
- match *self {
- Self::File => true,
- _ => false,
- }
- }
-}
-
#[derive(Clone, Debug)]
pub struct JoshutoMetadata {
pub len: u64,
diff --git a/src/io/io_observer.rs b/src/io/io_observer.rs
index c882911..0648fbd 100644
--- a/src/io/io_observer.rs
+++ b/src/io/io_observer.rs
@@ -1,9 +1,13 @@
use std::path;
use std::thread;
+use crate::io::{FileOp, IOWorkerProgress};
+use crate::util::format;
+
#[derive(Debug)]
pub struct IOWorkerObserver {
pub handle: thread::JoinHandle<()>,
+ pub progress: Option<IOWorkerProgress>,
msg: String,
src: path::PathBuf,
dest: path::PathBuf,
@@ -13,25 +17,57 @@ impl IOWorkerObserver {
pub fn new(handle: thread::JoinHandle<()>, src: path::PathBuf, dest: path::PathBuf) -> Self {
Self {
handle,
+ progress: None,
src,
dest,
msg: String::new(),
}
}
- pub fn join(self) {
- self.handle.join();
+ pub fn join(self) -> bool {
+ match self.handle.join() {
+ Ok(_) => true,
+ _ => false,
+ }
}
- pub fn set_msg(&mut self, msg: String) {
- self.msg = msg
+ pub fn set_progress(&mut self, progress: IOWorkerProgress) {
+ self.progress = Some(progress);
+ }
+ pub fn update_msg(&mut self) {
+ match self.progress.as_ref() {
+ None => {}
+ Some(progress) => {
+ let size_str = format::file_size_to_string(progress.processed());
+ match progress.kind() {
+ FileOp::Cut => {
+ let msg = format!(
+ "moving ({}/{}) {} completed",
+ progress.index() + 1,
+ progress.len(),
+ size_str
+ );
+ self.msg = msg;
+ }
+ FileOp::Copy => {
+ let msg = format!(
+ "copying ({}/{}) {} completed",
+ progress.index() + 1,
+ progress.len(),
+ size_str
+ );
+ self.msg = msg;
+ }
+ }
+ }
+ }
}
pub fn get_msg(&self) -> &str {
self.msg.as_str()
}
- pub fn get_src_path(&self) -> &path::Path {
+ pub fn src_path(&self) -> &path::Path {
self.src.as_path()
}
- pub fn get_dest_path(&self) -> &path::Path {
+ pub fn dest_path(&self) -> &path::Path {
self.dest.as_path()
}
}
diff --git a/src/io/io_worker.rs b/src/io/io_worker.rs
index dbccc70..f44a2e6 100644
--- a/src/io/io_worker.rs
+++ b/src/io/io_worker.rs
@@ -37,15 +37,50 @@ impl std::fmt::Display for IOWorkerOptions {
#[derive(Clone, Debug)]
pub struct IOWorkerProgress {
- pub kind: FileOp,
- pub index: usize,
- pub len: usize,
- pub processed: u64,
+ _kind: FileOp,
+ _index: usize,
+ _len: usize,
+ _processed: u64,
+}
+
+impl IOWorkerProgress {
+ pub fn new(_kind: FileOp, _index: usize, _len: usize, _processed: u64) -> Self {
+ Self {
+ _kind,
+ _index,
+ _len,
+ _processed,
+ }
+ }
+
+ pub fn kind(&self) -> FileOp {
+ self._kind
+ }
+
+ pub fn index(&self) -> usize {
+ self._index
+ }
+
+ pub fn set_index(&mut self, _index: usize) {
+ self._index = _index;
+ }
+
+ pub fn len(&self) -> usize {
+ self._len
+ }
+
+ pub fn processed(&self) -> u64 {
+ self._processed
+ }
+
+ pub fn set_processed(&mut self, _processed: u64) {
+ self._processed = _processed;
+ }
}
#[derive(Debug)]
pub struct IOWorkerThread {
- pub kind: FileOp,
+ _kind: FileOp,
pub options: IOWorkerOptions,
pub paths: Vec<path::PathBuf>,
pub dest: path::PathBuf,
@@ -53,36 +88,35 @@ pub struct IOWorkerThread {
impl IOWorkerThread {
pub fn new(
- kind: FileOp,
+ _kind: FileOp,
paths: Vec<path::PathBuf>,
dest: path::PathBuf,
options: IOWorkerOptions,
) -> Self {
Self {
- kind,
+ _kind,
options,
paths,
dest,
}
}
+ pub fn kind(&self) -> FileOp {
+ self._kind
+ }
+
pub fn start(&self, tx: mpsc::Sender<IOWorkerProgress>) -> std::io::Result<IOWorkerProgress> {
- match self.kind {
+ match self.kind() {
FileOp::Cut => self.paste_cut(tx),
FileOp::Copy => self.paste_copy(tx),
}
}
fn paste_copy(&self, tx: mpsc::Sender<IOWorkerProgress>) -> std::io::Result<IOWorkerProgress> {
- let mut progress = IOWorkerProgress {
- kind: self.kind,
- index: 0,
- processed: 0,
- len: self.paths.len(),
- };
+ let mut progress = IOWorkerProgress::new(self.kind(), 0, self.paths.len(), 0);
for (i, path) in self.paths.iter().enumerate() {
- progress.index = i;
- tx.send(progress.clone());
+ progress.set_index(i);
+ let _ = tx.send(progress.clone());
self.recursive_copy(
path.as_path(),
self.dest.as_path(),
@@ -90,12 +124,12 @@ impl IOWorkerThread {
&mut progress,
)?;
}
- Ok(IOWorkerProgress {
- kind: self.kind,
- index: self.paths.len(),
- processed: progress.processed,
- len: self.paths.len(),
- })
+ Ok(IOWorkerProgress::new(
+ self.kind(),
+ self.paths.len(),
+ self.paths.len(),
+ progress.processed(),
+ ))
}
fn recursive_copy(
@@ -122,11 +156,11 @@ impl IOWorkerThread {
tx.clone(),
progress,
)?;
- tx.send(progress.clone());
+ let _ = tx.send(progress.clone());
}
Ok(())
} else if file_type.is_file() {
- progress.processed += fs::copy(src, dest_buf)?;
+ progress._processed += fs::copy(src, dest_buf)?;
Ok(())
} else if file_type.is_symlink() {
let link_path = fs::read_link(src)?;
@@ -138,15 +172,10 @@ impl IOWorkerThread {
}
fn paste_cut(&self, tx: mpsc::Sender<IOWorkerProgress>) -> std::io::Result<IOWorkerProgress> {
- let mut progress = IOWorkerProgress {
- kind: self.kind,
- index: 0,
- processed: 0,
- len: self.paths.len(),
- };
+ let mut progress = IOWorkerProgress::new(self.kind(), 0, self.paths.len(), 0);
for (i, path) in self.paths.iter().enumerate() {
- progress.index = i;
- tx.send(progress.clone());
+ progress.set_index(i);
+ let _ = tx.send(progress.clone());
self.recursive_cut(
path.as_path(),
self.dest.as_path(),
@@ -154,12 +183,12 @@ impl IOWorkerThread {
&mut progress,
)?;
}
- Ok(IOWorkerProgress {
- kind: self.kind,
- index: self.paths.len(),
- processed: progress.processed,
- len: self.paths.len(),
- })
+ Ok(IOWorkerProgress::new(
+ self.kind(),
+ self.paths.len(),
+ self.paths.len(),
+ progress.processed(),
+ ))
}
pub fn recursive_cut(
@@ -179,7 +208,7 @@ impl IOWorkerThread {
if file_type.is_dir() {
match fs::rename(src, dest_buf.as_path()) {
Ok(_) => {
- progress.processed += metadata.len();
+ progress._processed += metadata.len();
}
Err(_) => {
fs::create_dir(dest_buf.as_path())?;
@@ -199,13 +228,13 @@ impl IOWorkerThread {
if fs::rename(src, dest_buf.as_path()).is_err() {
fs::copy(src, dest_buf.as_path())?;
fs::remove_file(src)?;
- progress.processed += metadata.len();
+ progress._processed += metadata.len();
}
} else if file_type.is_symlink() {
let link_path = fs::read_link(src)?;
std::os::unix::fs::symlink(link_path, dest_buf)?;
fs::remove_file(src)?;
- progress.processed += metadata.len();
+ progress._processed += metadata.len();
}
Ok(())
}
diff --git a/src/run.rs b/src/run.rs
index a5524c7..496175e 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -3,7 +3,8 @@ use crate::config::{JoshutoCommandMapping, JoshutoConfig};
use crate::context::JoshutoContext;
use crate::tab::JoshutoTab;
use crate::ui;
-use crate::ui::widgets::{TuiCommandMenu, TuiView};
+use crate::ui::views::TuiView;
+use crate::ui::widgets::TuiCommandMenu;
use crate::util::event::Event;
use crate::util::load_child::LoadChild;
use crate::util::worker;
diff --git a/src/ui/mod.rs b/src/ui/mod.rs
index 844a70c..b5c98c8 100644
--- a/src/ui/mod.rs
+++ b/src/ui/mod.rs
@@ -1,6 +1,7 @@
use tui::layout::Constraint;
mod tui_backend;
+pub mod views;
pub mod widgets;
pub use tui_backend::*;
diff --git a/src/ui/tui_backend.rs b/src/ui/tui_backend.rs
index 395f081..2294737 100644
--- a/src/ui/tui_backend.rs
+++ b/src/ui/tui_backend.rs
@@ -30,7 +30,7 @@ impl TuiBackend {
where
W: Widget,
{
- self.terminal_mut().draw(|frame| {
+ let _ = self.terminal_mut().draw(|frame| {
let rect = frame.size();
frame.render_widget(widget, rect);
});
@@ -44,7 +44,7 @@ impl TuiBackend {
pub fn terminal_drop(&mut self) {
let _ = self.terminal.take();
- stdout().flush();
+ let _ = stdout().flush();
}
pub fn terminal_restore(&mut self) -> std::io::Result<()> {
diff --git a/src/ui/views/mod.rs b/src/ui/views/mod.rs
new file mode 100644
index 0000000..e6b1c41
--- /dev/null
+++ b/src/ui/views/mod.rs
@@ -0,0 +1,7 @@
+mod tui_folder_view;
+mod tui_view;
+mod tui_worker_view;
+
+pub use self::tui_folder_view::TuiFolderView;
+pub use self::tui_view::TuiView;
+pub use self::tui_worker_view::TuiWorkerView;
diff --git a/src/ui/widgets/tui_folder_view.rs b/src/ui/views/tui_folder_view.rs
index 01dcf2b..cd8283d 100644
--- a/src/ui/widgets/tui_folder_view.rs
+++ b/src/ui/views/tui_folder_view.rs
@@ -4,8 +4,8 @@ use tui::style::{Color, Style};
use tui::text::Span;
use tui::widgets::{Paragraph, Widget, Wrap};
-use super::{TuiDirList, TuiDirListDetailed, TuiFooter, TuiTabBar, TuiTopBar};
use crate::context::JoshutoContext;
+use crate::ui::widgets::{TuiDirList, TuiDirListDetailed, TuiFooter, TuiTabBar, TuiTopBar};
const TAB_VIEW_WIDTH: u16 = 15;
diff --git a/src/ui/widgets/tui_progress_view.rs b/src/ui/views/tui_progress_view.rs
index 9dad78f..9dad78f 100644
--- a/src/ui/widgets/tui_progress_view.rs
+++ b/src/ui/views/tui_progress_view.rs
diff --git a/src/ui/widgets/tui_view.rs b/src/ui/views/tui_view.rs
index f86eaec..81512b5 100644
--- a/src/ui/widgets/tui_view.rs
+++ b/src/ui/views/tui_view.rs
@@ -5,8 +5,6 @@ use tui::widgets::Widget;
use super::TuiFolderView;
use crate::context::JoshutoContext;
-const TAB_VIEW_WIDTH: u16 = 15;
-
pub struct TuiView<'a> {
pub context: &'a JoshutoContext,
pub show_bottom_status: bool,
diff --git a/src/ui/views/tui_worker_view.rs b/src/ui/views/tui_worker_view.rs
new file mode 100644
index 0000000..536c45a
--- /dev/null
+++ b/src/ui/views/tui_worker_view.rs
@@ -0,0 +1,55 @@
+use termion::event::Key;
+
+use tui::layout::Rect;
+
+use crate::context::JoshutoContext;
+use crate::ui::widgets::TuiWorker;
+use crate::ui::TuiBackend;
+use crate::util::event::Event;
+use crate::util::worker;
+
+pub struct TuiWorkerView {}
+
+impl TuiWorkerView {
+ pub fn new() -> Self {
+ Self {}
+ }
+
+ pub fn display(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) {
+ context.flush_event();
+ let terminal = backend.terminal_mut();
+
+ loop {
+ let _ = terminal.draw(|frame| {
+ let f_size: Rect = frame.size();
+ if f_size.height == 0 {
+ return;
+ }
+ {
+ let view = TuiWorker::new(&context);
+ frame.render_widget(view, f_size);
+ }
+ });
+
+ if let Ok(event) = context.poll_event() {
+ match event {
+ Event::IOWorkerProgress(res) => {
+ worker::process_worker_progress(context, res);
+ }
+ Event::IOWorkerResult(res) => {
+ worker::process_finished_worker(context, res);
+ }
+ Event::Input(key) => {
+ match key {
+ Key::Esc => {
+ break;
+ }
+ _ => {}
+ }
+ context.flush_event();
+ }
+ };
+ }
+ }
+ }
+}
diff --git a/src/ui/widgets/mod.rs b/src/ui/widgets/mod.rs
index fe756a3..b09b4df 100644
--- a/src/ui/widgets/mod.rs
+++ b/src/ui/widgets/mod.rs
@@ -1,23 +1,19 @@
mod tui_dirlist;
mod tui_dirlist_detailed;
-mod tui_folder_view;
mod tui_footer;
mod tui_menu;
mod tui_prompt;
mod tui_tab;
mod tui_textfield;
mod tui_topbar;
-mod tui_view;
-mod tui_worker_view;
+mod tui_worker;
pub use self::tui_dirlist::TuiDirList;
pub use self::tui_dirlist_detailed::TuiDirListDetailed;
-pub use self::tui_folder_view::TuiFolderView;
pub use self::tui_footer::TuiFooter;
pub use self::tui_menu::{TuiCommandMenu, TuiMenu};
pub use self::tui_prompt::TuiPrompt;
pub use self::tui_tab::TuiTabBar;
pub use self::tui_textfield::TuiTextField;
pub use self::tui_topbar::TuiTopBar;
-pub use self::tui_view::TuiView;
-pub use self::tui_worker_view::TuiWorkerView;
+pub use self::tui_worker::TuiWorker;
diff --git a/src/ui/widgets/tui_dirlist_detailed.rs b/src/ui/widgets/tui_dirlist_detailed.rs
index c76e198..70330c9 100644
--- a/src/ui/widgets/tui_dirlist_detailed.rs
+++ b/src/ui/widgets/tui_dirlist_detailed.rs
@@ -66,7 +66,7 @@ impl<'a> Widget for TuiDirListDetailed<'a> {
buf.set_string(x + area_width as u16 - 1, y + i as u16, "…", style);
}
}
- FileType::Symlink(p) => {
+ FileType::Symlink(_) => {
if name_width < area_width - 4 {
buf.set_string(x, y + i as u16, name, style);
buf.set_string(x + area_width as u16 - 4, y + i as u16, "->", style);
diff --git a/src/ui/widgets/tui_menu.rs b/src/ui/widgets/tui_menu.rs
index 80a3d3a..f7c9080 100644
--- a/src/ui/widgets/tui_menu.rs
+++ b/src/ui/widgets/tui_menu.rs
@@ -6,10 +6,10 @@ use tui::layout::Rect;
use tui::style::{Color, Style};
use tui::widgets::{Block, Borders, Clear, Widget};
-use super::TuiView;
use crate::commands::{CommandKeybind, KeyCommand};
use crate::config::JoshutoCommandMapping;
use crate::context::JoshutoContext;
+use crate::ui::views::TuiView;
use crate::ui::TuiBackend;
use crate::util::event::Event;
use crate::util::worker;
@@ -63,7 +63,7 @@ impl TuiCommandMenu {
context.flush_event();
loop {
- terminal.draw(|frame| {
+ let _ = terminal.draw(|frame| {
let f_size: Rect = frame.size();
{
diff --git a/src/ui/widgets/tui_prompt.rs b/src/ui/widgets/tui_prompt.rs
index ea6aa49..f520de9 100644
--- a/src/ui/widgets/tui_