mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-21 21:09:42 +00:00
feat: Command Description (#437)
* Implement about page Add title Add hints * Add descriptions for commands * Refactor about to description
This commit is contained in:
parent
969c83dda6
commit
a7e6ea0246
|
@ -24,6 +24,7 @@ pub fn get_tabs(validate: bool) -> Vec<Tab> {
|
|||
.map(|(TabEntry { name, data }, directory)| {
|
||||
let mut tree = Tree::new(ListNode {
|
||||
name: "root".to_string(),
|
||||
description: "".to_string(),
|
||||
command: Command::None,
|
||||
});
|
||||
let mut root = tree.root_mut();
|
||||
|
@ -146,12 +147,14 @@ fn create_directory(data: Vec<Entry>, node: &mut NodeMut<ListNode>, command_dir:
|
|||
if let Some(entries) = entry.entries {
|
||||
let mut node = node.append(ListNode {
|
||||
name: entry.name,
|
||||
description: entry.description,
|
||||
command: Command::None,
|
||||
});
|
||||
create_directory(entries, &mut node, command_dir);
|
||||
} else if let Some(command) = entry.command {
|
||||
node.append(ListNode {
|
||||
name: entry.name,
|
||||
description: entry.description,
|
||||
command: Command::Raw(command),
|
||||
});
|
||||
} else if let Some(script) = entry.script {
|
||||
|
@ -161,6 +164,7 @@ fn create_directory(data: Vec<Entry>, node: &mut NodeMut<ListNode>, command_dir:
|
|||
}
|
||||
node.append(ListNode {
|
||||
name: entry.name,
|
||||
description: entry.description,
|
||||
command: Command::LocalFile(dir),
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -21,5 +21,6 @@ pub struct Tab {
|
|||
#[derive(Clone, Hash, Eq, PartialEq)]
|
||||
pub struct ListNode {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub command: Command,
|
||||
}
|
||||
|
|
|
@ -2,32 +2,40 @@ name = "Applications Setup"
|
|||
|
||||
[[data]]
|
||||
name = "Alacritty"
|
||||
description = "Alacritty is a modern terminal emulator that comes with sensible defaults, but allows for extensive configuration. By integrating with other applications, rather than reimplementing their functionality, it manages to provide a flexible set of features with high performance. The supported platforms currently consist of BSD, Linux, macOS and Windows.\nThis command installs and condifures alacritty terminal emulator."
|
||||
script = "alacritty-setup.sh"
|
||||
|
||||
[[data]]
|
||||
name = "Bash Prompt"
|
||||
description = "The .bashrc file is a script that runs every time a new terminal session is started in Unix-like operating systems.\nIt is used to configure the shell session, set up aliases, define functions, and more, making the terminal easier to use and more powerful.\nThis command configures the key sections and functionalities defined in the .bashrc file from CTT's mybash repository.\nhttps://github.com/ChrisTitusTech/mybash"
|
||||
script = "mybash-setup.sh"
|
||||
|
||||
[[data]]
|
||||
name = "DWM-Titus"
|
||||
description = "DWM is a dynamic window manager for X.\nIt manages windows in tiled, monocle and floating layouts.\nAll of the layouts can be applied dynamically, optimising the environment for the application in use and the task performed.\nThis command installs and configures DWM and a desktop manager.\nThe list of patches applied can be found in CTT's DWM repository\nhttps://github.com/ChrisTitusTech/dwm-titus"
|
||||
script = "dwmtitus-setup.sh"
|
||||
|
||||
[[data]]
|
||||
name = "Kitty"
|
||||
description = "kitty is a free and open-source GPU-accelerated terminal emulator for Linux, macOS, and some BSD distributions, focused on performance and features.\nkitty is written in a mix of C and Python programming languages.\n This command installs and configures kitty."
|
||||
script = "kitty-setup.sh"
|
||||
|
||||
[[data]]
|
||||
name = "Neovim"
|
||||
description = "Neovim is a refactor, and sometimes redactor, in the tradition of Vim.\nIt is not a rewrite but a continuation and extension of Vim.\nThis command configures neovim from CTT's neovim configuration.\nhttps://github.com/ChrisTitusTech/neovim"
|
||||
script = "neovim-setup.sh"
|
||||
|
||||
[[data]]
|
||||
name = "Rofi"
|
||||
description = "Rofi is a window switcher, run dialog, ssh-launcher and dmenu replacement that started as a clone of simpleswitcher, written by Sean Pringle and later expanded by Dave Davenport.\nThis command installs and configures rofi with configuration from CTT's DWM repo.\nhttps://github.com/ChrisTitusTech/dwm-titus"
|
||||
script = "rofi-setup.sh"
|
||||
|
||||
[[data]]
|
||||
name = "ZSH Prompt"
|
||||
description = "The Z shell is a Unix shell that can be used as an interactive login shell and as a command interpreter for shell scripting. Zsh is an extended Bourne shell with many improvements, including some features of Bash, ksh, and tcsh.\nThis command installs ZSH prompt and provides basic configuration."
|
||||
script = "zsh-setup.sh"
|
||||
|
||||
[[data]]
|
||||
name = "Fastfetch"
|
||||
script = "fastfetch-setup.sh"
|
||||
description = "Fastfetch is a neofetch-like tool for fetching system information and displaying it prettily.\nIt is written mainly in C, with performance and customizability in mind.\nThis command installs fastfetch and configures from CTT's mybash repository.\nhttps://github.com/ChrisTitusTech/mybash"
|
||||
script = "fastfetch-setup.sh"
|
||||
|
|
|
@ -5,4 +5,5 @@ name = "Diablo II Resurrected"
|
|||
|
||||
[[data.entries]]
|
||||
name = "Loot Filter Install"
|
||||
description = "This is a loot filter for Diablo II Resurrected.\nIt's designed to be a simple, clean, and easy to read loot filter that highlights the most important items.\nWorks on battle.net and single player.\nNo frills, no config, just highlights high runes and other valuable items.\nFor more information visit: https://github.com/ChrisTitusTech/d2r-loot-filter"
|
||||
script = "diablo-ii/d2r-loot-filters.sh"
|
||||
|
|
|
@ -2,4 +2,5 @@ name = "Security"
|
|||
|
||||
[[data]]
|
||||
name = "Firewall Baselines (CTT)"
|
||||
description = "Developed to ease iptables firewall configuration, UFW provides a user friendly way to create an IPv4 or IPv6 host-based firewall.\nThis command installs UFW and configures UFW based on CTT's recommended rules.\nFor more information visit: https://christitus.com/linux-security-mistakes"
|
||||
script = "firewall-baselines.sh"
|
||||
|
|
|
@ -10,14 +10,17 @@ values = ["pacman"]
|
|||
|
||||
[[data.entries]]
|
||||
name = "Arch Server Setup"
|
||||
description = "This command installs a minimal arch server setup under 5 minutes."
|
||||
script = "arch/server-setup.sh"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Paru AUR Helper"
|
||||
description = "Paru is your standard pacman wrapping AUR helper with lots of features and minimal interaction.\nTo know more about AUR helpers visit: https://wiki.archlinux.org/title/AUR_helpers"
|
||||
script = "arch/paru-setup.sh"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Yay AUR Helper"
|
||||
description = "Yet Another Yogurt - An AUR Helper Written in Go.\nTo know more about AUR helpers visit: https://wiki.archlinux.org/title/AUR_helpers"
|
||||
script = "arch/yay-setup.sh"
|
||||
|
||||
[[data]]
|
||||
|
@ -30,26 +33,32 @@ values = ["dnf"]
|
|||
|
||||
[[data.entries]]
|
||||
name = "RPM Fusion Setup"
|
||||
description = "RPM Fusion provides software that the Fedora Project or Red Hat doesn't want to ship.\nThat software is provided as precompiled RPMs for all current Fedora versions and current Red Hat Enterprise Linux or clones versions; you can use the RPM Fusion repositories with tools like yum and PackageKit.\nFor more information visit: https://rpmfusion.org/"
|
||||
script = "fedora/rpm-fusion-setup.sh"
|
||||
|
||||
[[data]]
|
||||
name = "Full System Update"
|
||||
description = "This command updates your system to the latest packages available for your distro"
|
||||
script = "system-update.sh"
|
||||
|
||||
[[data]]
|
||||
name = "Build Prerequisites"
|
||||
description = "This script is designed to handle the installation of various software dependencies across different Linux distributions"
|
||||
script = "1-compile-setup.sh"
|
||||
|
||||
[[data]]
|
||||
name = "Gaming Dependencies"
|
||||
description = "This script is designed to handle the installation of gaming dependencies across different Linux distributions"
|
||||
script = "2-gaming-setup.sh"
|
||||
|
||||
[[data]]
|
||||
name = "Global Theme"
|
||||
description = "This script is designed to handle the installation and configuration of global theming"
|
||||
script = "3-global-theme.sh"
|
||||
|
||||
[[data]]
|
||||
name = "Remove Snaps"
|
||||
description = "This script is designed to remove snap"
|
||||
script = "4-remove-snaps.sh"
|
||||
|
||||
[[data]]
|
||||
|
|
|
@ -2,22 +2,27 @@ name = "Utilities"
|
|||
|
||||
[[data]]
|
||||
name = "WiFi Manager"
|
||||
description = "This utility is designed to manage wifi in your system"
|
||||
script = "wifi-control.sh"
|
||||
|
||||
[[data]]
|
||||
name = "Bluetooth Manager"
|
||||
description = "This utility is designed to manage bluetooth in your system"
|
||||
script = "bluetooth-control.sh"
|
||||
|
||||
[[data]]
|
||||
name = "Numlock on Startup"
|
||||
description = "This utility is designed to configure auto enabling of numlock on boot"
|
||||
script = "numlock.sh"
|
||||
|
||||
[[data]]
|
||||
name = "Ollama"
|
||||
description = "This utility is designed to manage ollama in your system"
|
||||
script = "ollama.sh"
|
||||
|
||||
[[data]]
|
||||
name = "Service Manager"
|
||||
description = "This utility is designed to manage services in your system"
|
||||
script = "service-control.sh"
|
||||
|
||||
[[data]]
|
||||
|
@ -51,42 +56,52 @@ values = [":0", ":1", ":2", ":3", ":4", ":5", ":6", ":7", ":8", ":9"]
|
|||
|
||||
[[data.entries]]
|
||||
name = "Duplicate Displays"
|
||||
description = "This utility is designed to duplicate display among multi-monitor setup in your system"
|
||||
script = "monitor-control/duplicate_displays.sh"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Extend Displays"
|
||||
description = "This utility is designed to extend display among multi-monitor setup in your system"
|
||||
script = "monitor-control/extend_displays.sh"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Auto Detect Displays"
|
||||
description = "This utility is designed to detect and apply recommended configuration for monitors connected with your system"
|
||||
script = "monitor-control/auto_detect_displays.sh"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Enable Monitor"
|
||||
description = "This utility is designed to enable a monitor in your system"
|
||||
script = "monitor-control/enable_monitor.sh"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Disable Monitor"
|
||||
description = "This utility is designed to disable a monitor in your system"
|
||||
script = "monitor-control/disable_monitor.sh"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Set Primary Monitor"
|
||||
description = "This utility is designed to set a Primary monitor in your system"
|
||||
script = "monitor-control/set_primary_monitor.sh"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Change Orientation"
|
||||
description = "This utility is designed to change the orientation of monitors in your system"
|
||||
script = "monitor-control/change_orientation.sh"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Manage Arrangement"
|
||||
description = "This utility is designed to arrange monitors in multi-monitor setup in your system"
|
||||
script = "monitor-control/manage_arrangement.sh"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Scale Monitors"
|
||||
description = "This utility is designed to change the scaling of monitors in your system"
|
||||
script = "monitor-control/scale_monitor.sh"
|
||||
|
||||
[[data.entries]]
|
||||
name = "Reset Scaling"
|
||||
description = "This utility is designed to reset scaling of a monitor in your system"
|
||||
script = "monitor-control/reset_scaling.sh"
|
||||
matches = true
|
||||
|
||||
|
|
|
@ -64,7 +64,9 @@ impl Float {
|
|||
// Returns true if the floating window is finished.
|
||||
pub fn handle_key_event(&mut self, key: &KeyEvent) -> bool {
|
||||
match key.code {
|
||||
KeyCode::Enter | KeyCode::Char('p') | KeyCode::Esc if self.content.is_finished() => {
|
||||
KeyCode::Enter | KeyCode::Char('p') | KeyCode::Char('d') | KeyCode::Esc
|
||||
if self.content.is_finished() =>
|
||||
{
|
||||
true
|
||||
}
|
||||
_ => self.content.handle_key_event(key),
|
||||
|
|
|
@ -11,18 +11,26 @@ use ratatui::{
|
|||
widgets::{Block, Borders, List},
|
||||
Frame,
|
||||
};
|
||||
|
||||
pub enum FloatingTextMode {
|
||||
Preview,
|
||||
Description,
|
||||
}
|
||||
pub struct FloatingText {
|
||||
text: Vec<String>,
|
||||
mode: FloatingTextMode,
|
||||
scroll: usize,
|
||||
}
|
||||
|
||||
impl FloatingText {
|
||||
pub fn new(text: Vec<String>) -> Self {
|
||||
Self { text, scroll: 0 }
|
||||
pub fn new(text: Vec<String>, mode: FloatingTextMode) -> Self {
|
||||
Self {
|
||||
text,
|
||||
scroll: 0,
|
||||
mode,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_command(command: &Command) -> Option<Self> {
|
||||
pub fn from_command(command: &Command, mode: FloatingTextMode) -> Option<Self> {
|
||||
let lines = match command {
|
||||
Command::Raw(cmd) => {
|
||||
// Reconstruct the line breaks and file formatting after the
|
||||
|
@ -38,7 +46,7 @@ impl FloatingText {
|
|||
// If command is a folder, we don't display a preview
|
||||
Command::None => return None,
|
||||
};
|
||||
Some(Self::new(lines))
|
||||
Some(Self::new(lines, mode))
|
||||
}
|
||||
|
||||
fn scroll_down(&mut self) {
|
||||
|
@ -57,8 +65,16 @@ impl FloatingText {
|
|||
impl FloatContent for FloatingText {
|
||||
fn draw(&mut self, frame: &mut Frame, area: Rect) {
|
||||
// Define the Block with a border and background color
|
||||
let block_title = match self.mode {
|
||||
FloatingTextMode::Preview => "Command Preview",
|
||||
FloatingTextMode::Description => "Command Description",
|
||||
};
|
||||
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title(block_title)
|
||||
.title_alignment(ratatui::layout::Alignment::Center)
|
||||
.title_style(Style::default().reversed())
|
||||
.style(Style::default());
|
||||
|
||||
// Draw the Block first
|
||||
|
@ -68,7 +84,7 @@ impl FloatContent for FloatingText {
|
|||
let inner_area = block.inner(area);
|
||||
|
||||
// Create the list of lines to be displayed
|
||||
let lines: Vec<Line> = self
|
||||
let mut lines: Vec<Line> = self
|
||||
.text
|
||||
.iter()
|
||||
.skip(self.scroll)
|
||||
|
@ -86,6 +102,10 @@ impl FloatContent for FloatingText {
|
|||
.map(Line::from)
|
||||
.collect();
|
||||
|
||||
// Prevents background text from appearing after the floating content
|
||||
while lines.len() < inner_area.height as usize {
|
||||
lines.push(Line::from(" ".repeat(inner_area.width as usize)));
|
||||
}
|
||||
// Create list widget
|
||||
let list = List::new(lines)
|
||||
.block(Block::default())
|
||||
|
|
|
@ -131,6 +131,7 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) {
|
|||
hints.push(get_list_item_shortcut(state));
|
||||
if state.selected_item_is_cmd() {
|
||||
hints.push(Shortcut::new(vec!["p"], "Enable preview"));
|
||||
hints.push(Shortcut::new(vec!["d"], "Command Description"));
|
||||
}
|
||||
}
|
||||
hints.push(Shortcut::new(vec!["Tab"], "Focus tab list"));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
filter::{Filter, SearchAction},
|
||||
float::{Float, FloatContent},
|
||||
floating_text::FloatingText,
|
||||
floating_text::{FloatingText, FloatingTextMode},
|
||||
hint::{draw_shortcuts, SHORTCUT_LINES},
|
||||
running_command::RunningCommand,
|
||||
theme::Theme,
|
||||
|
@ -294,6 +294,7 @@ impl AppState {
|
|||
KeyCode::Char('j') | KeyCode::Down => self.selection.select_next(),
|
||||
KeyCode::Char('k') | KeyCode::Up => self.selection.select_previous(),
|
||||
KeyCode::Char('p') => self.enable_preview(),
|
||||
KeyCode::Char('d') => self.enable_description(),
|
||||
KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => self.handle_enter(),
|
||||
KeyCode::Char('h') | KeyCode::Left => {
|
||||
if self.at_root() {
|
||||
|
@ -351,6 +352,23 @@ impl AppState {
|
|||
}
|
||||
None
|
||||
}
|
||||
fn get_selected_description(&mut self) -> Option<String> {
|
||||
let mut selected_index = self.selection.selected().unwrap_or(0);
|
||||
|
||||
if !self.at_root() && selected_index == 0 {
|
||||
return None;
|
||||
}
|
||||
if !self.at_root() {
|
||||
selected_index = selected_index.saturating_sub(1);
|
||||
}
|
||||
|
||||
if let Some(item) = self.filter.item_list().get(selected_index) {
|
||||
if !item.has_children {
|
||||
return Some(item.node.description.clone());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
pub fn go_to_selected_dir(&mut self) {
|
||||
let mut selected_index = self.selection.selected().unwrap_or(0);
|
||||
|
||||
|
@ -413,11 +431,23 @@ impl AppState {
|
|||
}
|
||||
fn enable_preview(&mut self) {
|
||||
if let Some(command) = self.get_selected_command() {
|
||||
if let Some(preview) = FloatingText::from_command(&command) {
|
||||
if let Some(preview) = FloatingText::from_command(&command, FloatingTextMode::Preview) {
|
||||
self.spawn_float(preview, 80, 80);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn enable_description(&mut self) {
|
||||
if let Some(command_description) = self.get_selected_description() {
|
||||
let description_content: Vec<String> = vec![]
|
||||
.into_iter()
|
||||
.chain(command_description.lines().map(|line| line.to_string())) // New line when \n is given in toml
|
||||
.collect();
|
||||
|
||||
let description = FloatingText::new(description_content, FloatingTextMode::Description);
|
||||
self.spawn_float(description, 80, 80);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_enter(&mut self) {
|
||||
if let Some(cmd) = self.get_selected_command() {
|
||||
let command = RunningCommand::new(cmd);
|
||||
|
|
Loading…
Reference in New Issue
Block a user