mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-05 13:15:21 +00:00
use command names in FloatContent
titles
Co-authored-by: Afonso Franco F. <afonso@francof.net>
This commit is contained in:
parent
763804a8d9
commit
658e2fa4ff
|
@ -29,8 +29,8 @@ pub struct FloatingText {
|
||||||
max_line_width: usize,
|
max_line_width: usize,
|
||||||
v_scroll: usize,
|
v_scroll: usize,
|
||||||
h_scroll: usize,
|
h_scroll: usize,
|
||||||
mode_title: String,
|
|
||||||
frame_height: usize,
|
frame_height: usize,
|
||||||
|
title: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! style {
|
macro_rules! style {
|
||||||
|
@ -125,7 +125,7 @@ fn get_lines_owned(s: &str) -> Vec<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FloatingText {
|
impl FloatingText {
|
||||||
pub fn new(text: String, title: &str) -> Self {
|
pub fn new(text: String, title: String) -> Self {
|
||||||
let src = get_lines(&text)
|
let src = get_lines(&text)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
|
@ -134,7 +134,7 @@ impl FloatingText {
|
||||||
let max_line_width = max_width!(src);
|
let max_line_width = max_width!(src);
|
||||||
Self {
|
Self {
|
||||||
src,
|
src,
|
||||||
mode_title: title.to_string(),
|
title,
|
||||||
max_line_width,
|
max_line_width,
|
||||||
v_scroll: 0,
|
v_scroll: 0,
|
||||||
h_scroll: 0,
|
h_scroll: 0,
|
||||||
|
@ -148,6 +148,7 @@ impl FloatingText {
|
||||||
// just apply highlights directly
|
// just apply highlights directly
|
||||||
(max_width!(get_lines(cmd)), Some(cmd.clone()))
|
(max_width!(get_lines(cmd)), Some(cmd.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::LocalFile { file, .. } => {
|
Command::LocalFile { file, .. } => {
|
||||||
// have to read from tmp dir to get cmd src
|
// have to read from tmp dir to get cmd src
|
||||||
let raw = std::fs::read_to_string(file)
|
let raw = std::fs::read_to_string(file)
|
||||||
|
@ -165,7 +166,7 @@ impl FloatingText {
|
||||||
|
|
||||||
Some(Self {
|
Some(Self {
|
||||||
src,
|
src,
|
||||||
mode_title: title,
|
title,
|
||||||
max_line_width,
|
max_line_width,
|
||||||
h_scroll: 0,
|
h_scroll: 0,
|
||||||
v_scroll: 0,
|
v_scroll: 0,
|
||||||
|
@ -201,10 +202,12 @@ impl FloatingText {
|
||||||
|
|
||||||
impl FloatContent for FloatingText {
|
impl FloatContent for FloatingText {
|
||||||
fn top_title(&self) -> Option<Line<'_>> {
|
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)
|
let title_line = Line::from(title_text)
|
||||||
.centered()
|
.centered()
|
||||||
.style(Style::default().reversed());
|
.style(Style::default().reversed());
|
||||||
|
|
||||||
Some(title_line)
|
Some(title_line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +282,7 @@ impl FloatContent for FloatingText {
|
||||||
|
|
||||||
fn get_shortcut_list(&self) -> (&str, Box<[Shortcut]>) {
|
fn get_shortcut_list(&self) -> (&str, Box<[Shortcut]>) {
|
||||||
(
|
(
|
||||||
&self.mode_title,
|
&self.title,
|
||||||
Box::new([
|
Box::new([
|
||||||
Shortcut::new("Scroll down", ["j", "Down"]),
|
Shortcut::new("Scroll down", ["j", "Down"]),
|
||||||
Shortcut::new("Scroll up", ["k", "Up"]),
|
Shortcut::new("Scroll up", ["k", "Up"]),
|
||||||
|
|
|
@ -640,11 +640,6 @@ impl AppState {
|
||||||
None
|
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) {
|
pub fn go_to_selected_dir(&mut self) {
|
||||||
let selected_index = self.selection.selected().unwrap_or(0);
|
let selected_index = self.selection.selected().unwrap_or(0);
|
||||||
|
|
||||||
|
@ -697,21 +692,20 @@ impl AppState {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enable_preview(&mut self) {
|
fn enable_preview(&mut self) {
|
||||||
if let Some(list_node) = self.get_selected_node() {
|
if let Some(node) = self.get_selected_node() {
|
||||||
let mut preview_title = "[Preview] - ".to_string();
|
let preview_title = format!("Command Preview - {}", node.name.as_str());
|
||||||
preview_title.push_str(list_node.name.as_str());
|
if let Some(preview) = FloatingText::from_command(&node.command, preview_title) {
|
||||||
if let Some(preview) = FloatingText::from_command(&list_node.command, preview_title) {
|
|
||||||
self.spawn_float(preview, 80, 80);
|
self.spawn_float(preview, 80, 80);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enable_description(&mut self) {
|
fn enable_description(&mut self) {
|
||||||
if let Some(command_description) = self.get_selected_description() {
|
if let Some(node) = self.get_selected_node() {
|
||||||
if !command_description.is_empty() {
|
let desc_title = format!("Command Description - {}", &node.name);
|
||||||
let description = FloatingText::new(command_description, "Command Description");
|
|
||||||
self.spawn_float(description, 80, 80);
|
let description = FloatingText::new(node.description.clone(), desc_title);
|
||||||
}
|
self.spawn_float(description, 80, 80);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -795,7 +789,10 @@ impl AppState {
|
||||||
|
|
||||||
fn toggle_task_list_guide(&mut self) {
|
fn toggle_task_list_guide(&mut self) {
|
||||||
self.spawn_float(
|
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,
|
||||||
80,
|
80,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user