mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-22 21:24:49 +02:00
refactor: change name of some stuff, add some comments (#992)
* some quick refactoring first * add todo for bug report template
This commit is contained in:
parent
7f7a328977
commit
4870ff365a
2
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
2
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@ -88,6 +88,8 @@ body:
|
|||||||
**Note: if you installed from `bottom` from cargo, please ensure that you installed the right crate (https://crates.io/crates/bottom).**
|
**Note: if you installed from `bottom` from cargo, please ensure that you installed the right crate (https://crates.io/crates/bottom).**
|
||||||
placeholder: Installed bottom through the Arch official repos.
|
placeholder: Installed bottom through the Arch official repos.
|
||||||
|
|
||||||
|
# TODO: After some point also add in a `btm check` invocation
|
||||||
|
|
||||||
- type: textarea
|
- type: textarea
|
||||||
id: reproduce
|
id: reproduce
|
||||||
validations:
|
validations:
|
||||||
|
@ -41,7 +41,7 @@ doctest = true
|
|||||||
doc = true
|
doc = true
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
# debug = true
|
# debug = true # Might be nice to have a custom profile for flamegraphs.
|
||||||
# strip = false
|
# strip = false
|
||||||
debug = 0
|
debug = 0
|
||||||
strip = "symbols"
|
strip = "symbols"
|
||||||
|
10
src/app.rs
10
src/app.rs
@ -12,7 +12,7 @@ pub use states::*;
|
|||||||
use typed_builder::*;
|
use typed_builder::*;
|
||||||
use unicode_segmentation::{GraphemeCursor, UnicodeSegmentation};
|
use unicode_segmentation::{GraphemeCursor, UnicodeSegmentation};
|
||||||
|
|
||||||
use crate::widgets::{ProcWidget, ProcWidgetMode};
|
use crate::widgets::{ProcWidgetMode, ProcWidgetState};
|
||||||
use crate::{
|
use crate::{
|
||||||
constants,
|
constants,
|
||||||
data_conversion::ConvertedData,
|
data_conversion::ConvertedData,
|
||||||
@ -1190,7 +1190,7 @@ impl App {
|
|||||||
.proc_state
|
.proc_state
|
||||||
.get_mut_widget_state(self.current_widget.widget_id)
|
.get_mut_widget_state(self.current_widget.widget_id)
|
||||||
{
|
{
|
||||||
proc_widget_state.select_column(ProcWidget::CPU);
|
proc_widget_state.select_column(ProcWidgetState::CPU);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1200,7 +1200,7 @@ impl App {
|
|||||||
.proc_state
|
.proc_state
|
||||||
.get_mut_widget_state(self.current_widget.widget_id)
|
.get_mut_widget_state(self.current_widget.widget_id)
|
||||||
{
|
{
|
||||||
proc_widget_state.select_column(ProcWidget::MEM);
|
proc_widget_state.select_column(ProcWidgetState::MEM);
|
||||||
}
|
}
|
||||||
} else if let Some(disk) = self
|
} else if let Some(disk) = self
|
||||||
.disk_state
|
.disk_state
|
||||||
@ -1215,7 +1215,7 @@ impl App {
|
|||||||
.proc_state
|
.proc_state
|
||||||
.get_mut_widget_state(self.current_widget.widget_id)
|
.get_mut_widget_state(self.current_widget.widget_id)
|
||||||
{
|
{
|
||||||
proc_widget_state.select_column(ProcWidget::PID_OR_COUNT);
|
proc_widget_state.select_column(ProcWidgetState::PID_OR_COUNT);
|
||||||
}
|
}
|
||||||
} else if let Some(disk) = self
|
} else if let Some(disk) = self
|
||||||
.disk_state
|
.disk_state
|
||||||
@ -1240,7 +1240,7 @@ impl App {
|
|||||||
.proc_state
|
.proc_state
|
||||||
.get_mut_widget_state(self.current_widget.widget_id)
|
.get_mut_widget_state(self.current_widget.widget_id)
|
||||||
{
|
{
|
||||||
proc_widget_state.select_column(ProcWidget::PROC_NAME_OR_CMD);
|
proc_widget_state.select_column(ProcWidgetState::PROC_NAME_OR_CMD);
|
||||||
}
|
}
|
||||||
} else if let Some(disk) = self
|
} else if let Some(disk) = self
|
||||||
.disk_state
|
.disk_state
|
||||||
|
@ -9,7 +9,7 @@ use crate::{
|
|||||||
utils::gen_util::str_width,
|
utils::gen_util::str_width,
|
||||||
widgets::{
|
widgets::{
|
||||||
BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState,
|
BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState,
|
||||||
ProcWidget, TempWidgetState,
|
ProcWidgetState, TempWidgetState,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -251,19 +251,19 @@ impl AppSearchState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct ProcState {
|
pub struct ProcState {
|
||||||
pub widget_states: HashMap<u64, ProcWidget>,
|
pub widget_states: HashMap<u64, ProcWidgetState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProcState {
|
impl ProcState {
|
||||||
pub fn init(widget_states: HashMap<u64, ProcWidget>) -> Self {
|
pub fn init(widget_states: HashMap<u64, ProcWidgetState>) -> Self {
|
||||||
ProcState { widget_states }
|
ProcState { widget_states }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut ProcWidget> {
|
pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut ProcWidgetState> {
|
||||||
self.widget_states.get_mut(&widget_id)
|
self.widget_states.get_mut(&widget_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_widget_state(&self, widget_id: u64) -> Option<&ProcWidget> {
|
pub fn get_widget_state(&self, widget_id: u64) -> Option<&ProcWidgetState> {
|
||||||
self.widget_states.get(&widget_id)
|
self.widget_states.get(&widget_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,11 +113,6 @@ pub fn handle_key_event_or_break(
|
|||||||
) -> bool {
|
) -> bool {
|
||||||
// debug!("KeyEvent: {:?}", event);
|
// debug!("KeyEvent: {:?}", event);
|
||||||
|
|
||||||
// TODO: [PASTE] Note that this does NOT support some emojis like flags. This is due to us
|
|
||||||
// catching PER CHARACTER right now WITH A forced throttle! This means multi-char will not work.
|
|
||||||
// We can solve this (when we do paste probably) while keeping the throttle (mainly meant for movement)
|
|
||||||
// by throttling after *bulk+singular* actions, not just singular ones.
|
|
||||||
|
|
||||||
if event.modifiers.is_empty() {
|
if event.modifiers.is_empty() {
|
||||||
// Required catch for searching - otherwise you couldn't search with q.
|
// Required catch for searching - otherwise you couldn't search with q.
|
||||||
if event.code == KeyCode::Char('q') && !app.is_in_search_widget() {
|
if event.code == KeyCode::Char('q') && !app.is_in_search_widget() {
|
||||||
|
@ -24,7 +24,7 @@ use crate::{
|
|||||||
utils::error::{self, BottomError},
|
utils::error::{self, BottomError},
|
||||||
widgets::{
|
widgets::{
|
||||||
BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState,
|
BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState,
|
||||||
ProcWidget, ProcWidgetMode, TempWidgetState,
|
ProcWidgetMode, ProcWidgetState, TempWidgetState,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ pub fn build_app(
|
|||||||
let mut cpu_state_map: HashMap<u64, CpuWidgetState> = HashMap::new();
|
let mut cpu_state_map: HashMap<u64, CpuWidgetState> = HashMap::new();
|
||||||
let mut mem_state_map: HashMap<u64, MemWidgetState> = HashMap::new();
|
let mut mem_state_map: HashMap<u64, MemWidgetState> = HashMap::new();
|
||||||
let mut net_state_map: HashMap<u64, NetWidgetState> = HashMap::new();
|
let mut net_state_map: HashMap<u64, NetWidgetState> = HashMap::new();
|
||||||
let mut proc_state_map: HashMap<u64, ProcWidget> = HashMap::new();
|
let mut proc_state_map: HashMap<u64, ProcWidgetState> = HashMap::new();
|
||||||
let mut temp_state_map: HashMap<u64, TempWidgetState> = HashMap::new();
|
let mut temp_state_map: HashMap<u64, TempWidgetState> = HashMap::new();
|
||||||
let mut disk_state_map: HashMap<u64, DiskTableWidget> = HashMap::new();
|
let mut disk_state_map: HashMap<u64, DiskTableWidget> = HashMap::new();
|
||||||
let mut battery_state_map: HashMap<u64, BatteryWidgetState> = HashMap::new();
|
let mut battery_state_map: HashMap<u64, BatteryWidgetState> = HashMap::new();
|
||||||
@ -326,7 +326,7 @@ pub fn build_app(
|
|||||||
|
|
||||||
proc_state_map.insert(
|
proc_state_map.insert(
|
||||||
widget.widget_id,
|
widget.widget_id,
|
||||||
ProcWidget::new(
|
ProcWidgetState::new(
|
||||||
&app_config_fields,
|
&app_config_fields,
|
||||||
mode,
|
mode,
|
||||||
is_case_sensitive,
|
is_case_sensitive,
|
||||||
|
@ -72,7 +72,7 @@ type ProcessTable = SortDataTable<ProcWidgetData, ProcColumn>;
|
|||||||
type SortTable = DataTable<Cow<'static, str>, SortTableColumn>;
|
type SortTable = DataTable<Cow<'static, str>, SortTableColumn>;
|
||||||
type StringPidMap = FxHashMap<String, Vec<Pid>>;
|
type StringPidMap = FxHashMap<String, Vec<Pid>>;
|
||||||
|
|
||||||
pub struct ProcWidget {
|
pub struct ProcWidgetState {
|
||||||
pub mode: ProcWidgetMode,
|
pub mode: ProcWidgetMode,
|
||||||
|
|
||||||
/// The state of the search box.
|
/// The state of the search box.
|
||||||
@ -92,7 +92,7 @@ pub struct ProcWidget {
|
|||||||
pub force_update_data: bool,
|
pub force_update_data: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProcWidget {
|
impl ProcWidgetState {
|
||||||
pub const PID_OR_COUNT: usize = 0;
|
pub const PID_OR_COUNT: usize = 0;
|
||||||
pub const PROC_NAME_OR_CMD: usize = 1;
|
pub const PROC_NAME_OR_CMD: usize = 1;
|
||||||
pub const CPU: usize = 2;
|
pub const CPU: usize = 2;
|
||||||
@ -222,7 +222,7 @@ impl ProcWidget {
|
|||||||
|
|
||||||
let id_pid_map = FxHashMap::default();
|
let id_pid_map = FxHashMap::default();
|
||||||
|
|
||||||
let mut table = ProcWidget {
|
let mut table = ProcWidgetState {
|
||||||
proc_search: process_search_state,
|
proc_search: process_search_state,
|
||||||
table,
|
table,
|
||||||
sort_table,
|
sort_table,
|
||||||
@ -240,7 +240,7 @@ impl ProcWidget {
|
|||||||
pub fn is_using_command(&self) -> bool {
|
pub fn is_using_command(&self) -> bool {
|
||||||
self.table
|
self.table
|
||||||
.columns
|
.columns
|
||||||
.get(ProcWidget::PROC_NAME_OR_CMD)
|
.get(ProcWidgetState::PROC_NAME_OR_CMD)
|
||||||
.map(|col| matches!(col.inner(), ProcColumn::Command))
|
.map(|col| matches!(col.inner(), ProcColumn::Command))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
@ -248,7 +248,7 @@ impl ProcWidget {
|
|||||||
pub fn is_mem_percent(&self) -> bool {
|
pub fn is_mem_percent(&self) -> bool {
|
||||||
self.table
|
self.table
|
||||||
.columns
|
.columns
|
||||||
.get(ProcWidget::MEM)
|
.get(ProcWidgetState::MEM)
|
||||||
.map(|col| matches!(col.inner(), ProcColumn::MemoryPercent))
|
.map(|col| matches!(col.inner(), ProcColumn::MemoryPercent))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user