diff --git a/tui/Cargo.toml b/tui/Cargo.toml index b6e57edc..681d645d 100644 --- a/tui/Cargo.toml +++ b/tui/Cargo.toml @@ -7,17 +7,12 @@ edition = "2021" license.workspace = true repository = "https://github.com/ChrisTitusTech/linutil/tree/main/tui" version.workspace = true -include = [ - "src/*.rs", - "Cargo.toml", - "build.rs", - "cool_tips.txt", -] +include = ["src/*.rs", "Cargo.toml", "build.rs", "cool_tips.txt"] build = "build.rs" [features] default = ["tips"] -tips = [] +tips = ["rand"] [dependencies] clap = { version = "4.5.16", features = ["derive"] } @@ -28,7 +23,7 @@ portable-pty = "0.8.1" ratatui = "0.28.1" tui-term = "0.1.12" unicode-width = "0.1.13" -rand = "0.8.5" +rand = { version = "0.8.5", optional = true } linutil_core = { path = "../core", version = "24.9.19" } [build-dependencies] diff --git a/tui/src/state.rs b/tui/src/state.rs index 2a829747..9bfb982f 100644 --- a/tui/src/state.rs +++ b/tui/src/state.rs @@ -74,7 +74,7 @@ impl AppState { selected_commands: Vec::new(), drawable: false, #[cfg(feature = "tips")] - tip: get_random_line(include_str!("../cool_tips.txt").lines().collect()), + tip: get_random_tip(), }; state.update_items(); state @@ -543,12 +543,16 @@ impl AppState { } #[cfg(feature = "tips")] -fn get_random_line(lines: Vec<&str>) -> &str { - if lines.is_empty() { +const TIPS: &str = include_str!("../cool_tips.txt"); + +#[cfg(feature = "tips")] +fn get_random_tip() -> &'static str { + let tips: Vec<&str> = TIPS.lines().collect(); + if tips.is_empty() { return ""; } let mut rng = rand::thread_rng(); - let random_index = rng.gen_range(0..lines.len()); - lines[random_index] + let random_index = rng.gen_range(0..tips.len()); + tips[random_index] }