Skip to content

Commit 658e2fa

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

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

tui/src/floating_text.rs

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

3636
macro_rules! style {
@@ -125,7 +125,7 @@ fn get_lines_owned(s: &str) -> Vec<String> {
125125
}
126126

127127
impl FloatingText {
128-
pub fn new(text: String, title: &str) -> Self {
128+
pub fn new(text: String, title: String) -> Self {
129129
let src = get_lines(&text)
130130
.into_iter()
131131
.map(|s| s.to_string())
@@ -134,7 +134,7 @@ impl FloatingText {
134134
let max_line_width = max_width!(src);
135135
Self {
136136
src,
137-
mode_title: title.to_string(),
137+
title,
138138
max_line_width,
139139
v_scroll: 0,
140140
h_scroll: 0,
@@ -148,6 +148,7 @@ impl FloatingText {
148148
// just apply highlights directly
149149
(max_width!(get_lines(cmd)), Some(cmd.clone()))
150150
}
151+
151152
Command::LocalFile { file, .. } => {
152153
// have to read from tmp dir to get cmd src
153154
let raw = std::fs::read_to_string(file)
@@ -165,7 +166,7 @@ impl FloatingText {
165166

166167
Some(Self {
167168
src,
168-
mode_title: title,
169+
title,
169170
max_line_width,
170171
h_scroll: 0,
171172
v_scroll: 0,
@@ -201,10 +202,12 @@ impl FloatingText {
201202

202203
impl FloatContent for FloatingText {
203204
fn top_title(&self) -> Option<Line<'_>> {
204-
let title_text = format!(" {} ", self.mode_title);
205+
let title_text = format!(" {} ", self.title);
206+
205207
let title_line = Line::from(title_text)
206208
.centered()
207209
.style(Style::default().reversed());
210+
208211
Some(title_line)
209212
}
210213

@@ -279,7 +282,7 @@ impl FloatContent for FloatingText {
279282

280283
fn get_shortcut_list(&self) -> (&str, Box<[Shortcut]>) {
281284
(
282-
&self.mode_title,
285+
&self.title,
283286
Box::new([
284287
Shortcut::new("Scroll down", ["j", "Down"]),
285288
Shortcut::new("Scroll up", ["k", "Up"]),

tui/src/state.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -640,11 +640,6 @@ impl AppState {
640640
None
641641
}
642642

643-
fn get_selected_description(&self) -> Option<String> {
644-
self.get_selected_node()
645-
.map(|node| node.description.clone())
646-
}
647-
648643
pub fn go_to_selected_dir(&mut self) {
649644
let selected_index = self.selection.selected().unwrap_or(0);
650645

@@ -697,21 +692,20 @@ impl AppState {
697692
}
698693

699694
fn enable_preview(&mut self) {
700-
if let Some(list_node) = self.get_selected_node() {
701-
let mut preview_title = "[Preview] - ".to_string();
702-
preview_title.push_str(list_node.name.as_str());
703-
if let Some(preview) = FloatingText::from_command(&list_node.command, preview_title) {
695+
if let Some(node) = self.get_selected_node() {
696+
let preview_title = format!("Command Preview - {}", node.name.as_str());
697+
if let Some(preview) = FloatingText::from_command(&node.command, preview_title) {
704698
self.spawn_float(preview, 80, 80);
705699
}
706700
}
707701
}
708702

709703
fn enable_description(&mut self) {
710-
if let Some(command_description) = self.get_selected_description() {
711-
if !command_description.is_empty() {
712-
let description = FloatingText::new(command_description, "Command Description");
713-
self.spawn_float(description, 80, 80);
714-
}
704+
if let Some(node) = self.get_selected_node() {
705+
let desc_title = format!("Command Description - {}", &node.name);
706+
707+
let description = FloatingText::new(node.description.clone(), desc_title);
708+
self.spawn_float(description, 80, 80);
715709
}
716710
}
717711

@@ -795,7 +789,10 @@ impl AppState {
795789

796790
fn toggle_task_list_guide(&mut self) {
797791
self.spawn_float(
798-
FloatingText::new(ACTIONS_GUIDE.to_string(), "Important Actions Guide"),
792+
FloatingText::new(
793+
ACTIONS_GUIDE.to_string(),
794+
"Important Actions Guide".to_string(),
795+
),
799796
80,
800797
80,
801798
);

0 commit comments

Comments
 (0)