Skip to content

Commit

Permalink
Use string instead of box::leak
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevithakannan2 committed Oct 1, 2024
1 parent 6c2aaf3 commit cc16c3e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tui/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct AppState {
selected_commands: Vec<Command>,
drawable: bool,
#[cfg(feature = "tips")]
tip: &'static str,
tip: String,
}

pub enum Focus {
Expand Down Expand Up @@ -363,7 +363,7 @@ impl AppState {
};

#[cfg(feature = "tips")]
let bottom_title = Line::from(self.tip.bold().blue()).right_aligned();
let bottom_title = Line::from(self.tip.clone().bold().blue()).right_aligned();
#[cfg(not(feature = "tips"))]
let bottom_title = "";

Expand Down Expand Up @@ -686,13 +686,13 @@ impl AppState {
const TIPS: &str = include_str!("../cool_tips.txt");

#[cfg(feature = "tips")]
fn get_random_tip() -> &'static str {
fn get_random_tip() -> String {
let tips: Vec<&str> = TIPS.lines().collect();
if tips.is_empty() {
return "";
return "".to_string();
}

let mut rng = rand::thread_rng();
let random_index = rng.gen_range(0..tips.len());
Box::leak(format!(" {} ", tips[random_index]).into_boxed_str())
format!(" {} ", tips[random_index])
}

0 comments on commit cc16c3e

Please sign in to comment.