feat(ui): rerender on SIGWINCH
This commit is contained in:
27
Cargo.lock
generated
27
Cargo.lock
generated
@@ -16,6 +16,11 @@ dependencies = [
|
||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arc-swap"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "async-std"
|
||||
version = "1.4.0"
|
||||
@@ -1138,6 +1143,24 @@ dependencies = [
|
||||
"opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook"
|
||||
version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"arc-swap 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.2"
|
||||
@@ -1370,6 +1393,7 @@ dependencies = [
|
||||
"jwalk 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"signal-hook 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"stderrlog 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"structopt 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"termion 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -1466,6 +1490,7 @@ dependencies = [
|
||||
[metadata]
|
||||
"checksum aho-corasick 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)" = "743ad5a418686aad3b87fd14c43badd828cf26e214a00f92a384291cf22e1811"
|
||||
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
"checksum arc-swap 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d663a8e9a99154b5fb793032533f6328da35e23aac63d5c152279aa8ba356825"
|
||||
"checksum async-std 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0bf6039b315300e057d198b9d3ab92ee029e31c759b7f1afae538145e6f18a3e"
|
||||
"checksum async-task 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d22dc86693d375d2733b536fd8914bea0fa93adf4b1e6bcbd9c7c500cb62d920"
|
||||
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
|
||||
@@ -1596,6 +1621,8 @@ dependencies = [
|
||||
"checksum serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)" = "9371ade75d4c2d6cb154141b9752cf3781ec9c05e0e5cf35060e1e70ee7b9c25"
|
||||
"checksum serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)" = "691b17f19fc1ec9d94ec0b5864859290dff279dbd7b03f017afda54eb36c3c35"
|
||||
"checksum sha-1 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df"
|
||||
"checksum signal-hook 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "10b9f3a1686a29f53cfd91ee5e3db3c12313ec02d33765f02c1a9645a1811e2c"
|
||||
"checksum signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41"
|
||||
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
|
||||
"checksum smallvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5c2fb2ec9bcd216a5b0d0ccf31ab17b5ed1d627960edff65bbe95d3ce221cefc"
|
||||
"checksum stderrlog 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "32e5ee9b90a5452c570a0b0ac1c99ae9498db7e56e33d74366de7f2a7add7f25"
|
||||
|
||||
@@ -22,6 +22,7 @@ async-std = "*"
|
||||
futures = "*"
|
||||
walkdir = "2"
|
||||
jwalk = "0.3"
|
||||
signal-hook = "0.1.10"
|
||||
|
||||
[dev-dependencies]
|
||||
stderrlog = "0.4"
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
mod controls;
|
||||
mod filesystem;
|
||||
mod signals;
|
||||
|
||||
pub use controls::*;
|
||||
pub use filesystem::*;
|
||||
pub use signals::*;
|
||||
|
||||
23
src/input/signals.rs
Normal file
23
src/input/signals.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use signal_hook::iterator::Signals;
|
||||
|
||||
pub type OnSigWinch = dyn Fn(Box<dyn Fn()>) + Send;
|
||||
pub type SigCleanup = dyn Fn() + Send;
|
||||
|
||||
pub fn sigwinch() -> (Box<OnSigWinch>, Box<SigCleanup>) {
|
||||
let signals = Signals::new(&[signal_hook::SIGWINCH]).unwrap();
|
||||
let on_winch = {
|
||||
let signals = signals.clone();
|
||||
move |cb: Box<dyn Fn()>| {
|
||||
for signal in signals.forever() {
|
||||
match signal {
|
||||
signal_hook::SIGWINCH => cb(),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let cleanup = move || {
|
||||
signals.close();
|
||||
};
|
||||
(Box::new(on_winch), Box::new(cleanup))
|
||||
}
|
||||
16
src/main.rs
16
src/main.rs
@@ -19,6 +19,7 @@ use ::std::sync::{Arc, Mutex};
|
||||
use input::scan_folder;
|
||||
use input::handle_keypress;
|
||||
use input::KeyboardEvents;
|
||||
use input::sigwinch;
|
||||
use ui::state::State;
|
||||
use ui::Display;
|
||||
|
||||
@@ -99,6 +100,8 @@ where
|
||||
|
||||
let app = Arc::new(Mutex::new(App::new(terminal_backend)));
|
||||
|
||||
let (on_sigwinch, cleanup) = sigwinch();
|
||||
|
||||
active_threads.push(
|
||||
thread::Builder::new()
|
||||
.name("stdin_handler".to_string())
|
||||
@@ -109,6 +112,7 @@ where
|
||||
let mut app = app.lock().expect("could not get app");
|
||||
handle_keypress(evt, &mut app);
|
||||
if !app.is_running {
|
||||
cleanup();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -124,6 +128,18 @@ where
|
||||
app.render();
|
||||
}
|
||||
|
||||
active_threads.push(
|
||||
thread::Builder::new()
|
||||
.name("resize_handler".to_string())
|
||||
.spawn({
|
||||
let app = app.clone();
|
||||
move || {
|
||||
on_sigwinch(Box::new(move || { app.lock().unwrap().render() }));
|
||||
}
|
||||
})
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
for thread_handler in active_threads {
|
||||
thread_handler.join().unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user