Skip to content

Commit f27852b

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

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

tui/src/floating_text.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub enum FloatingTextMode {
3232

3333
pub struct FloatingText {
3434
pub src: Vec<String>,
35+
name: Option<String>,
3536
max_line_width: usize,
3637
v_scroll: usize,
3738
h_scroll: usize,
@@ -130,7 +131,7 @@ fn get_lines_owned(s: &str) -> Vec<String> {
130131
}
131132

132133
impl FloatingText {
133-
pub fn new(text: String, mode: FloatingTextMode) -> Self {
134+
pub fn new(text: String, name: Option<String>, mode: FloatingTextMode) -> Self {
134135
let src = get_lines(&text)
135136
.into_iter()
136137
.map(|s| s.to_string())
@@ -139,19 +140,25 @@ impl FloatingText {
139140
let max_line_width = max_width!(src);
140141
Self {
141142
src,
143+
name,
142144
mode_title: Self::get_mode_title(mode),
143145
max_line_width,
144146
v_scroll: 0,
145147
h_scroll: 0,
146148
}
147149
}
148150

149-
pub fn from_command(command: &Command, mode: FloatingTextMode) -> Option<Self> {
151+
pub fn from_command(
152+
command: &Command,
153+
name: Option<String>,
154+
mode: FloatingTextMode,
155+
) -> Option<Self> {
150156
let (max_line_width, src) = match command {
151157
Command::Raw(cmd) => {
152158
// just apply highlights directly
153159
(max_width!(get_lines(cmd)), Some(cmd.clone()))
154160
}
161+
155162
Command::LocalFile { file, .. } => {
156163
// have to read from tmp dir to get cmd src
157164
let raw = std::fs::read_to_string(file)
@@ -169,6 +176,7 @@ impl FloatingText {
169176

170177
Some(Self {
171178
src,
179+
name,
172180
mode_title: Self::get_mode_title(mode),
173181
max_line_width,
174182
h_scroll: 0,
@@ -211,10 +219,16 @@ impl FloatingText {
211219

212220
impl FloatContent for FloatingText {
213221
fn top_title(&self) -> Option<Line<'_>> {
214-
let title_text = format!(" {} ", self.mode_title);
222+
let mut title_text = format!(" {} ", self.mode_title);
223+
224+
if let Some(ref name) = self.name {
225+
title_text = format!("{}- {} ", title_text, name);
226+
}
227+
215228
let title_line = Line::from(title_text)
216229
.centered()
217230
.style(Style::default().reversed());
231+
218232
Some(title_line)
219233
}
220234

tui/src/state.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -652,17 +652,22 @@ impl AppState {
652652

653653
fn enable_preview(&mut self) {
654654
if let Some(node) = self.get_selected_node() {
655-
if let Some(preview) =
656-
FloatingText::from_command(&node.command, FloatingTextMode::Preview)
657-
{
655+
if let Some(preview) = FloatingText::from_command(
656+
&node.command,
657+
Some(node.name.clone()),
658+
FloatingTextMode::Preview,
659+
) {
658660
self.spawn_float(preview, 80, 80);
659661
}
660662
}
661663
}
662664

663665
fn enable_description(&mut self) {
664666
if let Some(command_description) = self.get_selected_description() {
665-
let description = FloatingText::new(command_description, FloatingTextMode::Description);
667+
let name = self.get_selected_node().map(|node| node.name.clone());
668+
669+
let description =
670+
FloatingText::new(command_description, name, FloatingTextMode::Description);
666671
self.spawn_float(description, 80, 80);
667672
}
668673
}
@@ -728,7 +733,11 @@ impl AppState {
728733

729734
fn toggle_task_list_guide(&mut self) {
730735
self.spawn_float(
731-
FloatingText::new(ACTIONS_GUIDE.to_string(), FloatingTextMode::ActionsGuide),
736+
FloatingText::new(
737+
ACTIONS_GUIDE.to_string(),
738+
None,
739+
FloatingTextMode::ActionsGuide,
740+
),
732741
80,
733742
80,
734743
);

0 commit comments

Comments
 (0)