diff --git a/Cargo.lock b/Cargo.lock index 85095f58..285f818f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1217,7 +1217,10 @@ dependencies = [ "lazy_static", "libc", "log", + "maplit", + "ncurses", "signal-hook", + "term_size", "unicode-segmentation", "unicode-width", ] @@ -2637,6 +2640,17 @@ dependencies = [ "socket2", ] +[[package]] +name = "ncurses" +version = "5.101.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e2c5d34d72657dc4b638a1c25d40aae81e4f1c699062f72f467237920752032" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "ndk" version = "0.6.0" @@ -4329,6 +4343,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "term_size" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "termcolor" version = "1.1.3" diff --git a/veilid-cli/Cargo.toml b/veilid-cli/Cargo.toml index 0e871df1..d3c76201 100644 --- a/veilid-cli/Cargo.toml +++ b/veilid-cli/Cargo.toml @@ -10,11 +10,16 @@ license = "LGPL-2.0-or-later OR MPL-2.0 OR (MIT AND BSD-3-Clause)" name = "veilid-cli" path = "src/main.rs" +[target.'cfg(unix)'.dependencies] +cursive = { path = "../external/cursive/cursive", default-features = false, features = ["ncurses-backend", "toml"]} + +[target.'cfg(not(unix))'.dependencies] +cursive = { path = "../external/cursive/cursive", default-features = false, features = ["crossterm-backend", "toml"]} + [dependencies] async-std = { version = "^1.9", features = ["unstable", "attributes"] } async-tungstenite = { version = "^0.8", features = ["async-std-runtime"] } async_executors = { version = "^0", default-features = false, features = [ "async_std" ]} -cursive = { path = "../external/cursive/cursive", default-features = false, features = ["crossterm-backend", "toml"]} cursive-flexi-logger-view = { path = "../external/cursive-flexi-logger-view" } cursive_buffered_backend = { path = "../external/cursive_buffered_backend" } # cursive-multiplex = "0.4.0" diff --git a/veilid-cli/src/ui.rs b/veilid-cli/src/ui.rs index 686f7d34..62365927 100644 --- a/veilid-cli/src/ui.rs +++ b/veilid-cli/src/ui.rs @@ -649,17 +649,30 @@ impl UI { cursive_flexi_logger_view::resize(node_log_scrollback); // Instantiate the cursive runnable + let runnable; + cfg_if::cfg_if! { + if #[cfg(unix)] { + runnable = CursiveRunnable::new( + || -> Result, Box> { + let ncurses_backend = cursive::backends::curses::n::Backend::init().unwrap(); + let buffered_backend = + cursive_buffered_backend::BufferedBackend::new(ncurses_backend); - // reduces flicker, but it costs cpu - let runnable = CursiveRunnable::new( - || -> Result, Box> { - let crossterm_backend = cursive::backends::crossterm::Backend::init().unwrap(); - let buffered_backend = - cursive_buffered_backend::BufferedBackend::new(crossterm_backend); + Ok(Box::new(buffered_backend)) + }, + ); + } else { + runnable = CursiveRunnable::new( + || -> Result, Box> { + let crossterm_backend = cursive::backends::crossterm::Backend::init().unwrap(); + let buffered_backend = + cursive_buffered_backend::BufferedBackend::new(crossterm_backend); - Ok(Box::new(buffered_backend)) - }, - ); + Ok(Box::new(buffered_backend)) + }, + ); + } + } //let runnable = cursive::default(); // Make the callback mechanism easily reachable