mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-21 21:09:42 +00:00
Merge pull request #633 from afonsofrancof:generic-popup-title
Made popup title customizable. The Script's preview title is now its command name
This commit is contained in:
commit
abebe9bee1
|
@ -24,18 +24,12 @@ use tree_sitter_bash as hl_bash;
|
|||
use tree_sitter_highlight::{self as hl, HighlightEvent};
|
||||
use zips::zip_result;
|
||||
|
||||
pub enum FloatingTextMode {
|
||||
Preview,
|
||||
Description,
|
||||
ActionsGuide,
|
||||
}
|
||||
|
||||
pub struct FloatingText {
|
||||
pub src: Vec<String>,
|
||||
max_line_width: usize,
|
||||
v_scroll: usize,
|
||||
h_scroll: usize,
|
||||
mode_title: &'static str,
|
||||
mode_title: String,
|
||||
}
|
||||
|
||||
macro_rules! style {
|
||||
|
@ -130,7 +124,7 @@ fn get_lines_owned(s: &str) -> Vec<String> {
|
|||
}
|
||||
|
||||
impl FloatingText {
|
||||
pub fn new(text: String, mode: FloatingTextMode) -> Self {
|
||||
pub fn new(text: String, title: &str) -> Self {
|
||||
let src = get_lines(&text)
|
||||
.into_iter()
|
||||
.map(|s| s.to_string())
|
||||
|
@ -139,14 +133,14 @@ impl FloatingText {
|
|||
let max_line_width = max_width!(src);
|
||||
Self {
|
||||
src,
|
||||
mode_title: Self::get_mode_title(mode),
|
||||
mode_title: title.to_string(),
|
||||
max_line_width,
|
||||
v_scroll: 0,
|
||||
h_scroll: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_command(command: &Command, mode: FloatingTextMode) -> Option<Self> {
|
||||
pub fn from_command(command: &Command, title: String) -> Option<Self> {
|
||||
let (max_line_width, src) = match command {
|
||||
Command::Raw(cmd) => {
|
||||
// just apply highlights directly
|
||||
|
@ -169,21 +163,13 @@ impl FloatingText {
|
|||
|
||||
Some(Self {
|
||||
src,
|
||||
mode_title: Self::get_mode_title(mode),
|
||||
mode_title: title,
|
||||
max_line_width,
|
||||
h_scroll: 0,
|
||||
v_scroll: 0,
|
||||
})
|
||||
}
|
||||
|
||||
fn get_mode_title(mode: FloatingTextMode) -> &'static str {
|
||||
match mode {
|
||||
FloatingTextMode::Preview => "Command Preview",
|
||||
FloatingTextMode::Description => "Command Description",
|
||||
FloatingTextMode::ActionsGuide => "Important Actions Guide",
|
||||
}
|
||||
}
|
||||
|
||||
fn scroll_down(&mut self) {
|
||||
if self.v_scroll + 1 < self.src.len() {
|
||||
self.v_scroll += 1;
|
||||
|
@ -214,7 +200,7 @@ impl FloatContent for FloatingText {
|
|||
// Define the Block with a border and background color
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title(self.mode_title)
|
||||
.title(self.mode_title.clone())
|
||||
.title_alignment(ratatui::layout::Alignment::Center)
|
||||
.title_style(Style::default().reversed())
|
||||
.style(Style::default());
|
||||
|
@ -292,7 +278,7 @@ impl FloatContent for FloatingText {
|
|||
|
||||
fn get_shortcut_list(&self) -> (&str, Box<[Shortcut]>) {
|
||||
(
|
||||
self.mode_title,
|
||||
&self.mode_title,
|
||||
Box::new([
|
||||
Shortcut::new("Scroll down", ["j", "Down"]),
|
||||
Shortcut::new("Scroll up", ["k", "Up"]),
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
use std::rc::Rc;
|
||||
|
||||
use crate::{
|
||||
confirmation::{ConfirmPrompt, ConfirmStatus},
|
||||
filter::{Filter, SearchAction},
|
||||
float::{Float, FloatContent},
|
||||
floating_text::{FloatingText, FloatingTextMode},
|
||||
floating_text::FloatingText,
|
||||
hint::{create_shortcut_list, Shortcut},
|
||||
running_command::RunningCommand,
|
||||
theme::Theme,
|
||||
|
@ -21,6 +19,7 @@ use ratatui::{
|
|||
widgets::{Block, Borders, List, ListState, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
use temp_dir::TempDir;
|
||||
|
||||
const MIN_WIDTH: u16 = 77;
|
||||
|
@ -655,10 +654,10 @@ impl AppState {
|
|||
}
|
||||
|
||||
fn enable_preview(&mut self) {
|
||||
if let Some(node) = self.get_selected_node() {
|
||||
if let Some(preview) =
|
||||
FloatingText::from_command(&node.command, FloatingTextMode::Preview)
|
||||
{
|
||||
if let Some(list_node) = self.get_selected_node() {
|
||||
let mut preview_title = "[Preview] - ".to_string();
|
||||
preview_title.push_str(list_node.name.as_str());
|
||||
if let Some(preview) = FloatingText::from_command(&list_node.command, preview_title) {
|
||||
self.spawn_float(preview, 80, 80);
|
||||
}
|
||||
}
|
||||
|
@ -666,7 +665,7 @@ impl AppState {
|
|||
|
||||
fn enable_description(&mut self) {
|
||||
if let Some(command_description) = self.get_selected_description() {
|
||||
let description = FloatingText::new(command_description, FloatingTextMode::Description);
|
||||
let description = FloatingText::new(command_description, "Command Description");
|
||||
self.spawn_float(description, 80, 80);
|
||||
}
|
||||
}
|
||||
|
@ -732,7 +731,7 @@ impl AppState {
|
|||
|
||||
fn toggle_task_list_guide(&mut self) {
|
||||
self.spawn_float(
|
||||
FloatingText::new(ACTIONS_GUIDE.to_string(), FloatingTextMode::ActionsGuide),
|
||||
FloatingText::new(ACTIONS_GUIDE.to_string(), "Important Actions Guide"),
|
||||
80,
|
||||
80,
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue
Block a user