From 4d7b913064ef3ce919f30fa145e47a5157007224 Mon Sep 17 00:00:00 2001 From: Sanjiv Sahayam Date: Fri, 5 Apr 2024 17:07:44 +1100 Subject: [PATCH] Update tui to ratatui --- Cargo.lock | 288 +++++++++++++++++++++++++++++++++---------------- Cargo.toml | 4 +- src/console.rs | 2 +- src/tui_app.rs | 93 ++++++++-------- 4 files changed, 245 insertions(+), 142 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f2495e..24ce1c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,18 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.1.3" @@ -26,6 +38,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -91,7 +109,7 @@ checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.58", ] [[package]] @@ -174,6 +192,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" +[[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.90" @@ -225,6 +252,19 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "compact_str" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f86b9c4c00838774a6d902ef931eff7470720c51d90c2e32cfe15dc304737b3f" +dependencies = [ + "castaway", + "cfg-if", + "itoa", + "ryu", + "static_assertions", +] + [[package]] name = "concurrent-queue" version = "2.4.0" @@ -258,15 +298,15 @@ checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "crossterm" -version = "0.22.1" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c85525306c4291d1b73ce93c8acf9c339f9b213aef6c1d85c3830cbf1c16325c" +checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", "crossterm_winapi", "libc", - "mio 0.7.14", - "parking_lot 0.11.2", + "mio", + "parking_lot", "signal-hook", "signal-hook-mio", "winapi", @@ -489,7 +529,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.58", ] [[package]] @@ -607,6 +647,10 @@ name = "hashbrown" version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash", + "allocator-api2", +] [[package]] name = "heck" @@ -883,6 +927,12 @@ dependencies = [ "hashbrown 0.14.3", ] +[[package]] +name = "indoc" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" + [[package]] name = "infer" version = "0.2.3" @@ -914,6 +964,15 @@ dependencies = [ "serde", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" @@ -988,6 +1047,15 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +[[package]] +name = "lru" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3262e75e648fce39813cb56ac41f3c3e3f65217ebf3844d818d1f9398cfb0dc" +dependencies = [ + "hashbrown 0.14.3", +] + [[package]] name = "memchr" version = "2.7.2" @@ -1009,19 +1077,6 @@ dependencies = [ "adler", ] -[[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.11" @@ -1029,19 +1084,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", + "log", "wasi 0.11.0+wasi-snapshot-preview1", "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 = "native-tls" version = "0.2.11" @@ -1060,15 +1107,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "ntapi" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" -dependencies = [ - "winapi", -] - [[package]] name = "num-bigint" version = "0.4.4" @@ -1191,7 +1229,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.58", ] [[package]] @@ -1230,17 +1268,6 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core 0.8.6", -] - [[package]] name = "parking_lot" version = "0.12.1" @@ -1248,21 +1275,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.9", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall 0.2.16", - "smallvec", - "winapi", + "parking_lot_core", ] [[package]] @@ -1273,11 +1286,17 @@ checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.4.1", + "redox_syscall", "smallvec", "windows-targets 0.48.5", ] +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + [[package]] name = "pem" version = "3.0.3" @@ -1311,7 +1330,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.58", ] [[package]] @@ -1376,12 +1395,12 @@ dependencies = [ "futures", "octocrab", "pretty_assertions", + "ratatui", "reqwest", "serde", "serde_json", "tempfile", "tokio", - "tui", "unidiff", "url", "wiremock", @@ -1438,12 +1457,23 @@ dependencies = [ ] [[package]] -name = "redox_syscall" -version = "0.2.16" +name = "ratatui" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "bcb12f8fbf6c62614b0d56eb352af54f6a22410c3b079eb53ee93c7b97dd31d8" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", + "cassowary", + "compact_str", + "crossterm", + "indoc", + "itertools", + "lru", + "paste", + "stability", + "strum", + "unicode-segmentation", + "unicode-width", ] [[package]] @@ -1640,6 +1670,12 @@ dependencies = [ "untrusted", ] +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + [[package]] name = "ryu" version = "1.0.17" @@ -1710,7 +1746,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.58", ] [[package]] @@ -1774,7 +1810,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" dependencies = [ "libc", - "mio 0.7.14", + "mio", "signal-hook", ] @@ -1832,7 +1868,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.58", ] [[package]] @@ -1851,18 +1887,67 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "stability" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd1b177894da2a2d9120208c3386066af06a488255caabc5de8ddca22dbc3ce" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "strsim" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strum" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d8cec3501a5194c432b2b7976db6b7d10ec95c253208b45f83f7136aa985e29" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.58", +] + [[package]] name = "subtle" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.58" @@ -1945,7 +2030,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.58", ] [[package]] @@ -2003,9 +2088,9 @@ dependencies = [ "backtrace", "bytes", "libc", - "mio 0.8.11", + "mio", "num_cpus", - "parking_lot 0.12.1", + "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", @@ -2021,7 +2106,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.58", ] [[package]] @@ -2128,7 +2213,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.58", ] [[package]] @@ -2146,19 +2231,6 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" -[[package]] -name = "tui" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23ed0a32c88b039b73f1b6c5acbd0554bfa5b6be94467375fd947c4de3a02271" -dependencies = [ - "bitflags 1.3.2", - "cassowary", - "crossterm", - "unicode-segmentation", - "unicode-width", -] - [[package]] name = "unicode-bidi" version = "0.3.15" @@ -2227,6 +2299,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "waker-fn" version = "1.1.1" @@ -2275,7 +2353,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.58", "wasm-bindgen-shared", ] @@ -2309,7 +2387,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.58", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2540,6 +2618,26 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + [[package]] name = "zeroize" version = "1.7.0" diff --git a/Cargo.toml b/Cargo.toml index 1d281f3..de03f4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,13 +14,13 @@ unidiff = "0.3" futures = "0.3" clap = { version = "3", features = ["default" ,"env"] } dirs = "5" -tui = "0.17" -crossterm = "0.22" chrono = "0.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" reqwest = "0.12" base64 = "0.22" +crossterm = "0.27" +ratatui = "0.26.1" [dev-dependencies] tempfile = "3" diff --git a/src/console.rs b/src/console.rs index 4ea871f..b69e639 100644 --- a/src/console.rs +++ b/src/console.rs @@ -1,4 +1,4 @@ -use tui::{self, widgets}; +use ratatui::{self, widgets}; pub struct StatefulList { pub state: widgets::ListState, diff --git a/src/tui_app.rs b/src/tui_app.rs index 12e929b..002648b 100644 --- a/src/tui_app.rs +++ b/src/tui_app.rs @@ -10,11 +10,11 @@ use std::{ time::{Duration, Instant}, fmt::Display, }; -use tui::{ +use ratatui::{ backend::{Backend, CrosstermBackend}, layout::{Constraint, Direction, Layout, Alignment}, style::{Color, Modifier, Style}, - text::{Span, Spans}, + text::{Span, Line}, widgets::{Block, Borders, List, ListItem, Paragraph, Wrap}, Frame, Terminal, }; @@ -54,7 +54,7 @@ fn run_app( ) -> R { let mut last_tick = Instant::now(); loop { - terminal.draw(|f| ui(f, &mut app)).map_err(|e| PursError::TUIError(NestedError::from(e)))?; + terminal.draw(|f| ui::(f, &mut app)).map_err(|e| PursError::TUIError(NestedError::from(e)))?; let timeout = tick_rate .checked_sub(last_tick.elapsed()) @@ -87,7 +87,7 @@ fn run_app( } } -fn ui(f: &mut Frame, app: &mut App) +fn ui(f: &mut Frame<'_>, app: &mut App) { // Create two chunks with equal horizontal screen space let chunks = Layout::default() @@ -101,16 +101,18 @@ fn ui(f: &mut Frame, app: &mut App) .items .iter() .map(|i| { - let lines = - vec![ - Spans::from(""), - Spans::from(pr_line(i)), - ]; - - ListItem::new(lines) - .style( - Style::default() - ) + let mut pr_lines: Vec> = pr_line(i); + pr_lines.insert(0, Span::from("")); + + let lines = + Line + ::default() + .spans(pr_lines); + + ListItem::new(lines) + .style( + Style::default() + ) }) .collect(); @@ -161,7 +163,7 @@ fn ui(f: &mut Frame, app: &mut App) } -fn no_pr_details<'a>() -> Vec> { +fn no_pr_details<'a>() -> Vec> { vec![ help_line("How to to use purs"), help_line("------------------"), @@ -173,18 +175,12 @@ fn no_pr_details<'a>() -> Vec> { ] } -fn help_line(message: &str) -> Spans { +fn help_line<'a>(message: &'a str) -> Line<'a> { let style = Style::default().fg(Color::Yellow); - Spans::from( - vec![ - Span::styled(message, style) - ] - ) - } - -fn pr_details(pr: &ValidatedPullRequest) -> Vec { - + Line::styled(message, style) +} +fn pr_details<'a>(pr: &ValidatedPullRequest) -> Vec> { let owner_repo = details_key_value("Base Repository", pr.config_owner_repo.to_string()); let title = details_key_value("Title", pr.title.clone()); let pr_no = details_key_value("PR#", pr.pr_number.to_string()); @@ -212,26 +208,35 @@ fn pr_details(pr: &ValidatedPullRequest) -> Vec { let pr_owner = details_key_value("Owner", get_pr_owner(pr.pr_owner.clone())); - vec![ - Spans::from(""), - Spans::from(created_at), - Spans::from(updated_at), - Spans::from(owner_repo), - Spans::from(title), - Spans::from(pr_owner), - Spans::from(pr_no), - Spans::from(pr_url), - Spans::from(pr_repo), - Spans::from(pr_branch), - Spans::from(head_sha), - Spans::from(base_sha), - Spans::from(comment_no), - Spans::from(review_no), - Spans::from(reviewer_names), - Spans::from(pr_diff_no), - Spans::from(draft), - ] + let span_lines = + vec![ + created_at, + updated_at, + owner_repo, + title, + pr_owner, + pr_no, + pr_url, + pr_repo, + pr_branch, + head_sha, + base_sha, + comment_no, + review_no, + reviewer_names, + pr_diff_no, + draft, + ]; + + let lines = + span_lines + .into_iter() + .map(|span_line| { + Line::default().spans(span_line) + }) + .collect::>(); + lines } fn get_pr_owner(owner_option: Option) -> String {