Skip to content

Commit

Permalink
add inline comments styles inside the functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad-Owais-Warsi committed Oct 9, 2024
1 parent e2a7c52 commit a15aff6
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 76 deletions.
8 changes: 4 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl App {
area: Rect,
kernel_modules: &mut KernelModules<'_>,
) {
/// Filter the module list depending on the input query.
// Filter the module list depending on the input query.
let mut kernel_module_list = kernel_modules.default_list.clone();
if (self.input_mode == InputMode::None
|| self.input_mode == InputMode::Search)
Expand All @@ -391,7 +391,7 @@ impl App {
.contains(&self.input_query.to_lowercase())
});
}
/// Append '...' if dependent modules exceed the block width.
// Append '...' if dependent modules exceed the block width.
let dependent_width = (area.width / 2).saturating_sub(7) as usize;
for module in &mut kernel_module_list {
if module[2].len() > dependent_width {
Expand All @@ -400,13 +400,13 @@ impl App {
}
}
kernel_modules.list = kernel_module_list;
/// Set the scroll offset for modules.
// Set the scroll offset for modules.
let modules_scroll_offset = area
.height
.checked_sub(5)
.and_then(|height| kernel_modules.index.checked_sub(height as usize))
.unwrap_or(0);
/// Set selected state of the modules and render the table widget.
// Set selected state of the modules and render the table widget.
frame.render_widget(
Table::new(
kernel_modules
Expand Down
12 changes: 6 additions & 6 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ impl Events {

/// Create a new events instance.
pub fn new(refresh_rate: u64, kernel_logs: &KernelLogs) -> Self {
/// Convert refresh rate to Duration from milliseconds.
// Convert refresh rate to Duration from milliseconds.
let refresh_rate = Duration::from_millis(refresh_rate);
/// Create a new asynchronous channel.
// Create a new asynchronous channel.
let (tx, rx) = mpsc::channel();
/// Handle inputs using stdin stream and sender of the channel.
// Handle inputs using stdin stream and sender of the channel.
let input_handler = {
let tx = tx.clone();
thread::spawn(move || {
Expand All @@ -41,7 +41,7 @@ impl Events {
}
})
};
/// Handle kernel logs using 'dmesg' output.
// Handle kernel logs using 'dmesg' output.
let kernel_handler = {
let tx = tx.clone();
let mut kernel_logs = kernel_logs.clone();
Expand All @@ -53,15 +53,15 @@ impl Events {
thread::sleep(refresh_rate * 10);
})
};
/// Create a loop for handling events.
// Create a loop for handling events.
let tick_handler = {
let tx = tx.clone();
thread::spawn(move || loop {
tx.send(Event::Tick).unwrap_or_default();
thread::sleep(refresh_rate);
})
};
/// Return events.
// Return events.
Self {
tx,
rx,
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Command {
mut title: String,
symbol: Symbol,
) -> Self {
/// Parse the command title if '!' is given.
// Parse the command title if '!' is given.
if title.contains('!') {
title = (*title
.split('!')
Expand Down
14 changes: 7 additions & 7 deletions src/kernel/lkm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl KernelModules<'_> {
/// Parse kernel modules from '/proc/modules'.
pub fn refresh(&mut self) -> Result<(), Box<dyn Error>> {
let mut module_list: Vec<Vec<String>> = Vec::new();
/// Set the command for reading kernel modules and execute it.
// Set the command for reading kernel modules and execute it.
let mut module_read_cmd = String::from("cat /proc/modules");
match self.args.sort {
SortType::Size => module_read_cmd += " | sort -n -r -t ' ' -k2",
Expand All @@ -107,7 +107,7 @@ impl KernelModules<'_> {
}
let modules_content = util::exec_cmd("sh", &["-c", &module_read_cmd])?;

/// Parse content for module name, size and related information.
// Parse content for module name, size and related information.
for line in modules_content.lines() {
let columns: Vec<&str> = line.split_whitespace().collect();
let mut module_name = format!(" {}", columns[0]);
Expand All @@ -122,7 +122,7 @@ impl KernelModules<'_> {
ByteSize::b(columns[1].to_string().parse().unwrap_or(0)).to_string();
module_list.push(vec![module_name, module_size, used_modules]);
}
/// Reverse the kernel modules if the argument is provided.
// Reverse the kernel modules if the argument is provided.
if self.args.reverse {
module_list.reverse();
}
Expand Down Expand Up @@ -277,22 +277,22 @@ impl KernelModules<'_> {
if self.list.is_empty() {
self.index = 0;
} else {
/// Scroll module list.
// Scroll module list.
match direction {
ScrollDirection::Up => self.previous_module(),
ScrollDirection::Down => self.next_module(),
ScrollDirection::Top => self.index = 0,
ScrollDirection::Bottom => self.index = self.list.len() - 1,
_ => {}
}
/// Set current module name.
// Set current module name.
self.current_name = self.list[self.index][0]
.split_whitespace()
.next()
.unwrap_or("?")
.trim()
.to_string();
/// Execute 'modinfo' and add style to its output.
// Execute 'modinfo' and add style to its output.
self.current_info.stylize_data(
Box::leak(
util::exec_cmd("modinfo", &[&self.current_name])
Expand All @@ -305,7 +305,7 @@ impl KernelModules<'_> {
":",
self.style.clone(),
);
/// Clear the current command.
// Clear the current command.
if !self.command.is_none() {
self.command = ModuleCommand::None;
}
Expand Down
Loading

0 comments on commit a15aff6

Please sign in to comment.