mirror of https://github.com/bobwen-dev/hunter
switch to parking_lot's Mutex/RwLock
This commit is contained in:
parent
16948dcec4
commit
a735747a27
|
@ -636,6 +636,7 @@ dependencies = [
|
||||||
"nix 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"nix 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"notify 4.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
"notify 4.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"osstrtools 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"osstrtools 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"parse-ansi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"parse-ansi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pathbuftools 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pathbuftools 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -759,6 +760,14 @@ dependencies = [
|
||||||
"scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lock_api"
|
||||||
|
version = "0.3.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.8"
|
version = "0.4.8"
|
||||||
|
@ -1024,6 +1033,15 @@ dependencies = [
|
||||||
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot"
|
||||||
|
version = "0.10.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"lock_api 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"parking_lot_core 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot_core"
|
name = "parking_lot_core"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
|
@ -1039,6 +1057,19 @@ dependencies = [
|
||||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot_core"
|
||||||
|
version = "0.7.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parse-ansi"
|
name = "parse-ansi"
|
||||||
version = "0.1.6"
|
version = "0.1.6"
|
||||||
|
@ -1427,6 +1458,11 @@ dependencies = [
|
||||||
"maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "smallvec"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strip-ansi-escapes"
|
name = "strip-ansi-escapes"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -1789,6 +1825,7 @@ dependencies = [
|
||||||
"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
|
"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
|
||||||
"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
|
"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
|
||||||
"checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff"
|
"checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff"
|
||||||
|
"checksum lock_api 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75"
|
||||||
"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
|
"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
|
||||||
"checksum lscolors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea3b3414b2d015c4fd689815f2551797f3c2296bb241dd709c7da233ec7cba4b"
|
"checksum lscolors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea3b3414b2d015c4fd689815f2551797f3c2296bb241dd709c7da233ec7cba4b"
|
||||||
"checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084"
|
"checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084"
|
||||||
|
@ -1820,8 +1857,10 @@ dependencies = [
|
||||||
"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
|
"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
|
||||||
"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
|
"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
|
||||||
"checksum osstrtools 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7acb1f1b0af8b54107dc46ca4579bae0df3663e8501849201af732c3c0bd0d94"
|
"checksum osstrtools 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7acb1f1b0af8b54107dc46ca4579bae0df3663e8501849201af732c3c0bd0d94"
|
||||||
|
"checksum parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e"
|
||||||
"checksum parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa7767817701cce701d5585b9c4db3cdd02086398322c1d7e8bf5094a96a2ce7"
|
"checksum parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa7767817701cce701d5585b9c4db3cdd02086398322c1d7e8bf5094a96a2ce7"
|
||||||
"checksum parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb88cb1cb3790baa6776844f968fea3be44956cf184fa1be5a03341f5491278c"
|
"checksum parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb88cb1cb3790baa6776844f968fea3be44956cf184fa1be5a03341f5491278c"
|
||||||
|
"checksum parking_lot_core 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3"
|
||||||
"checksum parse-ansi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "50c48b4d524f8a10bf6ab37dc0b7583f17c8ec88b617b364ddfc3baee4dcf878"
|
"checksum parse-ansi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "50c48b4d524f8a10bf6ab37dc0b7583f17c8ec88b617b364ddfc3baee4dcf878"
|
||||||
"checksum pathbuftools 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "00f002a88874c85e30d4e133baae43cf382ceecf025f9493ce23eb381fcc922e"
|
"checksum pathbuftools 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "00f002a88874c85e30d4e133baae43cf382ceecf025f9493ce23eb381fcc922e"
|
||||||
"checksum petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f"
|
"checksum petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f"
|
||||||
|
@ -1868,6 +1907,7 @@ dependencies = [
|
||||||
"checksum sixel-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fb46e0cd5569bf910390844174a5a99d52dd40681fff92228d221d9f8bf87dea"
|
"checksum sixel-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fb46e0cd5569bf910390844174a5a99d52dd40681fff92228d221d9f8bf87dea"
|
||||||
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
|
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
|
||||||
"checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6"
|
"checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6"
|
||||||
|
"checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4"
|
||||||
"checksum strip-ansi-escapes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d63676e2abafa709460982ddc02a3bb586b6d15a49b75c212e06edd3933acee"
|
"checksum strip-ansi-escapes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d63676e2abafa709460982ddc02a3bb586b6d15a49b75c212e06edd3933acee"
|
||||||
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||||
"checksum strum 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e5d1c33039533f051704951680f1adfd468fd37ac46816ded0d9ee068e60f05f"
|
"checksum strum 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e5d1c33039533f051704951680f1adfd468fd37ac46816ded0d9ee068e60f05f"
|
||||||
|
|
|
@ -46,6 +46,7 @@ itertools = "0.8"
|
||||||
nix = "0.17"
|
nix = "0.17"
|
||||||
strip-ansi-escapes = "0.1"
|
strip-ansi-escapes = "0.1"
|
||||||
crossbeam = "0.7"
|
crossbeam = "0.7"
|
||||||
|
parking_lot = "0.10"
|
||||||
|
|
||||||
|
|
||||||
image = { version = "0.21.1", optional = true }
|
image = { version = "0.21.1", optional = true }
|
||||||
|
|
|
@ -5,9 +5,10 @@ use failure::Fail;
|
||||||
|
|
||||||
|
|
||||||
use termion::event::Key;
|
use termion::event::Key;
|
||||||
|
use parking_lot::Mutex;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::foldview::LogEntry;
|
use crate::foldview::LogEntry;
|
||||||
use crate::mediaview::MediaError;
|
use crate::mediaview::MediaError;
|
||||||
|
@ -191,12 +192,12 @@ lazy_static! {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_logs() -> HResult<Vec<LogEntry>> {
|
pub fn get_logs() -> HResult<Vec<LogEntry>> {
|
||||||
let logs = LOG.lock()?.drain(..).collect();
|
let logs = LOG.lock().drain(..).collect();
|
||||||
Ok(logs)
|
Ok(logs)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn put_log<L: Into<LogEntry>>(log: L) -> HResult<()> {
|
pub fn put_log<L: Into<LogEntry>>(log: L) -> HResult<()> {
|
||||||
LOG.lock()?.push(log.into());
|
LOG.lock().push(log.into());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
use termion::event::Key;
|
use termion::event::Key;
|
||||||
|
use parking_lot::{Mutex, RwLock};
|
||||||
|
|
||||||
use pathbuftools::PathBufTools;
|
use pathbuftools::PathBufTools;
|
||||||
use osstrtools::OsStrTools;
|
use osstrtools::OsStrTools;
|
||||||
use async_value::Stale;
|
use async_value::Stale;
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::sync::{Arc, Mutex, RwLock};
|
use std::sync::Arc;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::os::unix::ffi::OsStringExt;
|
use std::os::unix::ffi::OsStringExt;
|
||||||
|
@ -193,8 +195,15 @@ impl Tabbable for TabView<FileBrowser> {
|
||||||
dirs
|
dirs
|
||||||
});
|
});
|
||||||
|
|
||||||
self.active_tab_mut_().fs_cache.watch_only(open_dirs).log();
|
self.active_tab_mut_()
|
||||||
self.active_tab_mut_().fs_stat.write()?.refresh().log();
|
.fs_cache
|
||||||
|
.watch_only(open_dirs)
|
||||||
|
.log();
|
||||||
|
self.active_tab_mut_()
|
||||||
|
.fs_stat
|
||||||
|
.write()
|
||||||
|
.refresh()
|
||||||
|
.log();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,7 +470,9 @@ impl FileBrowser {
|
||||||
tab_paths: None
|
tab_paths: None
|
||||||
};
|
};
|
||||||
|
|
||||||
self.proc_view.lock()?.run_proc_raw(cmd)?;
|
self.proc_view
|
||||||
|
.lock()
|
||||||
|
.run_proc_raw(cmd)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -618,10 +629,15 @@ impl FileBrowser {
|
||||||
None => &self.cwd
|
None => &self.cwd
|
||||||
}.path.to_string_lossy().to_string();
|
}.path.to_string_lossy().to_string();
|
||||||
|
|
||||||
self.bookmarks.lock()?.set_coordinates(&self.core.coordinates).log();
|
self.bookmarks
|
||||||
|
.lock()
|
||||||
|
.set_coordinates(&self.core.coordinates)
|
||||||
|
.log();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let bookmark = self.bookmarks.lock()?.pick(cwd.to_string());
|
let bookmark = self.bookmarks
|
||||||
|
.lock()
|
||||||
|
.pick(cwd.to_string());
|
||||||
|
|
||||||
if let Err(HError::TerminalResizedError) = bookmark {
|
if let Err(HError::TerminalResizedError) = bookmark {
|
||||||
self.core.screen.clear().log();
|
self.core.screen.clear().log();
|
||||||
|
@ -633,7 +649,10 @@ impl FileBrowser {
|
||||||
|
|
||||||
if let Err(HError::WidgetResizedError) = bookmark {
|
if let Err(HError::WidgetResizedError) = bookmark {
|
||||||
let coords = &self.core.coordinates;
|
let coords = &self.core.coordinates;
|
||||||
self.bookmarks.lock()?.set_coordinates(&coords).log();
|
self.bookmarks
|
||||||
|
.lock()
|
||||||
|
.set_coordinates(&coords)
|
||||||
|
.log();
|
||||||
self.core.screen.clear().log();
|
self.core.screen.clear().log();
|
||||||
self.refresh().log();
|
self.refresh().log();
|
||||||
self.draw().log();
|
self.draw().log();
|
||||||
|
@ -660,8 +679,14 @@ impl FileBrowser {
|
||||||
pub fn add_bookmark(&mut self) -> HResult<()> {
|
pub fn add_bookmark(&mut self) -> HResult<()> {
|
||||||
let cwd = self.cwd.path.to_string_lossy().to_string();
|
let cwd = self.cwd.path.to_string_lossy().to_string();
|
||||||
let coords = &self.core.coordinates;
|
let coords = &self.core.coordinates;
|
||||||
self.bookmarks.lock()?.set_coordinates(&coords).log();
|
|
||||||
self.bookmarks.lock()?.add(&cwd)?;
|
self.bookmarks
|
||||||
|
.lock()
|
||||||
|
.set_coordinates(&coords)
|
||||||
|
.log();
|
||||||
|
self.bookmarks
|
||||||
|
.lock()
|
||||||
|
.add(&cwd)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1074,7 +1099,8 @@ impl FileBrowser {
|
||||||
fn external_select(&mut self) -> HResult<()> {
|
fn external_select(&mut self) -> HResult<()> {
|
||||||
let shell = std::env::var("SHELL").unwrap_or("bash".into());
|
let shell = std::env::var("SHELL").unwrap_or("bash".into());
|
||||||
let cmd = self.core
|
let cmd = self.core
|
||||||
.config.read()?
|
.config
|
||||||
|
.read()
|
||||||
.get()?
|
.get()?
|
||||||
.select_cmd
|
.select_cmd
|
||||||
.clone();
|
.clone();
|
||||||
|
@ -1182,7 +1208,8 @@ impl FileBrowser {
|
||||||
fn external_cd(&mut self) -> HResult<()> {
|
fn external_cd(&mut self) -> HResult<()> {
|
||||||
let shell = std::env::var("SHELL").unwrap_or("bash".into());
|
let shell = std::env::var("SHELL").unwrap_or("bash".into());
|
||||||
let cmd = self.core
|
let cmd = self.core
|
||||||
.config.read()?
|
.config
|
||||||
|
.read()
|
||||||
.get()?
|
.get()?
|
||||||
.cd_cmd
|
.cd_cmd
|
||||||
.clone();
|
.clone();
|
||||||
|
@ -1272,7 +1299,9 @@ impl FileBrowser {
|
||||||
tab_paths: Some(tab_dirs)
|
tab_paths: Some(tab_dirs)
|
||||||
};
|
};
|
||||||
|
|
||||||
self.proc_view.lock()?.run_proc_subshell(cmd)?;
|
self.proc_view
|
||||||
|
.lock()
|
||||||
|
.run_proc_subshell(cmd)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1309,7 +1338,7 @@ impl FileBrowser {
|
||||||
self.preview_widget().map(|preview| preview.cancel_animation()).log();
|
self.preview_widget().map(|preview| preview.cancel_animation()).log();
|
||||||
let procview = self.proc_view.clone();
|
let procview = self.proc_view.clone();
|
||||||
loop {
|
loop {
|
||||||
match procview.lock()?.popup() {
|
match procview.lock().popup() {
|
||||||
// Ignore refresh
|
// Ignore refresh
|
||||||
Err(HError::RefreshParent) => continue,
|
Err(HError::RefreshParent) => continue,
|
||||||
Err(HError::TerminalResizedError) |
|
Err(HError::TerminalResizedError) |
|
||||||
|
@ -1323,7 +1352,9 @@ impl FileBrowser {
|
||||||
pub fn show_log(&mut self) -> HResult<()> {
|
pub fn show_log(&mut self) -> HResult<()> {
|
||||||
self.preview_widget().map(|preview| preview.cancel_animation()).log();
|
self.preview_widget().map(|preview| preview.cancel_animation()).log();
|
||||||
loop {
|
loop {
|
||||||
let res = self.log_view.lock()?.popup();
|
let res = self.log_view
|
||||||
|
.lock()
|
||||||
|
.popup();
|
||||||
|
|
||||||
if let Err(HError::RefreshParent) = res {
|
if let Err(HError::RefreshParent) = res {
|
||||||
continue
|
continue
|
||||||
|
@ -1382,7 +1413,10 @@ impl FileBrowser {
|
||||||
let count_xpos = xsize - file_count.len() as u16;
|
let count_xpos = xsize - file_count.len() as u16;
|
||||||
let count_ypos = ypos + self.get_coordinates()?.ysize();
|
let count_ypos = ypos + self.get_coordinates()?.ysize();
|
||||||
|
|
||||||
let fs = self.fs_stat.read()?.find_fs(&file.path)?.clone();
|
let fs = self.fs_stat
|
||||||
|
.read()
|
||||||
|
.find_fs(&file.path)?
|
||||||
|
.clone();
|
||||||
|
|
||||||
let dev = fs.get_dev().unwrap_or(String::from(""));
|
let dev = fs.get_dev().unwrap_or(String::from(""));
|
||||||
let free_space = fs.get_free();
|
let free_space = fs.get_free();
|
||||||
|
@ -1429,9 +1463,19 @@ impl Widget for FileBrowser {
|
||||||
fn set_coordinates(&mut self, coordinates: &Coordinates) -> HResult<()> {
|
fn set_coordinates(&mut self, coordinates: &Coordinates) -> HResult<()> {
|
||||||
self.core.coordinates = coordinates.clone();
|
self.core.coordinates = coordinates.clone();
|
||||||
self.columns.set_coordinates(&coordinates).log();
|
self.columns.set_coordinates(&coordinates).log();
|
||||||
self.proc_view.lock()?.set_coordinates(&coordinates).log();
|
|
||||||
self.log_view.lock()?.set_coordinates(&coordinates).log();
|
self.proc_view
|
||||||
self.bookmarks.lock()?.set_coordinates(&coordinates).log();
|
.lock()
|
||||||
|
.set_coordinates(&coordinates)
|
||||||
|
.log();
|
||||||
|
self.log_view
|
||||||
|
.lock()
|
||||||
|
.set_coordinates(&coordinates)
|
||||||
|
.log();
|
||||||
|
self.bookmarks
|
||||||
|
.lock()
|
||||||
|
.set_coordinates(&coordinates)
|
||||||
|
.log();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1468,7 +1512,7 @@ impl Widget for FileBrowser {
|
||||||
let xsize = term::xsize_u();
|
let xsize = term::xsize_u();
|
||||||
let mut status = self.get_core()?
|
let mut status = self.get_core()?
|
||||||
.status_bar_content
|
.status_bar_content
|
||||||
.lock()?;
|
.lock();
|
||||||
let status = status.as_mut()
|
let status = status.as_mut()
|
||||||
.take();
|
.take();
|
||||||
let active = self.columns
|
let active = self.columns
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use lazy_static;
|
use lazy_static;
|
||||||
use termion::event::Key;
|
use termion::event::Key;
|
||||||
use failure::{self, Fail};
|
use failure::{self, Fail};
|
||||||
|
use parking_lot::{Mutex, RwLock};
|
||||||
|
|
||||||
use crate::widget::{Widget, WidgetCore};
|
use crate::widget::{Widget, WidgetCore};
|
||||||
use crate::coordinates::Coordinates;
|
use crate::coordinates::Coordinates;
|
||||||
|
@ -9,7 +10,7 @@ use crate::fail::{HResult, HError, ErrorLog, ErrorCause};
|
||||||
use crate::imgview::ImgView;
|
use crate::imgview::ImgView;
|
||||||
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::{Arc, Mutex, RwLock,
|
use std::sync::{Arc,
|
||||||
mpsc::{channel, Sender}};
|
mpsc::{channel, Sender}};
|
||||||
|
|
||||||
use std::io::{BufRead, BufReader, Write};
|
use std::io::{BufRead, BufReader, Write};
|
||||||
|
@ -120,7 +121,7 @@ impl MediaView {
|
||||||
// Use current size. Widget could have been resized at some point
|
// Use current size. Widget could have been resized at some point
|
||||||
let (xsize, ysize, xpix, ypix) =
|
let (xsize, ysize, xpix, ypix) =
|
||||||
{
|
{
|
||||||
let view = thread_imgview.lock()?;
|
let view = thread_imgview.lock();
|
||||||
let (xsize, ysize) = view.core.coordinates.size_u();
|
let (xsize, ysize) = view.core.coordinates.size_u();
|
||||||
let (xpix, ypix) = view.core.coordinates.size_pixels()?;
|
let (xpix, ypix) = view.core.coordinates.size_pixels()?;
|
||||||
(xsize, ysize, xpix, ypix)
|
(xsize, ysize, xpix, ypix)
|
||||||
|
@ -159,7 +160,7 @@ impl MediaView {
|
||||||
let mut stdout = BufReader::new(previewer.stdout.take()?);
|
let mut stdout = BufReader::new(previewer.stdout.take()?);
|
||||||
let mut stdin = previewer.stdin.take()?;
|
let mut stdin = previewer.stdin.take()?;
|
||||||
|
|
||||||
cprocess.lock().map(|mut p| *p = Some(previewer))?;
|
*cprocess.lock() = Some(previewer);
|
||||||
|
|
||||||
let mut frame = vec![];
|
let mut frame = vec![];
|
||||||
let newline = String::from("\n");
|
let newline = String::from("\n");
|
||||||
|
@ -167,7 +168,7 @@ impl MediaView {
|
||||||
let rx_cmd = rx_cmd.clone();
|
let rx_cmd = rx_cmd.clone();
|
||||||
|
|
||||||
std::thread::spawn(move || -> HResult<()> {
|
std::thread::spawn(move || -> HResult<()> {
|
||||||
for cmd in rx_cmd.lock()?.iter() {
|
for cmd in rx_cmd.lock().iter() {
|
||||||
write!(stdin, "{}", cmd)?;
|
write!(stdin, "{}", cmd)?;
|
||||||
write!(stdin, "\n")?;
|
write!(stdin, "\n")?;
|
||||||
stdin.flush()?;
|
stdin.flush()?;
|
||||||
|
@ -177,9 +178,10 @@ impl MediaView {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Check if preview-gen finished and break out of loop to restart
|
// Check if preview-gen finished and break out of loop to restart
|
||||||
if let Ok(Some(code)) = cprocess.lock()?
|
if let Ok(Some(code)) = cprocess.lock()
|
||||||
.as_mut()?
|
.as_mut()?
|
||||||
.try_wait() {
|
.try_wait()
|
||||||
|
{
|
||||||
if code.success() {
|
if code.success() {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
@ -200,7 +202,7 @@ impl MediaView {
|
||||||
stdout.read_line(&mut line_buf)?;
|
stdout.read_line(&mut line_buf)?;
|
||||||
let h = line_buf.trim().parse::<usize>()?;
|
let h = line_buf.trim().parse::<usize>()?;
|
||||||
|
|
||||||
let mut height = height.lock().unwrap();
|
let mut height = height.lock();
|
||||||
if *height != h {
|
if *height != h {
|
||||||
new_height = true;
|
new_height = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -212,18 +214,18 @@ impl MediaView {
|
||||||
line_buf.clear();
|
line_buf.clear();
|
||||||
stdout.read_line(&mut line_buf)?;
|
stdout.read_line(&mut line_buf)?;
|
||||||
let pos = &line_buf.trim();
|
let pos = &line_buf.trim();
|
||||||
*position.lock().unwrap() = pos
|
*position.lock() = pos
|
||||||
.parse::<usize>()?;
|
.parse::<usize>()?;
|
||||||
|
|
||||||
|
|
||||||
line_buf.clear();
|
line_buf.clear();
|
||||||
stdout.read_line(&mut line_buf)?;
|
stdout.read_line(&mut line_buf)?;
|
||||||
let dur = &line_buf.trim();
|
let dur = &line_buf.trim();
|
||||||
*duration.lock().unwrap() = dur
|
*duration.lock() = dur
|
||||||
.parse::<usize>()?;
|
.parse::<usize>()?;
|
||||||
|
|
||||||
|
|
||||||
if let Ok(mut imgview) = thread_imgview.lock() {
|
let mut imgview = thread_imgview.lock();
|
||||||
if new_height {
|
if new_height {
|
||||||
imgview.core.clear()?;
|
imgview.core.clear()?;
|
||||||
}
|
}
|
||||||
|
@ -231,7 +233,6 @@ impl MediaView {
|
||||||
sender.send(crate::widget::Events::WidgetReady)
|
sender.send(crate::widget::Events::WidgetReady)
|
||||||
.map_err(|e| HError::from(e))
|
.map_err(|e| HError::from(e))
|
||||||
.log();
|
.log();
|
||||||
}
|
|
||||||
|
|
||||||
line_buf.clear();
|
line_buf.clear();
|
||||||
frame = vec![];
|
frame = vec![];
|
||||||
|
@ -304,8 +305,8 @@ impl MediaView {
|
||||||
pub fn progress_bar(&self) -> HResult<String> {
|
pub fn progress_bar(&self) -> HResult<String> {
|
||||||
let xsize = self.core.coordinates.xsize_u();
|
let xsize = self.core.coordinates.xsize_u();
|
||||||
|
|
||||||
let position = self.position.lock()?.clone();
|
let position = self.position.lock().clone();
|
||||||
let duration = self.duration.lock()?.clone();
|
let duration = self.duration.lock().clone();
|
||||||
|
|
||||||
if duration == 0 || position == 0 {
|
if duration == 0 || position == 0 {
|
||||||
Ok(format!("{:elements$}", "|", elements=xsize))
|
Ok(format!("{:elements$}", "|", elements=xsize))
|
||||||
|
@ -323,8 +324,8 @@ impl MediaView {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn progress_string(&self) -> HResult<String> {
|
pub fn progress_string(&self) -> HResult<String> {
|
||||||
let position = self.position.lock()?.clone();
|
let position = self.position.lock().clone();
|
||||||
let duration = self.duration.lock()?.clone();
|
let duration = self.duration.lock().clone();
|
||||||
|
|
||||||
let fposition = self.format_secs(position);
|
let fposition = self.format_secs(position);
|
||||||
let fduration = self.format_secs(duration);
|
let fduration = self.format_secs(duration);
|
||||||
|
@ -342,7 +343,7 @@ impl MediaView {
|
||||||
|
|
||||||
let mut icons = String::new();
|
let mut icons = String::new();
|
||||||
|
|
||||||
if *MUTE.read()? == true {
|
if *MUTE.read() == true {
|
||||||
icons += &crate::term::goto_xy_u(xpos+xsize-2, ypos+lines);
|
icons += &crate::term::goto_xy_u(xpos+xsize-2, ypos+lines);
|
||||||
icons += mute_char;
|
icons += mute_char;
|
||||||
} else {
|
} else {
|
||||||
|
@ -351,7 +352,7 @@ impl MediaView {
|
||||||
icons += " ";
|
icons += " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if *AUTOPLAY.read()? == true {
|
if *AUTOPLAY.read() == true {
|
||||||
icons += &crate::term::goto_xy_u(xpos+xsize-4, ypos+lines);
|
icons += &crate::term::goto_xy_u(xpos+xsize-4, ypos+lines);
|
||||||
icons += play_char;
|
icons += play_char;
|
||||||
} else {
|
} else {
|
||||||
|
@ -371,8 +372,8 @@ impl MediaView {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_pause(&mut self) -> HResult<()> {
|
pub fn toggle_pause(&mut self) -> HResult<()> {
|
||||||
let auto = AUTOPLAY.read()?.clone();
|
let auto = AUTOPLAY.read().clone();
|
||||||
let pos = self.position.lock()?.clone();
|
let pos = self.position.lock().clone();
|
||||||
|
|
||||||
// This combination means only first frame was shown, since
|
// This combination means only first frame was shown, since
|
||||||
// self.paused will be false, even with autoplay off
|
// self.paused will be false, even with autoplay off
|
||||||
|
@ -410,27 +411,19 @@ impl MediaView {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn autoplay(&self) -> bool {
|
pub fn autoplay(&self) -> bool {
|
||||||
if let Ok(autoplay) = AUTOPLAY.read() {
|
*AUTOPLAY.read()
|
||||||
return *autoplay;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mute(&self) -> bool {
|
pub fn mute(&self) -> bool {
|
||||||
if let Ok(mute) = MUTE.read() {
|
*MUTE.read()
|
||||||
return *mute;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_autoplay(&self) {
|
pub fn toggle_autoplay(&self) {
|
||||||
if let Ok(mut autoplay) = AUTOPLAY.write() {
|
*AUTOPLAY.write() = !*AUTOPLAY.read();
|
||||||
*autoplay = !*autoplay;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_mute(&self) {
|
pub fn toggle_mute(&self) {
|
||||||
if let Ok(mut mute) = MUTE.write() {
|
let mut mute = MUTE.write();
|
||||||
*mute = !*mute;
|
*mute = !*mute;
|
||||||
if *mute {
|
if *mute {
|
||||||
self.controller.send(String::from("m")).ok();
|
self.controller.send(String::from("m")).ok();
|
||||||
|
@ -438,12 +431,11 @@ impl MediaView {
|
||||||
self.controller.send(String::from("u")).ok();
|
self.controller.send(String::from("u")).ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn kill(&mut self) -> HResult<()> {
|
pub fn kill(&mut self) -> HResult<()> {
|
||||||
let proc = self.process.clone();
|
let proc = self.process.clone();
|
||||||
std::thread::spawn(move || -> HResult<()> {
|
std::thread::spawn(move || -> HResult<()> {
|
||||||
proc.lock()?
|
proc.lock()
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
p.kill().map_err(|e| HError::from(e)).log();
|
p.kill().map_err(|e| HError::from(e)).log();
|
||||||
|
@ -470,7 +462,7 @@ impl Widget for MediaView {
|
||||||
|
|
||||||
self.core.coordinates = coordinates.clone();
|
self.core.coordinates = coordinates.clone();
|
||||||
|
|
||||||
let mut imgview = self.imgview.lock()?;
|
let mut imgview = self.imgview.lock();
|
||||||
imgview.set_image_data(vec![]);
|
imgview.set_image_data(vec![]);
|
||||||
imgview.set_coordinates(&coordinates)?;
|
imgview.set_coordinates(&coordinates)?;
|
||||||
|
|
||||||
|
@ -497,13 +489,13 @@ impl Widget for MediaView {
|
||||||
|
|
||||||
fn get_drawlist(&self) -> HResult<String> {
|
fn get_drawlist(&self) -> HResult<String> {
|
||||||
let (xpos, ypos) = self.core.coordinates.position_u();
|
let (xpos, ypos) = self.core.coordinates.position_u();
|
||||||
let height = *self.height.lock()?;
|
let height = *self.height.lock();
|
||||||
let progress_str = self.progress_string()?;
|
let progress_str = self.progress_string()?;
|
||||||
let progress_bar = self.progress_bar()?;
|
let progress_bar = self.progress_bar()?;
|
||||||
|
|
||||||
let frame = self.imgview
|
let frame = self.imgview
|
||||||
.lock()
|
.lock()
|
||||||
.map(|img| img.get_drawlist())?;
|
.get_drawlist();
|
||||||
|
|
||||||
let mut frame = frame?;
|
let mut frame = frame?;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use async_value::{Async, Stale};
|
use async_value::{Async, Stale};
|
||||||
use termion::event::Key;
|
use termion::event::Key;
|
||||||
|
use parking_lot::Mutex;
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
|
||||||
|
use std::sync::Arc;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::files::{File, Files, Kind, Ticker};
|
use crate::files::{File, Files, Kind, Ticker};
|
||||||
|
@ -26,7 +28,7 @@ fn kill_proc() -> HResult<()> {
|
||||||
// Kill media previewer if it still runs
|
// Kill media previewer if it still runs
|
||||||
ImgView::kill_running();
|
ImgView::kill_running();
|
||||||
|
|
||||||
let mut pid = SUBPROC.lock()?;
|
let mut pid = SUBPROC.lock();
|
||||||
pid.map(|pid|
|
pid.map(|pid|
|
||||||
// Do this in another thread so we can wait on process to exit with SIGHUP
|
// Do this in another thread so we can wait on process to exit with SIGHUP
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
|
@ -75,7 +77,10 @@ impl<W: Widget + Send + 'static> AsyncWidget<W> {
|
||||||
closure(stale).map_err(|e| e.into()));
|
closure(stale).map_err(|e| e.into()));
|
||||||
widget.on_ready(move |_, stale| {
|
widget.on_ready(move |_, stale| {
|
||||||
if !stale.is_stale()? {
|
if !stale.is_stale()? {
|
||||||
sender.lock().map(|s| s.send(crate::widget::Events::WidgetReady)).ok();
|
sender.lock()
|
||||||
|
.send(crate::widget::Events::WidgetReady)
|
||||||
|
.map_err(HError::from)
|
||||||
|
.log();
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}).log();
|
}).log();
|
||||||
|
@ -104,8 +109,9 @@ impl<W: Widget + Send + 'static> AsyncWidget<W> {
|
||||||
widget.on_ready(move |_, stale| {
|
widget.on_ready(move |_, stale| {
|
||||||
if !stale.is_stale()? {
|
if !stale.is_stale()? {
|
||||||
sender.lock()
|
sender.lock()
|
||||||
.map(|s| s.send(crate::widget::Events::WidgetReady))
|
.send(crate::widget::Events::WidgetReady)
|
||||||
.ok();
|
.map_err(HError::from)
|
||||||
|
.log();
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}).log();
|
}).log();
|
||||||
|
@ -539,7 +545,7 @@ impl Previewer {
|
||||||
|
|
||||||
let pid = process.id();
|
let pid = process.id();
|
||||||
{
|
{
|
||||||
let mut pid_ = SUBPROC.lock()?;
|
let mut pid_ = SUBPROC.lock();
|
||||||
*pid_ = Some(pid);
|
*pid_ = Some(pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -548,7 +554,7 @@ impl Previewer {
|
||||||
if stale.is_stale()? { return Previewer::preview_failed(&file) }
|
if stale.is_stale()? { return Previewer::preview_failed(&file) }
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut pid_ = SUBPROC.lock()?;
|
let mut pid_ = SUBPROC.lock();
|
||||||
*pid_ = None;
|
*pid_ = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::Arc;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use std::process::{Child, Command};
|
use std::process::{Child, Command};
|
||||||
use std::os::unix::process::{CommandExt, ExitStatusExt};
|
use std::os::unix::process::{CommandExt, ExitStatusExt};
|
||||||
|
@ -10,6 +10,7 @@ use termion::event::Key;
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
use osstrtools::{OsStringTools, OsStrTools, OsStrConcat};
|
use osstrtools::{OsStringTools, OsStrTools, OsStrConcat};
|
||||||
use async_value::Stale;
|
use async_value::Stale;
|
||||||
|
use parking_lot::Mutex;
|
||||||
|
|
||||||
use crate::listview::{Listable, ListView};
|
use crate::listview::{Listable, ListView};
|
||||||
use crate::textview::TextView;
|
use crate::textview::TextView;
|
||||||
|
@ -133,10 +134,10 @@ impl Process {
|
||||||
let success = self.success.clone();
|
let success = self.success.clone();
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
let cmd = self.cmd.clone();
|
let cmd = self.cmd.clone();
|
||||||
let pid = self.handle.lock()?.id();
|
let pid = self.handle.lock().id();
|
||||||
|
|
||||||
std::thread::spawn(move || -> HResult<()> {
|
std::thread::spawn(move || -> HResult<()> {
|
||||||
let stdout = handle.lock()?.stdout.take()?;
|
let stdout = handle.lock().stdout.take()?;
|
||||||
let mut stdout = BufReader::new(stdout);
|
let mut stdout = BufReader::new(stdout);
|
||||||
let mut processor = move |cmd, sender: &Sender<Events>| -> HResult<()> {
|
let mut processor = move |cmd, sender: &Sender<Events>| -> HResult<()> {
|
||||||
loop {
|
loop {
|
||||||
|
@ -146,7 +147,7 @@ impl Process {
|
||||||
|
|
||||||
if len == 0 { return Ok(()) }
|
if len == 0 { return Ok(()) }
|
||||||
|
|
||||||
output.lock()?.push_str(&buffer);
|
output.lock().push_str(&buffer);
|
||||||
|
|
||||||
let status = format!("{}: read {} chars!", cmd, len);
|
let status = format!("{}: read {} chars!", cmd, len);
|
||||||
sender.send(Events::Status(status))?;
|
sender.send(Events::Status(status))?;
|
||||||
|
@ -159,15 +160,15 @@ impl Process {
|
||||||
};
|
};
|
||||||
processor(&cmd, &sender).log();
|
processor(&cmd, &sender).log();
|
||||||
|
|
||||||
if let Ok(proc_status) = handle.lock()?.wait() {
|
if let Ok(proc_status) = handle.lock().wait() {
|
||||||
let proc_success = proc_status.success();
|
let proc_success = proc_status.success();
|
||||||
let proc_status = match proc_status.code() {
|
let proc_status = match proc_status.code() {
|
||||||
Some(status) => status,
|
Some(status) => status,
|
||||||
None => proc_status.signal().unwrap_or(-1)
|
None => proc_status.signal().unwrap_or(-1)
|
||||||
};
|
};
|
||||||
|
|
||||||
*success.lock()? = Some(proc_success);
|
*success.lock() = Some(proc_success);
|
||||||
*status.lock()? = Some(proc_status);
|
*status.lock() = Some(proc_status);
|
||||||
|
|
||||||
let color_success =
|
let color_success =
|
||||||
if proc_success {
|
if proc_success {
|
||||||
|
@ -363,7 +364,7 @@ impl ListView<Vec<Process>> {
|
||||||
|
|
||||||
fn kill_proc(&mut self) -> HResult<()> {
|
fn kill_proc(&mut self) -> HResult<()> {
|
||||||
let proc = self.selected_proc()?;
|
let proc = self.selected_proc()?;
|
||||||
proc.handle.lock()?.kill()?;
|
proc.handle.lock().kill()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,8 +381,8 @@ impl ListView<Vec<Process>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_proc(&self, proc: &Process) -> HResult<String> {
|
pub fn render_proc(&self, proc: &Process) -> HResult<String> {
|
||||||
let pid = proc.handle.lock()?.id();
|
let pid = proc.handle.lock().id();
|
||||||
let status = match *proc.status.lock()? {
|
let status = match *proc.status.lock() {
|
||||||
Some(status) => format!("{}", status),
|
Some(status) => format!("{}", status),
|
||||||
None => format!("<{}>", pid),
|
None => format!("<{}>", pid),
|
||||||
};
|
};
|
||||||
|
@ -392,7 +393,7 @@ impl ListView<Vec<Process>> {
|
||||||
let padding = sized_string.len() - sized_string.width_cjk();
|
let padding = sized_string.len() - sized_string.width_cjk();
|
||||||
let padding = xsize - padding as u16;
|
let padding = xsize - padding as u16;
|
||||||
|
|
||||||
let color_status = match *proc.success.lock().unwrap() {
|
let color_status = match *proc.success.lock() {
|
||||||
Some(false) => { format!("{}{}", term::color_red(), status) }
|
Some(false) => { format!("{}{}", term::color_red(), status) }
|
||||||
_ => { status }
|
_ => { status }
|
||||||
};
|
};
|
||||||
|
@ -530,7 +531,7 @@ impl ProcView {
|
||||||
if Some(self.get_listview_mut().get_selection()) == self.viewing {
|
if Some(self.get_listview_mut().get_selection()) == self.viewing {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let output = self.get_listview_mut().selected_proc()?.output.lock()?.clone();
|
let output = self.get_listview_mut().selected_proc()?.output.lock().clone();
|
||||||
|
|
||||||
let animator = self.animator.clone();
|
let animator = self.animator.clone();
|
||||||
animator.set_fresh().log();
|
animator.set_fresh().log();
|
||||||
|
@ -601,7 +602,7 @@ impl Widget for ProcView {
|
||||||
let procs_running = listview
|
let procs_running = listview
|
||||||
.content
|
.content
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|proc| proc.status.lock().unwrap().is_none())
|
.filter(|proc| proc.status.lock().is_none())
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
let header = format!("Running processes: {} / {}",
|
let header = format!("Running processes: {} / {}",
|
||||||
|
@ -617,9 +618,9 @@ impl Widget for ProcView {
|
||||||
|
|
||||||
if let Some(proc) = listview.content.get(selection) {
|
if let Some(proc) = listview.content.get(selection) {
|
||||||
let cmd = &proc.cmd;
|
let cmd = &proc.cmd;
|
||||||
let pid = proc.handle.lock()?.id();
|
let pid = proc.handle.lock().id();
|
||||||
let proc_status = proc.status.lock()?;
|
let proc_status = proc.status.lock();
|
||||||
let proc_success = proc.success.lock()?;
|
let proc_success = proc.success.lock();
|
||||||
|
|
||||||
let procinfo = if proc_status.is_some() {
|
let procinfo = if proc_status.is_some() {
|
||||||
let color_success =
|
let color_success =
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
use mime_guess::Mime;
|
use mime_guess::Mime;
|
||||||
use termion::event::Key;
|
use termion::event::Key;
|
||||||
|
use parking_lot::Mutex;
|
||||||
|
|
||||||
use async_value::Async;
|
use async_value::Async;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::{
|
use std::sync::{Arc,
|
||||||
Arc, Mutex,
|
mpsc::Sender};
|
||||||
mpsc::Sender,
|
|
||||||
};
|
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
@ -420,9 +419,7 @@ impl QuickAction {
|
||||||
|
|
||||||
proc_view
|
proc_view
|
||||||
.lock()
|
.lock()
|
||||||
.map(|mut proc_view| {
|
.run_proc_raw(cmd)?;
|
||||||
proc_view.run_proc_raw(cmd)
|
|
||||||
})??;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
23
src/term.rs
23
src/term.rs
|
@ -1,5 +1,5 @@
|
||||||
use std::io::{Stdout, Write, BufWriter, BufRead};
|
use std::io::{Stdout, Write, BufWriter, BufRead};
|
||||||
use std::sync::{Arc, Mutex, RwLock};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use termion;
|
use termion;
|
||||||
use termion::screen::AlternateScreen;
|
use termion::screen::AlternateScreen;
|
||||||
|
@ -7,6 +7,7 @@ use termion::raw::{IntoRawMode, RawTerminal};
|
||||||
|
|
||||||
use parse_ansi::parse_bytes;
|
use parse_ansi::parse_bytes;
|
||||||
use crate::unicode_width::{UnicodeWidthStr, UnicodeWidthChar};
|
use crate::unicode_width::{UnicodeWidthStr, UnicodeWidthChar};
|
||||||
|
use parking_lot::{Mutex, RwLock};
|
||||||
|
|
||||||
use crate::fail::{HResult, ErrorLog};
|
use crate::fail::{HResult, ErrorLog};
|
||||||
use crate::trait_ext::ExtractResult;
|
use crate::trait_ext::ExtractResult;
|
||||||
|
@ -35,23 +36,23 @@ impl Screen {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_size(&self, size: (usize, usize)) -> HResult<()> {
|
pub fn set_size(&self, size: (usize, usize)) -> HResult<()> {
|
||||||
*self.size.write()? = Some(size);
|
*self.size.write() = Some(size);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_resized(&self) -> HResult<bool> {
|
pub fn is_resized(&self) -> HResult<bool> {
|
||||||
Ok(self.size.read()?.is_some())
|
Ok(self.size.read().is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_size(&self) -> HResult<(usize, usize)> {
|
pub fn get_size(&self) -> HResult<(usize, usize)> {
|
||||||
match self.size.read()?.clone() {
|
match self.size.read().clone() {
|
||||||
Some((xsize, ysize)) => Ok((xsize, ysize)),
|
Some((xsize, ysize)) => Ok((xsize, ysize)),
|
||||||
None => Ok((self.xsize()?, self.ysize()?))
|
None => Ok((self.xsize()?, self.ysize()?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take_size(&self) -> HResult<(usize, usize)> {
|
pub fn take_size(&self) -> HResult<(usize, usize)> {
|
||||||
Ok(self.size.write()?.take()?)
|
Ok(self.size.write().take()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_title(&mut self, title: &str) -> HResult<()> {
|
pub fn set_title(&mut self, title: &str) -> HResult<()> {
|
||||||
|
@ -71,16 +72,12 @@ impl Write for Screen {
|
||||||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
||||||
self.screen
|
self.screen
|
||||||
.lock()
|
.lock()
|
||||||
.map_err(|_| std::io::Error::new(std::io::ErrorKind::Other,
|
.write(buf)
|
||||||
"Screen Mutex poisoned!"))
|
|
||||||
.and_then(|mut s| s.write(buf))
|
|
||||||
}
|
}
|
||||||
fn flush(&mut self) -> std::io::Result<()> {
|
fn flush(&mut self) -> std::io::Result<()> {
|
||||||
self.screen
|
self.screen
|
||||||
.lock()
|
.lock()
|
||||||
.map_err(|_| std::io::Error::new(std::io::ErrorKind::Other,
|
.flush()
|
||||||
"Screen Mutex poisoned!"))
|
|
||||||
.and_then(|mut s| s.flush())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,13 +152,13 @@ pub trait ScreenExt: Write {
|
||||||
impl ScreenExt for Screen {
|
impl ScreenExt for Screen {
|
||||||
fn suspend_raw_mode(&mut self) -> HResult<()> {
|
fn suspend_raw_mode(&mut self) -> HResult<()> {
|
||||||
self.screen
|
self.screen
|
||||||
.lock()?
|
.lock()
|
||||||
.suspend_raw_mode()
|
.suspend_raw_mode()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn activate_raw_mode(&mut self) -> HResult<()> {
|
fn activate_raw_mode(&mut self) -> HResult<()> {
|
||||||
self.screen
|
self.screen
|
||||||
.lock()?
|
.lock()
|
||||||
.activate_raw_mode()
|
.activate_raw_mode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use std::sync::{Arc, Mutex, RwLock};
|
use std::sync::Arc;
|
||||||
use std::sync::mpsc::{Sender, Receiver, channel};
|
use std::sync::mpsc::{Sender, Receiver, channel};
|
||||||
use std::io::{Write, stdin};
|
use std::io::{Write, stdin};
|
||||||
|
|
||||||
use termion::event::{Event, Key, MouseEvent};
|
use termion::event::{Event, Key, MouseEvent};
|
||||||
use termion::input::TermRead;
|
use termion::input::TermRead;
|
||||||
use async_value::{Async, Stale};
|
use async_value::{Async, Stale};
|
||||||
|
use parking_lot::{Mutex, RwLock};
|
||||||
|
|
||||||
|
|
||||||
use crate::coordinates::{Coordinates, Position, Size};
|
use crate::coordinates::{Coordinates, Position, Size};
|
||||||
|
@ -91,17 +92,17 @@ impl WidgetCore {
|
||||||
config: Arc::new(RwLock::new(config)) };
|
config: Arc::new(RwLock::new(config)) };
|
||||||
|
|
||||||
let minibuffer = MiniBuffer::new(&core);
|
let minibuffer = MiniBuffer::new(&core);
|
||||||
*core.minibuffer.lock().unwrap() = Some(minibuffer);
|
*core.minibuffer.lock() = Some(minibuffer);
|
||||||
Ok(core)
|
Ok(core)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_sender(&self) -> Sender<Events> {
|
pub fn get_sender(&self) -> Sender<Events> {
|
||||||
self.event_sender.lock().unwrap().clone()
|
self.event_sender.lock().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_status(&self) -> HResult<()> {
|
pub fn draw_status(&self) -> HResult<()> {
|
||||||
let xsize = term::xsize_u();
|
let xsize = term::xsize_u();
|
||||||
let status = match self.status_bar_content.lock()?.as_ref() {
|
let status = match self.status_bar_content.lock().as_ref() {
|
||||||
Some(status) => status.to_string(),
|
Some(status) => status.to_string(),
|
||||||
None => "".to_string(),
|
None => "".to_string(),
|
||||||
};
|
};
|
||||||
|
@ -121,7 +122,7 @@ impl WidgetCore {
|
||||||
pub fn show_status(&self, status: &str) -> HResult<()> {
|
pub fn show_status(&self, status: &str) -> HResult<()> {
|
||||||
HError::log::<()>(status).ok();
|
HError::log::<()>(status).ok();
|
||||||
{
|
{
|
||||||
let mut status_content = self.status_bar_content.lock()?;
|
let mut status_content = self.status_bar_content.lock();
|
||||||
*status_content = Some(status.to_string());
|
*status_content = Some(status.to_string());
|
||||||
}
|
}
|
||||||
self.draw_status()?;
|
self.draw_status()?;
|
||||||
|
@ -129,7 +130,7 @@ impl WidgetCore {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_status(&self) -> HResult<()> {
|
pub fn clear_status(&self) -> HResult<()> {
|
||||||
if self.status_bar_content.lock()?.take().is_some() {
|
if self.status_bar_content.lock().take().is_some() {
|
||||||
self.draw_status().log();
|
self.draw_status().log();
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -137,7 +138,7 @@ impl WidgetCore {
|
||||||
|
|
||||||
pub fn minibuffer_clear(&self) -> HResult<()> {
|
pub fn minibuffer_clear(&self) -> HResult<()> {
|
||||||
self.minibuffer
|
self.minibuffer
|
||||||
.lock()?
|
.lock()
|
||||||
.as_mut()?
|
.as_mut()?
|
||||||
.clear();
|
.clear();
|
||||||
|
|
||||||
|
@ -146,7 +147,7 @@ impl WidgetCore {
|
||||||
|
|
||||||
pub fn minibuffer(&self, query: &str) -> HResult<String> {
|
pub fn minibuffer(&self, query: &str) -> HResult<String> {
|
||||||
let answer = self.minibuffer
|
let answer = self.minibuffer
|
||||||
.lock()?
|
.lock()
|
||||||
.as_mut()?
|
.as_mut()?
|
||||||
.query(query, false);
|
.query(query, false);
|
||||||
let mut screen = self.screen()?;
|
let mut screen = self.screen()?;
|
||||||
|
@ -156,7 +157,7 @@ impl WidgetCore {
|
||||||
|
|
||||||
pub fn minibuffer_continuous(&self, query: &str) -> HResult<String> {
|
pub fn minibuffer_continuous(&self, query: &str) -> HResult<String> {
|
||||||
let answer = self.minibuffer
|
let answer = self.minibuffer
|
||||||
.lock()?
|
.lock()
|
||||||
.as_mut()?
|
.as_mut()?
|
||||||
.query(query, true);
|
.query(query, true);
|
||||||
let mut screen = self.screen()?;
|
let mut screen = self.screen()?;
|
||||||
|
@ -203,7 +204,7 @@ impl WidgetCore {
|
||||||
|
|
||||||
fn get_conf(&self) -> HResult<Config> {
|
fn get_conf(&self) -> HResult<Config> {
|
||||||
let conf = self.config
|
let conf = self.config
|
||||||
.read()?
|
.read()
|
||||||
.get()?
|
.get()?
|
||||||
.clone();
|
.clone();
|
||||||
Ok(conf)
|
Ok(conf)
|
||||||
|
@ -397,7 +398,10 @@ pub trait Widget {
|
||||||
HError::input_updated(input)?
|
HError::input_updated(input)?
|
||||||
}
|
}
|
||||||
Events::ConfigLoaded => {
|
Events::ConfigLoaded => {
|
||||||
self.get_core_mut()?.config.write()?.pull_async()?;
|
self.get_core_mut()?
|
||||||
|
.config
|
||||||
|
.write()
|
||||||
|
.pull_async()?;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -472,7 +476,7 @@ pub trait Widget {
|
||||||
|
|
||||||
fn handle_input(&mut self) -> HResult<()> {
|
fn handle_input(&mut self) -> HResult<()> {
|
||||||
let (tx_internal_event, rx_internal_event) = channel();
|
let (tx_internal_event, rx_internal_event) = channel();
|
||||||
let rx_global_event = self.get_core()?.event_receiver.lock()?.take()?;
|
let rx_global_event = self.get_core()?.event_receiver.lock().take()?;
|
||||||
|
|
||||||
dispatch_events(tx_internal_event, rx_global_event, self.get_core()?.screen()?);
|
dispatch_events(tx_internal_event, rx_global_event, self.get_core()?.screen()?);
|
||||||
|
|
||||||
|
@ -492,7 +496,11 @@ pub trait Widget {
|
||||||
self.get_core()?.screen()?.clear().log();
|
self.get_core()?.screen()?.clear().log();
|
||||||
}
|
}
|
||||||
Events::ConfigLoaded => {
|
Events::ConfigLoaded => {
|
||||||
self.get_core_mut()?.config.write()?.pull_async().ok();
|
self.get_core_mut()?
|
||||||
|
.config
|
||||||
|
.write()
|
||||||
|
.pull_async()
|
||||||
|
.ok();
|
||||||
self.config_loaded().log();
|
self.config_loaded().log();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -536,7 +544,7 @@ fn dispatch_events(tx_internal: Sender<Events>,
|
||||||
match &event {
|
match &event {
|
||||||
Events::ExclusiveEvent(tx_event) => {
|
Events::ExclusiveEvent(tx_event) => {
|
||||||
tx_exclusive_event = match tx_event {
|
tx_exclusive_event = match tx_event {
|
||||||
Some(locked_sender) => locked_sender.lock().unwrap().take(),
|
Some(locked_sender) => locked_sender.lock().take(),
|
||||||
None => None
|
None => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue