feature: add readonly mode (#1861)

* init

* Fixed code smells

* Updated documentation as per feedback
This commit is contained in:
Adarsh Das
2025-11-17 16:33:46 +05:30
committed by GitHub
parent daafd2fa36
commit 45b2522929
8 changed files with 26 additions and 0 deletions
@@ -33,6 +33,7 @@ see information on these options by running `btm -h`, or run `btm --help` to dis
| `-S, --case_sensitive` | Enables case sensitivity by default when searching. |
| `-u, --current_usage` | Calculates process CPU usage as a percentage of current usage rather than total usage. |
| `--disable_advanced_kill` | Hides additional stopping options on Unix-like systems. |
| `--read_only` | Prevents performing any actions that affect the system (e.g. stopping processes). |
| `--get_threads` | Also gather process thread information. |
| `-g, --group_processes` | Groups processes with the same name by default. No effect if `--tree` is set. |
| `--hide_k_threads` | Hide kernel threads by default. |
@@ -41,6 +41,7 @@ each time:
| `show_table_scroll_position` | Boolean | Shows the scroll position tracker in table widgets. |
| `process_command` | Boolean | Show processes as their commands by default. |
| `disable_advanced_kill` | Boolean | Disable being able to send signals to processes on supported Unix-like systems. Only available on Linux, macOS, and FreeBSD. |
| `read_only` | Boolean | Prevents performing any actions that affect the system (e.g. stopping processes). |
| `network_use_binary_prefix` | Boolean | Displays the network widget with binary prefixes. |
| `network_use_bytes` | Boolean | Displays the network widget using bytes. |
| `network_use_log` | Boolean | Displays the network widget with a log scale. |
+3
View File
@@ -106,6 +106,9 @@
# Hides advanced options to stop a process on Unix-like systems.
#disable_advanced_kill = false
# Prevents performing any actions that affect the system (e.g. stopping processes).
#read_only = false
# Hides the kernel threads
#hide_k_threads = false
+5
View File
@@ -57,6 +57,7 @@ pub struct AppConfigFields {
pub show_table_scroll_position: bool,
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
pub is_advanced_kill: bool,
pub is_read_only: bool,
#[cfg(target_os = "linux")]
pub hide_k_threads: bool,
#[cfg(feature = "zfs")]
@@ -991,6 +992,10 @@ impl App {
///
/// TODO: This ideally gets abstracted out into a separate widget.
pub(crate) fn kill_current_process(&mut self) {
if self.app_config_fields.is_read_only {
return;
}
if let Some(pws) = self
.states
.proc_state
+3
View File
@@ -352,6 +352,9 @@ pub(crate) const CONFIG_TEXT: &str = r#"# This is a default config file for bott
# Hides advanced options to stop a process on Unix-like systems.
#disable_advanced_kill = false
# Prevents performing any actions that affect the system (e.g. stopping processes).
#read_only = false
# Hides the kernel threads
#hide_k_threads = false
+2
View File
@@ -242,6 +242,7 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL
let is_default_command = is_flag_enabled!(process_command, args.process, config);
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
let is_advanced_kill = !(is_flag_enabled!(disable_advanced_kill, args.process, config));
let is_read_only = is_flag_enabled!(read_only, args.process, config);
#[cfg(target_os = "linux")]
let hide_k_threads = is_flag_enabled!(hide_k_threads, args.process, config);
@@ -321,6 +322,7 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL
),
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
is_advanced_kill,
is_read_only,
#[cfg(target_os = "linux")]
hide_k_threads,
memory_legend_position,
+10
View File
@@ -324,6 +324,16 @@ pub struct ProcessArgs {
)]
pub disable_advanced_kill: bool,
#[arg(
long,
action = ArgAction::SetTrue,
help = "Prevents performing any actions that affect the system.",
long_help = "Prevents performing any actions that affect the system. Disables operations such as stopping or sending signals \
to processes.",
alias = "read-only"
)]
pub read_only: bool,
#[cfg(target_os = "linux")]
#[arg(
long,
+1
View File
@@ -40,6 +40,7 @@ pub(crate) struct GeneralConfig {
pub(crate) process_command: Option<bool>,
// #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
pub(crate) disable_advanced_kill: Option<bool>, // This does nothing on Windows, but we leave it enabled to make the config file consistent across platforms.
pub(crate) read_only: Option<bool>,
// #[cfg(target_os = "linux")]
pub(crate) hide_k_threads: Option<bool>,
// #[cfg(feature = "zfs")]