Skip to content

Commit 1a131a9

Browse files
use command names in FloatContent titles
Co-authored-by: Afonso Franco F. <[email protected]>
1 parent d7226ad commit 1a131a9

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

tui/src/floating_text.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct FloatingText {
2929
max_line_width: usize,
3030
v_scroll: usize,
3131
h_scroll: usize,
32-
mode_title: String,
32+
title: String,
3333
}
3434

3535
macro_rules! style {
@@ -124,7 +124,7 @@ fn get_lines_owned(s: &str) -> Vec<String> {
124124
}
125125

126126
impl FloatingText {
127-
pub fn new(text: String, title: &str) -> Self {
127+
pub fn new(text: String, title: String) -> Self {
128128
let src = get_lines(&text)
129129
.into_iter()
130130
.map(|s| s.to_string())
@@ -133,7 +133,7 @@ impl FloatingText {
133133
let max_line_width = max_width!(src);
134134
Self {
135135
src,
136-
mode_title: title.to_string(),
136+
title,
137137
max_line_width,
138138
v_scroll: 0,
139139
h_scroll: 0,
@@ -146,6 +146,7 @@ impl FloatingText {
146146
// just apply highlights directly
147147
(max_width!(get_lines(cmd)), Some(cmd.clone()))
148148
}
149+
149150
Command::LocalFile { file, .. } => {
150151
// have to read from tmp dir to get cmd src
151152
let raw = std::fs::read_to_string(file)
@@ -163,7 +164,7 @@ impl FloatingText {
163164

164165
Some(Self {
165166
src,
166-
mode_title: title,
167+
title,
167168
max_line_width,
168169
h_scroll: 0,
169170
v_scroll: 0,
@@ -197,10 +198,12 @@ impl FloatingText {
197198

198199
impl FloatContent for FloatingText {
199200
fn top_title(&self) -> Option<Line<'_>> {
200-
let title_text = format!(" {} ", self.mode_title);
201+
let title_text = format!(" {} ", self.title);
202+
201203
let title_line = Line::from(title_text)
202204
.centered()
203205
.style(Style::default().reversed());
206+
204207
Some(title_line)
205208
}
206209

@@ -274,7 +277,7 @@ impl FloatContent for FloatingText {
274277

275278
fn get_shortcut_list(&self) -> (&str, Box<[Shortcut]>) {
276279
(
277-
&self.mode_title,
280+
&self.title,
278281
Box::new([
279282
Shortcut::new("Scroll down", ["j", "Down"]),
280283
Shortcut::new("Scroll up", ["k", "Up"]),

tui/src/state.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -598,11 +598,6 @@ impl AppState {
598598
None
599599
}
600600

601-
fn get_selected_description(&self) -> Option<String> {
602-
self.get_selected_node()
603-
.map(|node| node.description.clone())
604-
}
605-
606601
pub fn go_to_selected_dir(&mut self) {
607602
let mut selected_index = self.selection.selected().unwrap_or(0);
608603

@@ -654,18 +649,19 @@ impl AppState {
654649
}
655650

656651
fn enable_preview(&mut self) {
657-
if let Some(list_node) = self.get_selected_node() {
658-
let mut preview_title = "[Preview] - ".to_string();
659-
preview_title.push_str(list_node.name.as_str());
660-
if let Some(preview) = FloatingText::from_command(&list_node.command, preview_title) {
652+
if let Some(node) = self.get_selected_node() {
653+
let preview_title = format!("Command Preview - {}", node.name.as_str());
654+
if let Some(preview) = FloatingText::from_command(&node.command, preview_title) {
661655
self.spawn_float(preview, 80, 80);
662656
}
663657
}
664658
}
665659

666660
fn enable_description(&mut self) {
667-
if let Some(command_description) = self.get_selected_description() {
668-
let description = FloatingText::new(command_description, "Command Description");
661+
if let Some(node) = self.get_selected_node() {
662+
let desc_title = format!("Command Description - {}", &node.name);
663+
664+
let description = FloatingText::new(node.description.clone(), desc_title);
669665
self.spawn_float(description, 80, 80);
670666
}
671667
}
@@ -731,7 +727,10 @@ impl AppState {
731727

732728
fn toggle_task_list_guide(&mut self) {
733729
self.spawn_float(
734-
FloatingText::new(ACTIONS_GUIDE.to_string(), "Important Actions Guide"),
730+
FloatingText::new(
731+
ACTIONS_GUIDE.to_string(),
732+
"Important Actions Guide".to_string(),
733+
),
735734
80,
736735
80,
737736
);

0 commit comments

Comments
 (0)