Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

icons added #111

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

Process Interactive Kill is a command line tool that helps to find and kill process.
It works like pkill command but search is interactive.
![Example pik](docs/pik.png)

This tool is still under development

Expand Down Expand Up @@ -70,6 +71,7 @@ sudo zypper install pik
On **Gentoo**

It is available via `lamdness` overlay

```sh
sudo eselect repository enable lamdness
sudo emaint -r lamdness sync
Expand Down Expand Up @@ -99,9 +101,19 @@ cargo binstall pik

### Application configuration

You may set your preferences in `pik.toml` file located in `~/.config/pik` directory.
You may set your preferences in `config.toml` file located in `~/.config/pik` directory.
All options are optional, if skipped default values will be used.
Example configuration with default settings can be found at [example config](example_config.toml)

You can find default values below

``` toml
# Size of the viewport
screen_size = { height = 20 } # run pik in 20 lines of the terminal
# screen_size = "fullscreen" # run pik in fullscreen

# Icons require nerd fonts v3
use_icons = false
```

### Key maps

Expand Down
Binary file added docs/pik.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions example_config.toml

This file was deleted.

14 changes: 13 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use serde::Deserialize;
pub struct AppConfig {
#[serde(default)]
pub screen_size: ScreenSize,
#[serde(default)]
pub use_icons: bool,
}

#[derive(Debug, Eq, PartialEq, Deserialize, Clone, Copy)]
Expand All @@ -50,20 +52,30 @@ mod tests {
fn should_deserialize_empty_configuration() {
let default_settings = toml::from_str("");
assert_eq!(default_settings, Ok(AppConfig::default()));
// ensure what actual defaults are
assert_eq!(
default_settings,
Ok(AppConfig {
screen_size: ScreenSize::Height(DEFAULT_SCREEN_SIZE),
use_icons: false
})
);
}

#[test]
fn should_allow_to_override_defaults() {
let default_settings: AppConfig = toml::from_str(
r#"
screen_size = "fullscreen"
use_icons = true
"#,
)
.unwrap();
assert_eq!(
default_settings,
AppConfig {
screen_size: ScreenSize::Fullscreen
screen_size: ScreenSize::Fullscreen,
use_icons: true
}
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
pub struct AppSettings {
pub viewport: Viewport,
pub filter_opions: FilterOptions,
pub use_icons: bool,
}

impl AppSettings {
Expand All @@ -20,6 +21,7 @@ impl AppSettings {
ignore_threads: !cli_args.include_threads_processes,
include_all_processes: cli_args.include_other_users_processes,
},
use_icons: config.use_icons,
}
}
}
Expand Down Expand Up @@ -96,6 +98,7 @@ mod tests {
settings,
AppSettings {
viewport: Viewport::Inline(25),
use_icons: false,
filter_opions: FilterOptions {
ignore_threads: false,
include_all_processes: true
Expand All @@ -108,6 +111,7 @@ mod tests {
fn should_prefer_cli_args_screen_size() {
let config = AppConfig {
screen_size: ScreenSize::Height(40),
..Default::default()
};
let cli_args = CliArgs {
screen_size: Some(ScreenSizeOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl App {
process_manager: ProcessManager::new()?,
search_results: ProcessSearchResults::empty(),
filter_options: app_settings.filter_opions,
tui: Tui::new(search_criteria),
tui: Tui::new(search_criteria, app_settings.use_icons),
};
app.search_for_processess();
Ok(app)
Expand Down
28 changes: 23 additions & 5 deletions src/tui/rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::processes::{MatchedBy, Process, ProcessSearchResults, ResultItem};

use super::highlight::highlight_text;

pub struct Theme {
struct Theme {
row_fg: Color,
selected_style_fg: Color,
normal_row_color: Color,
Expand All @@ -28,7 +28,7 @@ pub struct Theme {
}

impl Theme {
pub fn new() -> Self {
fn new() -> Self {
Self {
row_fg: tailwind::SLATE.c200,
selected_style_fg: tailwind::BLUE.c400,
Expand All @@ -43,6 +43,7 @@ impl Theme {

pub struct Tui {
theme: Theme,
use_icons: bool,
process_table: TableState,
process_table_scroll_state: ScrollbarState,
process_table_number_of_items: usize,
Expand All @@ -58,7 +59,18 @@ const MAX_PATH_LEN: usize = 38;
const MAX_ARGS_LEN: usize = 35;
const MAX_PORTS_LEN: usize = 20;

const TABLE_HEADERS: [&str; 8] = [
const TABLE_HEADERS_ICONS: [&str; 8] = [
"USER 󰋦",
"PID ",
"PARENT 󱖁",
"TIME ",
"CMD 󱃸",
"PATH ",
"ARGS 󱃼",
"PORTS ",
];

const TABLE_HEADERS_PLAIN: [&str; 8] = [
"USER", "PID", "PARENT", "RUN TIME", "CMD", "PATH", "ARGS", "PORTS",
];

Expand All @@ -74,13 +86,14 @@ const TABLE_WIDTHS: [Constraint; 8] = [
];

impl Tui {
pub fn new(search_text: String) -> Self {
pub fn new(search_text: String, use_icons: bool) -> Self {
let mut search_area = TextArea::from(search_text.lines());
search_area.move_cursor(tui_textarea::CursorMove::End);
Self {
process_table: TableState::default(),
process_table_scroll_state: ScrollbarState::new(0),
theme: Theme::new(),
use_icons,
process_table_number_of_items: 0,
process_details_scroll_offset: 0,
process_details_number_of_lines: 0,
Expand Down Expand Up @@ -247,8 +260,13 @@ impl Tui {
])
.style(Style::new().fg(self.theme.row_fg).bg(color))
});
let headers = if self.use_icons {
TABLE_HEADERS_ICONS
} else {
TABLE_HEADERS_PLAIN
};
let table = Table::new(rows, TABLE_WIDTHS)
.header(Row::new(TABLE_HEADERS))
.header(Row::new(headers))
.block(
Block::default()
.title_top(
Expand Down
Loading