From be6a99acb4b145c8546d658abbb0db5a01877c64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Tue, 6 Feb 2024 16:06:58 +0100 Subject: [PATCH] replace tui with ratatui --- Cargo.lock | 257 ++++++++++++++++------------------- Cargo.toml | 2 - server-cli/Cargo.toml | 9 +- server-cli/src/tui_runner.rs | 28 ++-- server-cli/src/tuilog.rs | 16 +-- 5 files changed, 137 insertions(+), 175 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8b3cb21dde..ce67d09945 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -692,6 +692,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" +[[package]] +name = "castaway" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a17ed5635fc8536268e5d4de1e22e81ac34419e5f052d4d51f4e01dcc263fcc" +dependencies = [ + "rustversion", +] + [[package]] name = "cc" version = "1.0.83" @@ -921,15 +930,6 @@ dependencies = [ "x11rb 0.13.0", ] -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "cmake" version = "0.1.45" @@ -1007,6 +1007,19 @@ dependencies = [ "memchr", ] +[[package]] +name = "compact_str" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f86b9c4c00838774a6d902ef931eff7470720c51d90c2e32cfe15dc304737b3f" +dependencies = [ + "castaway", + "cfg-if 1.0.0", + "itoa", + "ryu", + "static_assertions", +] + [[package]] name = "concurrent-queue" version = "2.4.0" @@ -1393,22 +1406,6 @@ version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" -[[package]] -name = "crossterm" -version = "0.17.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f4919d60f26ae233e14233cc39746c8c8bb8cd7b05840ace83604917b51b6c7" -dependencies = [ - "bitflags 1.3.2", - "crossterm_winapi 0.6.2", - "lazy_static", - "libc", - "mio 0.7.14", - "parking_lot 0.10.2", - "signal-hook 0.1.17", - "winapi", -] - [[package]] name = "crossterm" version = "0.26.1" @@ -1416,21 +1413,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13" dependencies = [ "bitflags 1.3.2", - "crossterm_winapi 0.9.1", + "crossterm_winapi", "libc", - "mio 0.8.10", + "mio", "parking_lot 0.12.1", - "signal-hook 0.3.17", + "signal-hook", "signal-hook-mio", "winapi", ] [[package]] -name = "crossterm_winapi" -version = "0.6.2" +name = "crossterm" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2265c3f8e080075d9b6417aa72293fc71662f34b4af2612d8d1b074d29510db" +checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" dependencies = [ + "bitflags 2.4.2", + "crossterm_winapi", + "libc", + "mio", + "parking_lot 0.12.1", + "signal-hook", + "signal-hook-mio", "winapi", ] @@ -1583,7 +1587,7 @@ checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if 1.0.0", "hashbrown 0.14.3", - "lock_api 0.4.11", + "lock_api", "once_cell", "parking_lot_core 0.9.9", ] @@ -2963,6 +2967,12 @@ dependencies = [ "serde", ] +[[package]] +name = "indoc" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8" + [[package]] name = "inline_tweak" version = "1.1.1" @@ -3335,15 +3345,6 @@ version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" -[[package]] -name = "lock_api" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" -dependencies = [ - "scopeguard", -] - [[package]] name = "lock_api" version = "0.4.11" @@ -3373,6 +3374,15 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "lru" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2c024b41519440580066ba82aab04092b333e09066a5eb86c7c4890df31f22" +dependencies = [ + "hashbrown 0.14.3", +] + [[package]] name = "lz-fear" version = "0.1.1" @@ -3573,19 +3583,6 @@ dependencies = [ "simd-adler32", ] -[[package]] -name = "mio" -version = "0.7.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" -dependencies = [ - "libc", - "log", - "miow", - "ntapi", - "winapi", -] - [[package]] name = "mio" version = "0.8.10" @@ -3598,15 +3595,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "miow" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" -dependencies = [ - "winapi", -] - [[package]] name = "more-asserts" version = "0.2.2" @@ -3863,7 +3851,7 @@ dependencies = [ "kqueue", "libc", "log", - "mio 0.8.10", + "mio", "walkdir", "windows-sys 0.48.0", ] @@ -3889,14 +3877,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "ntapi" -version = "0.3.7" -source = "git+https://github.com/MSxDOS/ntapi.git?rev=9f56b149c9e25796739157c0fce3e0007a7de6eb#9f56b149c9e25796739157c0fce3e0007a7de6eb" -dependencies = [ - "winapi", -] - [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -4305,16 +4285,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "parking_lot" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" -dependencies = [ - "lock_api 0.3.4", - "parking_lot_core 0.7.3", -] - [[package]] name = "parking_lot" version = "0.11.2" @@ -4322,7 +4292,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", - "lock_api 0.4.11", + "lock_api", "parking_lot_core 0.8.6", ] @@ -4332,24 +4302,10 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ - "lock_api 0.4.11", + "lock_api", "parking_lot_core 0.9.9", ] -[[package]] -name = "parking_lot_core" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b93f386bb233083c799e6e642a9d73db98c24a5deeb95ffc85bf281255dffc98" -dependencies = [ - "cfg-if 0.1.10", - "cloudabi", - "libc", - "redox_syscall 0.1.57", - "smallvec", - "winapi", -] - [[package]] name = "parking_lot_core" version = "0.8.6" @@ -4905,6 +4861,26 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8a99fddc9f0ba0a85884b8d14e3592853e787d581ca1816c91349b10e4eeab" +[[package]] +name = "ratatui" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "154b85ef15a5d1719bcaa193c3c81fe645cd120c156874cd660fe49fd21d1373" +dependencies = [ + "bitflags 2.4.2", + "cassowary", + "compact_str", + "crossterm 0.27.0", + "indoc", + "itertools 0.12.1", + "lru", + "paste", + "stability", + "strum 0.26.1", + "unicode-segmentation", + "unicode-width", +] + [[package]] name = "raw-window-handle" version = "0.4.3" @@ -4952,12 +4928,6 @@ dependencies = [ "yasna", ] -[[package]] -name = "redox_syscall" -version = "0.1.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" - [[package]] name = "redox_syscall" version = "0.2.16" @@ -5763,17 +5733,6 @@ version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5ea33232fdcf1bf691ca33450e5a94dde13e1a8cbb8caabc5e4f9d761e10b1a" -[[package]] -name = "signal-hook" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e31d442c16f047a671b5a71e2161d6e68814012b7f5379d269ebd915fac2729" -dependencies = [ - "libc", - "mio 0.7.14", - "signal-hook-registry", -] - [[package]] name = "signal-hook" version = "0.3.17" @@ -5791,8 +5750,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" dependencies = [ "libc", - "mio 0.8.10", - "signal-hook 0.3.17", + "mio", + "signal-hook", ] [[package]] @@ -5940,7 +5899,7 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" dependencies = [ - "lock_api 0.4.11", + "lock_api", ] [[package]] @@ -5962,6 +5921,16 @@ dependencies = [ "num-traits", ] +[[package]] +name = "stability" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd1b177894da2a2d9120208c3386066af06a488255caabc5de8ddca22dbc3ce" +dependencies = [ + "quote 1.0.35", + "syn 1.0.109", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -6084,7 +6053,16 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" dependencies = [ - "strum_macros", + "strum_macros 0.24.3", +] + +[[package]] +name = "strum" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "723b93e8addf9aa965ebe2d11da6d7540fa2283fcea14b3371ff055f7ba13f5f" +dependencies = [ + "strum_macros 0.26.1", ] [[package]] @@ -6100,6 +6078,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "strum_macros" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a3417fc93d76740d974a01654a09777cb500428cc874ca9f45edfe0c4d4cd18" +dependencies = [ + "heck 0.4.1", + "proc-macro2 1.0.78", + "quote 1.0.35", + "rustversion", + "syn 2.0.48", +] + [[package]] name = "sum_type" version = "0.2.0" @@ -6380,7 +6371,7 @@ dependencies = [ "backtrace", "bytes", "libc", - "mio 0.8.10", + "mio", "num_cpus", "pin-project-lite", "signal-hook-registry", @@ -6659,18 +6650,6 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" -[[package]] -name = "tui" -version = "0.10.0" -source = "git+https://github.com/fdehau/tui-rs.git?branch=paragraph-scroll#54b841fab6cfdb38e8dc1382176e965787964b4c" -dependencies = [ - "bitflags 1.3.2", - "cassowary", - "crossterm 0.17.7", - "unicode-segmentation", - "unicode-width", -] - [[package]] name = "tuple_utils" version = "0.4.0" @@ -6954,7 +6933,7 @@ dependencies = [ "slotmap", "specs", "spin_sleep", - "strum", + "strum 0.24.1", "tracing", "tracing-subscriber", "uuid", @@ -7222,7 +7201,7 @@ dependencies = [ "serde", "serde_json", "specs", - "strum", + "strum 0.24.1", "tokio", "tracing", "vek 0.15.8", @@ -7267,13 +7246,13 @@ dependencies = [ "mimalloc", "num_cpus", "prometheus", + "ratatui", "ron", "serde", "shell-words", - "signal-hook 0.3.17", + "signal-hook", "tokio", "tracing", - "tui", "veloren-common", "veloren-common-base", "veloren-common-frontend", @@ -7335,7 +7314,7 @@ dependencies = [ "shaderc", "slab", "specs", - "strum", + "strum 0.24.1", "tokio", "tracing", "treeculler", @@ -7431,7 +7410,7 @@ dependencies = [ "rstar", "rusqlite", "serde", - "strum", + "strum 0.24.1", "svg_fmt", "tracing", "tracing-subscriber", @@ -8418,7 +8397,7 @@ dependencies = [ "instant", "libc", "log", - "mio 0.8.10", + "mio", "ndk 0.7.0", "objc2", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index 14ce84cf73..ad33f01eb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -159,8 +159,6 @@ clap = { version = "4.2", features = ["derive"]} [patch.crates-io] vek = { git = "https://github.com/yoanlcq/vek.git", rev = "84d5cb65841d46599a986c5477341bea4456be26" } -# ntapi 3.7 fails to compile under windows due to the bug https://github.com/MSxDOS/ntapi/pull/12 -ntapi = { git = "https://github.com/MSxDOS/ntapi.git", rev = "9f56b149c9e25796739157c0fce3e0007a7de6eb" } shred = { git = "https://github.com/amethyst/shred.git", rev = "5d52c6fc390dd04c12158633e77591f6523d1f85" } # This is needed because of an issue with spirv & naga in wgpu 0.18, and there's an issue # with uint in uniforms for gl. diff --git a/server-cli/Cargo.toml b/server-cli/Cargo.toml index c42ba33618..e6b7ca3028 100644 --- a/server-cli/Cargo.toml +++ b/server-cli/Cargo.toml @@ -46,6 +46,7 @@ shell-words = "1.0.0" tracing = { workspace = true } ron = { workspace = true } serde = { workspace = true, features = [ "rc", "derive" ]} +ratatui = { version = "0.26.0", features = ["crossterm"] } #HTTP axum = { version = "0.6.20" } @@ -54,10 +55,4 @@ prometheus = { workspace = true } chrono = { workspace = true } [target.'cfg(windows)'.dependencies] -mimalloc = "0.1.29" - -[dependencies.tui] -git = "https://github.com/fdehau/tui-rs.git" -branch="paragraph-scroll" -default-features = false -features = ['crossterm'] +mimalloc = "0.1.29" \ No newline at end of file diff --git a/server-cli/src/tui_runner.rs b/server-cli/src/tui_runner.rs index 5284dd1891..7f9d490542 100644 --- a/server-cli/src/tui_runner.rs +++ b/server-cli/src/tui_runner.rs @@ -4,6 +4,13 @@ use crossterm::{ execute, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, }; +use ratatui::{ + backend::CrosstermBackend, + layout::Rect, + text::Text, + widgets::{Block, Borders, Paragraph}, + Terminal, +}; use std::{ io, sync::{ @@ -13,13 +20,6 @@ use std::{ time::Duration, }; use tracing::{debug, error, warn}; -use tui::{ - backend::CrosstermBackend, - layout::Rect, - text::Text, - widgets::{Block, Borders, Paragraph, Wrap}, - Terminal, -}; pub struct Tui { pub msg_r: mpsc::Receiver, @@ -140,18 +140,8 @@ impl Tui { let block = Block::default().borders(Borders::ALL); - let wrap = Wrap { - scroll_callback: Some(Box::new(|text_area, lines| { - LOG.resize(text_area.height as usize); - let len = lines.len() as u16; - (len.saturating_sub(text_area.height), 0) - })), - ..Default::default() - }; - - let logger = Paragraph::new(LOG.inner.lock().unwrap().clone()) - .block(block) - .wrap(wrap); + LOG.resize(log_rect.height as usize); + let logger = Paragraph::new(LOG.inner.lock().unwrap().clone()).block(block); f.render_widget(logger, log_rect); let text: Text = input.as_str().into(); diff --git a/server-cli/src/tuilog.rs b/server-cli/src/tuilog.rs index eceb7af987..c9d941a487 100644 --- a/server-cli/src/tuilog.rs +++ b/server-cli/src/tuilog.rs @@ -1,9 +1,13 @@ +use ratatui::{ + prelude::Line, + style::{Color, Modifier, Style}, + text::{Span, Text}, +}; use std::{ io::{self, Write}, sync::{Arc, Mutex}, }; use tracing::warn; -use tui::text::Text; #[derive(Debug, Default, Clone)] pub struct TuiLog<'a> { @@ -29,10 +33,6 @@ impl<'a> Write for TuiLog<'a> { // depend on an old version of nom. Alternatives to consider may include // `vte`, `anstyle-parse`, `vt100`, or others. use cansi::v3::categorise_text; - use tui::{ - style::{Color, Modifier}, - text::{Span, Spans}, - }; let line = core::str::from_utf8(buf).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; @@ -41,7 +41,7 @@ impl<'a> Write for TuiLog<'a> { let mut lines = Vec::new(); for out in categorise_text(line) { - let mut style = tui::style::Style::default(); + let mut style = Style::default(); // NOTE: There are other values returned from cansi that we don't bother to use // for now including background color, italics, blinking, etc. style.fg = match out.fg { @@ -72,12 +72,12 @@ impl<'a> Write for TuiLog<'a> { spans.push(Span::styled(t.to_owned(), style)); } if t.ends_with('\n') { - lines.push(Spans(core::mem::take(&mut spans))); + lines.push(Line::from(core::mem::take(&mut spans))); } } } if !spans.is_empty() { - lines.push(Spans(spans)); + lines.push(Line::from(spans)); } self.inner.lock().unwrap().lines.append(&mut lines);