Skip to content

Commit

Permalink
use command names in FloatContent titles
Browse files Browse the repository at this point in the history
Co-authored-by: Afonso Franco F. <[email protected]>
  • Loading branch information
cartercanedy and afonsofrancof committed Oct 10, 2024
1 parent d7226ad commit 1a131a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
15 changes: 9 additions & 6 deletions tui/src/floating_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct FloatingText {
max_line_width: usize,
v_scroll: usize,
h_scroll: usize,
mode_title: String,
title: String,
}

macro_rules! style {
Expand Down Expand Up @@ -124,7 +124,7 @@ fn get_lines_owned(s: &str) -> Vec<String> {
}

impl FloatingText {
pub fn new(text: String, title: &str) -> Self {
pub fn new(text: String, title: String) -> Self {
let src = get_lines(&text)
.into_iter()
.map(|s| s.to_string())
Expand All @@ -133,7 +133,7 @@ impl FloatingText {
let max_line_width = max_width!(src);
Self {
src,
mode_title: title.to_string(),
title,
max_line_width,
v_scroll: 0,
h_scroll: 0,
Expand All @@ -146,6 +146,7 @@ impl FloatingText {
// just apply highlights directly
(max_width!(get_lines(cmd)), Some(cmd.clone()))
}

Command::LocalFile { file, .. } => {
// have to read from tmp dir to get cmd src
let raw = std::fs::read_to_string(file)
Expand All @@ -163,7 +164,7 @@ impl FloatingText {

Some(Self {
src,
mode_title: title,
title,
max_line_width,
h_scroll: 0,
v_scroll: 0,
Expand Down Expand Up @@ -197,10 +198,12 @@ impl FloatingText {

impl FloatContent for FloatingText {
fn top_title(&self) -> Option<Line<'_>> {
let title_text = format!(" {} ", self.mode_title);
let title_text = format!(" {} ", self.title);

let title_line = Line::from(title_text)
.centered()
.style(Style::default().reversed());

Some(title_line)
}

Expand Down Expand Up @@ -274,7 +277,7 @@ impl FloatContent for FloatingText {

fn get_shortcut_list(&self) -> (&str, Box<[Shortcut]>) {
(
&self.mode_title,
&self.title,
Box::new([
Shortcut::new("Scroll down", ["j", "Down"]),
Shortcut::new("Scroll up", ["k", "Up"]),
Expand Down
23 changes: 11 additions & 12 deletions tui/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,6 @@ impl AppState {
None
}

fn get_selected_description(&self) -> Option<String> {
self.get_selected_node()
.map(|node| node.description.clone())
}

pub fn go_to_selected_dir(&mut self) {
let mut selected_index = self.selection.selected().unwrap_or(0);

Expand Down Expand Up @@ -654,18 +649,19 @@ impl AppState {
}

fn enable_preview(&mut self) {
if let Some(list_node) = self.get_selected_node() {
let mut preview_title = "[Preview] - ".to_string();
preview_title.push_str(list_node.name.as_str());
if let Some(preview) = FloatingText::from_command(&list_node.command, preview_title) {
if let Some(node) = self.get_selected_node() {
let preview_title = format!("Command Preview - {}", node.name.as_str());
if let Some(preview) = FloatingText::from_command(&node.command, preview_title) {
self.spawn_float(preview, 80, 80);
}
}
}

fn enable_description(&mut self) {
if let Some(command_description) = self.get_selected_description() {
let description = FloatingText::new(command_description, "Command Description");
if let Some(node) = self.get_selected_node() {
let desc_title = format!("Command Description - {}", &node.name);

let description = FloatingText::new(node.description.clone(), desc_title);
self.spawn_float(description, 80, 80);
}
}
Expand Down Expand Up @@ -731,7 +727,10 @@ impl AppState {

fn toggle_task_list_guide(&mut self) {
self.spawn_float(
FloatingText::new(ACTIONS_GUIDE.to_string(), "Important Actions Guide"),
FloatingText::new(
ACTIONS_GUIDE.to_string(),
"Important Actions Guide".to_string(),
),
80,
80,
);
Expand Down

0 comments on commit 1a131a9

Please sign in to comment.