Skip to content

Commit 26a2f11

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

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
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

+14-6
Original file line numberDiff line numberDiff line change
@@ -654,18 +654,23 @@ impl AppState {
654654
}
655655

656656
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) {
657+
if let Some(node) = self.get_selected_node() {
658+
let preview_title = format!("Command Preview - {}", node.name.as_str());
659+
if let Some(preview) = FloatingText::from_command(&node.command, preview_title) {
661660
self.spawn_float(preview, 80, 80);
662661
}
663662
}
664663
}
665664

666665
fn enable_description(&mut self) {
667666
if let Some(command_description) = self.get_selected_description() {
668-
let description = FloatingText::new(command_description, "Command Description");
667+
let mut desc_title = "Command Description ".to_string();
668+
669+
if let Some(name) = self.get_selected_node().map(|node| node.name.clone()) {
670+
desc_title = format!("{desc_title}- {name}");
671+
}
672+
673+
let description = FloatingText::new(command_description, desc_title);
669674
self.spawn_float(description, 80, 80);
670675
}
671676
}
@@ -731,7 +736,10 @@ impl AppState {
731736

732737
fn toggle_task_list_guide(&mut self) {
733738
self.spawn_float(
734-
FloatingText::new(ACTIONS_GUIDE.to_string(), "Important Actions Guide"),
739+
FloatingText::new(
740+
ACTIONS_GUIDE.to_string(),
741+
" Important Actions Guide ".to_string(),
742+
),
735743
80,
736744
80,
737745
);

0 commit comments

Comments
 (0)