feat: Command Description (#437)

* Implement about page

Add title

Add hints

* Add descriptions for commands

* Refactor about to description
This commit is contained in:
JEEVITHA KANNAN K S 2024-09-19 05:47:08 +05:30 committed by GitHub
parent 969c83dda6
commit a7e6ea0246
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 102 additions and 10 deletions

View File

@ -24,6 +24,7 @@ pub fn get_tabs(validate: bool) -> Vec<Tab> {
.map(|(TabEntry { name, data }, directory)| { .map(|(TabEntry { name, data }, directory)| {
let mut tree = Tree::new(ListNode { let mut tree = Tree::new(ListNode {
name: "root".to_string(), name: "root".to_string(),
description: "".to_string(),
command: Command::None, command: Command::None,
}); });
let mut root = tree.root_mut(); 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 { if let Some(entries) = entry.entries {
let mut node = node.append(ListNode { let mut node = node.append(ListNode {
name: entry.name, name: entry.name,
description: entry.description,
command: Command::None, command: Command::None,
}); });
create_directory(entries, &mut node, command_dir); create_directory(entries, &mut node, command_dir);
} else if let Some(command) = entry.command { } else if let Some(command) = entry.command {
node.append(ListNode { node.append(ListNode {
name: entry.name, name: entry.name,
description: entry.description,
command: Command::Raw(command), command: Command::Raw(command),
}); });
} else if let Some(script) = entry.script { } 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 { node.append(ListNode {
name: entry.name, name: entry.name,
description: entry.description,
command: Command::LocalFile(dir), command: Command::LocalFile(dir),
}); });
} else { } else {

View File

@ -21,5 +21,6 @@ pub struct Tab {
#[derive(Clone, Hash, Eq, PartialEq)] #[derive(Clone, Hash, Eq, PartialEq)]
pub struct ListNode { pub struct ListNode {
pub name: String, pub name: String,
pub description: String,
pub command: Command, pub command: Command,
} }

View File

@ -2,32 +2,40 @@ name = "Applications Setup"
[[data]] [[data]]
name = "Alacritty" 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" script = "alacritty-setup.sh"
[[data]] [[data]]
name = "Bash Prompt" 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" script = "mybash-setup.sh"
[[data]] [[data]]
name = "DWM-Titus" 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" script = "dwmtitus-setup.sh"
[[data]] [[data]]
name = "Kitty" 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" script = "kitty-setup.sh"
[[data]] [[data]]
name = "Neovim" 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" script = "neovim-setup.sh"
[[data]] [[data]]
name = "Rofi" 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" script = "rofi-setup.sh"
[[data]] [[data]]
name = "ZSH Prompt" 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" script = "zsh-setup.sh"
[[data]] [[data]]
name = "Fastfetch" name = "Fastfetch"
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" script = "fastfetch-setup.sh"

View File

@ -5,4 +5,5 @@ name = "Diablo II Resurrected"
[[data.entries]] [[data.entries]]
name = "Loot Filter Install" 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" script = "diablo-ii/d2r-loot-filters.sh"

View File

@ -2,4 +2,5 @@ name = "Security"
[[data]] [[data]]
name = "Firewall Baselines (CTT)" 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" script = "firewall-baselines.sh"

View File

@ -10,14 +10,17 @@ values = ["pacman"]
[[data.entries]] [[data.entries]]
name = "Arch Server Setup" name = "Arch Server Setup"
description = "This command installs a minimal arch server setup under 5 minutes."
script = "arch/server-setup.sh" script = "arch/server-setup.sh"
[[data.entries]] [[data.entries]]
name = "Paru AUR Helper" 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" script = "arch/paru-setup.sh"
[[data.entries]] [[data.entries]]
name = "Yay AUR Helper" 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" script = "arch/yay-setup.sh"
[[data]] [[data]]
@ -30,26 +33,32 @@ values = ["dnf"]
[[data.entries]] [[data.entries]]
name = "RPM Fusion Setup" 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" script = "fedora/rpm-fusion-setup.sh"
[[data]] [[data]]
name = "Full System Update" name = "Full System Update"
description = "This command updates your system to the latest packages available for your distro"
script = "system-update.sh" script = "system-update.sh"
[[data]] [[data]]
name = "Build Prerequisites" 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" script = "1-compile-setup.sh"
[[data]] [[data]]
name = "Gaming Dependencies" name = "Gaming Dependencies"
description = "This script is designed to handle the installation of gaming dependencies across different Linux distributions"
script = "2-gaming-setup.sh" script = "2-gaming-setup.sh"
[[data]] [[data]]
name = "Global Theme" name = "Global Theme"
description = "This script is designed to handle the installation and configuration of global theming"
script = "3-global-theme.sh" script = "3-global-theme.sh"
[[data]] [[data]]
name = "Remove Snaps" name = "Remove Snaps"
description = "This script is designed to remove snap"
script = "4-remove-snaps.sh" script = "4-remove-snaps.sh"
[[data]] [[data]]

View File

@ -2,22 +2,27 @@ name = "Utilities"
[[data]] [[data]]
name = "WiFi Manager" name = "WiFi Manager"
description = "This utility is designed to manage wifi in your system"
script = "wifi-control.sh" script = "wifi-control.sh"
[[data]] [[data]]
name = "Bluetooth Manager" name = "Bluetooth Manager"
description = "This utility is designed to manage bluetooth in your system"
script = "bluetooth-control.sh" script = "bluetooth-control.sh"
[[data]] [[data]]
name = "Numlock on Startup" name = "Numlock on Startup"
description = "This utility is designed to configure auto enabling of numlock on boot"
script = "numlock.sh" script = "numlock.sh"
[[data]] [[data]]
name = "Ollama" name = "Ollama"
description = "This utility is designed to manage ollama in your system"
script = "ollama.sh" script = "ollama.sh"
[[data]] [[data]]
name = "Service Manager" name = "Service Manager"
description = "This utility is designed to manage services in your system"
script = "service-control.sh" script = "service-control.sh"
[[data]] [[data]]
@ -51,42 +56,52 @@ values = [":0", ":1", ":2", ":3", ":4", ":5", ":6", ":7", ":8", ":9"]
[[data.entries]] [[data.entries]]
name = "Duplicate Displays" name = "Duplicate Displays"
description = "This utility is designed to duplicate display among multi-monitor setup in your system"
script = "monitor-control/duplicate_displays.sh" script = "monitor-control/duplicate_displays.sh"
[[data.entries]] [[data.entries]]
name = "Extend Displays" name = "Extend Displays"
description = "This utility is designed to extend display among multi-monitor setup in your system"
script = "monitor-control/extend_displays.sh" script = "monitor-control/extend_displays.sh"
[[data.entries]] [[data.entries]]
name = "Auto Detect Displays" 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" script = "monitor-control/auto_detect_displays.sh"
[[data.entries]] [[data.entries]]
name = "Enable Monitor" name = "Enable Monitor"
description = "This utility is designed to enable a monitor in your system"
script = "monitor-control/enable_monitor.sh" script = "monitor-control/enable_monitor.sh"
[[data.entries]] [[data.entries]]
name = "Disable Monitor" name = "Disable Monitor"
description = "This utility is designed to disable a monitor in your system"
script = "monitor-control/disable_monitor.sh" script = "monitor-control/disable_monitor.sh"
[[data.entries]] [[data.entries]]
name = "Set Primary Monitor" name = "Set Primary Monitor"
description = "This utility is designed to set a Primary monitor in your system"
script = "monitor-control/set_primary_monitor.sh" script = "monitor-control/set_primary_monitor.sh"
[[data.entries]] [[data.entries]]
name = "Change Orientation" name = "Change Orientation"
description = "This utility is designed to change the orientation of monitors in your system"
script = "monitor-control/change_orientation.sh" script = "monitor-control/change_orientation.sh"
[[data.entries]] [[data.entries]]
name = "Manage Arrangement" name = "Manage Arrangement"
description = "This utility is designed to arrange monitors in multi-monitor setup in your system"
script = "monitor-control/manage_arrangement.sh" script = "monitor-control/manage_arrangement.sh"
[[data.entries]] [[data.entries]]
name = "Scale Monitors" name = "Scale Monitors"
description = "This utility is designed to change the scaling of monitors in your system"
script = "monitor-control/scale_monitor.sh" script = "monitor-control/scale_monitor.sh"
[[data.entries]] [[data.entries]]
name = "Reset Scaling" name = "Reset Scaling"
description = "This utility is designed to reset scaling of a monitor in your system"
script = "monitor-control/reset_scaling.sh" script = "monitor-control/reset_scaling.sh"
matches = true matches = true

View File

@ -64,7 +64,9 @@ impl Float {
// Returns true if the floating window is finished. // Returns true if the floating window is finished.
pub fn handle_key_event(&mut self, key: &KeyEvent) -> bool { pub fn handle_key_event(&mut self, key: &KeyEvent) -> bool {
match key.code { 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 true
} }
_ => self.content.handle_key_event(key), _ => self.content.handle_key_event(key),

View File

@ -11,18 +11,26 @@ use ratatui::{
widgets::{Block, Borders, List}, widgets::{Block, Borders, List},
Frame, Frame,
}; };
pub enum FloatingTextMode {
Preview,
Description,
}
pub struct FloatingText { pub struct FloatingText {
text: Vec<String>, text: Vec<String>,
mode: FloatingTextMode,
scroll: usize, scroll: usize,
} }
impl FloatingText { impl FloatingText {
pub fn new(text: Vec<String>) -> Self { pub fn new(text: Vec<String>, mode: FloatingTextMode) -> Self {
Self { text, scroll: 0 } 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 { let lines = match command {
Command::Raw(cmd) => { Command::Raw(cmd) => {
// Reconstruct the line breaks and file formatting after the // 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 // If command is a folder, we don't display a preview
Command::None => return None, Command::None => return None,
}; };
Some(Self::new(lines)) Some(Self::new(lines, mode))
} }
fn scroll_down(&mut self) { fn scroll_down(&mut self) {
@ -57,8 +65,16 @@ impl FloatingText {
impl FloatContent for FloatingText { impl FloatContent for FloatingText {
fn draw(&mut self, frame: &mut Frame, area: Rect) { fn draw(&mut self, frame: &mut Frame, area: Rect) {
// Define the Block with a border and background color // 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() let block = Block::default()
.borders(Borders::ALL) .borders(Borders::ALL)
.title(block_title)
.title_alignment(ratatui::layout::Alignment::Center)
.title_style(Style::default().reversed())
.style(Style::default()); .style(Style::default());
// Draw the Block first // Draw the Block first
@ -68,7 +84,7 @@ impl FloatContent for FloatingText {
let inner_area = block.inner(area); let inner_area = block.inner(area);
// Create the list of lines to be displayed // Create the list of lines to be displayed
let lines: Vec<Line> = self let mut lines: Vec<Line> = self
.text .text
.iter() .iter()
.skip(self.scroll) .skip(self.scroll)
@ -86,6 +102,10 @@ impl FloatContent for FloatingText {
.map(Line::from) .map(Line::from)
.collect(); .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 // Create list widget
let list = List::new(lines) let list = List::new(lines)
.block(Block::default()) .block(Block::default())

View File

@ -131,6 +131,7 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) {
hints.push(get_list_item_shortcut(state)); hints.push(get_list_item_shortcut(state));
if state.selected_item_is_cmd() { if state.selected_item_is_cmd() {
hints.push(Shortcut::new(vec!["p"], "Enable preview")); 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")); hints.push(Shortcut::new(vec!["Tab"], "Focus tab list"));

View File

@ -1,7 +1,7 @@
use crate::{ use crate::{
filter::{Filter, SearchAction}, filter::{Filter, SearchAction},
float::{Float, FloatContent}, float::{Float, FloatContent},
floating_text::FloatingText, floating_text::{FloatingText, FloatingTextMode},
hint::{draw_shortcuts, SHORTCUT_LINES}, hint::{draw_shortcuts, SHORTCUT_LINES},
running_command::RunningCommand, running_command::RunningCommand,
theme::Theme, theme::Theme,
@ -294,6 +294,7 @@ impl AppState {
KeyCode::Char('j') | KeyCode::Down => self.selection.select_next(), KeyCode::Char('j') | KeyCode::Down => self.selection.select_next(),
KeyCode::Char('k') | KeyCode::Up => self.selection.select_previous(), KeyCode::Char('k') | KeyCode::Up => self.selection.select_previous(),
KeyCode::Char('p') => self.enable_preview(), KeyCode::Char('p') => self.enable_preview(),
KeyCode::Char('d') => self.enable_description(),
KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => self.handle_enter(), KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => self.handle_enter(),
KeyCode::Char('h') | KeyCode::Left => { KeyCode::Char('h') | KeyCode::Left => {
if self.at_root() { if self.at_root() {
@ -351,6 +352,23 @@ impl AppState {
} }
None 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) { pub fn go_to_selected_dir(&mut self) {
let mut selected_index = self.selection.selected().unwrap_or(0); let mut selected_index = self.selection.selected().unwrap_or(0);
@ -413,11 +431,23 @@ impl AppState {
} }
fn enable_preview(&mut self) { fn enable_preview(&mut self) {
if let Some(command) = self.get_selected_command() { 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); 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) { fn handle_enter(&mut self) {
if let Some(cmd) = self.get_selected_command() { if let Some(cmd) = self.get_selected_command() {
let command = RunningCommand::new(cmd); let command = RunningCommand::new(cmd);