Skip to content

Commit

Permalink
doc: Use the conventional comment syntax (#174)
Browse files Browse the repository at this point in the history
* change the comment syntax from /* */ to ///

* remove C-type @return and @param lines

* remove C-type @return and @param lines

* remove unecessary lines

* add inline comments styles inside the functions

* format
  • Loading branch information
Muhammad-Owais-Warsi authored Oct 9, 2024
1 parent b8f12d9 commit 90b30cb
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 421 deletions.
144 changes: 32 additions & 112 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use std::sync::mpsc::Sender;
use termion::event::Key;
use unicode_width::UnicodeWidthStr;

/* Table header of the module table */
/// Table header of the module table
pub const TABLE_HEADER: &[&str] = &[" Module", "Size", "Used by"];

/* Available options in the module management menu */
/// Available options in the module management menu
const OPTIONS: &[(&str, &str)] = &[
("unload", "Unload the module"),
("reload", "Reload the module"),
Expand All @@ -36,7 +36,7 @@ const OPTIONS: &[(&str, &str)] = &[
("clear", "Clear the ring buffer"),
];

/* Supported directions of scrolling */
/// Supported directions of scrolling
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ScrollDirection {
Up,
Expand All @@ -48,11 +48,7 @@ pub enum ScrollDirection {
}

impl ScrollDirection {
/**
* Return iterator of the available scroll directions.
*
* @return Iter
*/
/// Return iterator of the available scroll directions.
#[allow(dead_code)]
pub fn iter() -> Iter<'static, ScrollDirection> {
[
Expand All @@ -67,8 +63,7 @@ impl ScrollDirection {
}
}

/* Main blocks of the terminal */

/// Main blocks of the terminal
#[derive(Clone, Copy, Debug, PartialEq, Eq, Sequence)]
pub enum Block {
UserInput,
Expand All @@ -77,14 +72,14 @@ pub enum Block {
Activities,
}

/* Sizes of the terminal blocks */
/// Sizes of the terminal blocks
pub struct BlockSize {
pub input: u16,
pub info: u16,
pub activities: u16,
}

/* Default initialization values for BlockSize */
/// Default initialization values for BlockSize
impl Default for BlockSize {
fn default() -> Self {
Self {
Expand All @@ -95,7 +90,7 @@ impl Default for BlockSize {
}
}

/* User input mode */
/// User input mode
#[derive(Clone, Copy, Debug, PartialEq, Eq, Sequence)]
pub enum InputMode {
None,
Expand All @@ -104,17 +99,13 @@ pub enum InputMode {
}

impl InputMode {
/**
* Check if input mode is set.
*
* @return bool
*/
/// Check if input mode is set.
pub fn is_none(self) -> bool {
self == Self::None
}
}

/* Implementation of Display for using InputMode members as string */
/// Implementation of Display for using InputMode members as string
impl Display for InputMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut input_mode = *self;
Expand All @@ -128,7 +119,7 @@ impl Display for InputMode {
}
}

/* Application settings and related methods */
/// Application settings and related methods
pub struct App {
pub selected_block: Block,
pub default_block: Block,
Expand All @@ -143,13 +134,7 @@ pub struct App {
}

impl App {
/**
* Create a new app instance.
*
* @param Block
* @param Style
* @return App
*/
/// Create a new app instance.
pub fn new(block: Block, style: Style) -> Self {
Self {
selected_block: block,
Expand Down Expand Up @@ -178,7 +163,7 @@ impl App {
}
}

/* Reset app properties to default. */
/// Reset app properties to default.
pub fn refresh(&mut self) {
self.selected_block = self.default_block;
self.block_size = BlockSize::default();
Expand All @@ -189,12 +174,7 @@ impl App {
self.show_options = false;
}

/**
* Get style depending on the selected state of the block.
*
* @param block
* @return TuiStyle
*/
/// Get style depending on the selected state of the block.
pub fn block_style(&self, block: Block) -> TuiStyle {
if self.show_options {
self.style.colored
Expand All @@ -205,11 +185,7 @@ impl App {
}
}

/**
* Get the size of the selected block.
*
* @return u16
*/
/// Get the size of the selected block.
pub fn block_size(&mut self) -> &mut u16 {
match self.selected_block {
Block::ModuleInfo => &mut self.block_size.info,
Expand All @@ -218,11 +194,7 @@ impl App {
}
}

/**
* Get clipboard contents as String.
*
* @return contents
*/
/// Get clipboard contents as String.
pub fn get_clipboard_contents(&mut self) -> String {
if let Some(clipboard) = self.clipboard.as_mut() {
if let Ok(contents) = clipboard.get_contents() {
Expand All @@ -232,11 +204,7 @@ impl App {
String::new()
}

/**
* Set clipboard contents.
*
* @param contents
*/
/// Set clipboard contents.
pub fn set_clipboard_contents(&mut self, contents: &str) {
if let Some(clipboard) = self.clipboard.as_mut() {
if let Err(e) = clipboard.set_contents(contents.to_string()) {
Expand All @@ -245,11 +213,7 @@ impl App {
}
}

/**
* Show help message on the information block.
*
* @param kernel_modules
*/
/// Show help message on the information block.
pub fn show_help_message(&mut self, kernel_modules: &mut KernelModules<'_>) {
let key_bindings: Vec<(&str, &str)> = util::KEY_BINDINGS.to_vec();
let mut help_text = Vec::new();
Expand All @@ -275,11 +239,7 @@ impl App {
.set(Text::from(help_text), help_text_raw.join("\n"));
}

/**
* Show dependent modules on the information block.
*
* @param kernel_modules
*/
/// Show dependent modules on the information block.
#[allow(clippy::nonminimal_bool)]
pub fn show_dependent_modules(
&mut self,
Expand Down Expand Up @@ -317,13 +277,7 @@ impl App {
}
}

/**
* Draw a block according to the index.
*
* @param frame
* @param area
* @param kernel
*/
/// Draw a block according to the index.
pub fn draw_dynamic_block(
&mut self,
frame: &mut Frame,
Expand All @@ -342,13 +296,7 @@ impl App {
}
}

/**
* Draw a paragraph widget for using as user input.
*
* @param frame
* @param area
* @param tx
*/
/// Draw a paragraph widget for using as user input.
pub fn draw_user_input(
&self,
frame: &mut Frame,
Expand Down Expand Up @@ -387,13 +335,7 @@ impl App {
);
}

/**
* Draw a paragraph widget for showing the kernel information.
*
* @param frame
* @param area
* @param info
*/
/// Draw a paragraph widget for showing the kernel information.
pub fn draw_kernel_info(&self, frame: &mut Frame, area: Rect, info: &[String]) {
frame.render_widget(
Paragraph::new(Span::raw(&info[1]))
Expand All @@ -417,20 +359,14 @@ impl App {
);
}

/**
* Configure and draw kernel modules table.
*
* @param frame
* @param area
* @param kernel_modules
*/
/// Configure and draw kernel modules table.
pub fn draw_kernel_modules(
&mut self,
frame: &mut Frame,
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 @@ -442,7 +378,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 @@ -451,13 +387,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 Expand Up @@ -504,7 +440,8 @@ impl App {
self.style.unicode.get(Symbol::LeftBracket),
if !kernel_modules.list.is_empty() {
((kernel_modules.index + 1) as f64
/ kernel_modules.list.len() as f64 * 100.0) as u64
/ kernel_modules.list.len() as f64
* 100.0) as u64
} else {
0
},
Expand All @@ -520,12 +457,7 @@ impl App {
}
}

/**
* Draws the options menu as a popup.
*
* @param frame
* @param area
*/
/// Draws the options menu as a popup.
pub fn draw_options_menu(
&mut self,
frame: &mut Frame,
Expand Down Expand Up @@ -603,13 +535,7 @@ impl App {
);
}

/**
* Draw a paragraph widget for showing module information.
*
* @param frame
* @param area
* @param kernel_modules
*/
/// Draw a paragraph widget for showing module information.
pub fn draw_module_info(
&self,
frame: &mut Frame,
Expand Down Expand Up @@ -651,13 +577,7 @@ impl App {
);
}

/**
* Draw a paragraph widget for showing kernel activities.
*
* @param frame
* @param area
* @param kernel_logs
*/
/// Draw a paragraph widget for showing kernel activities.
pub fn draw_kernel_activities(
&self,
frame: &mut Frame,
Expand Down
8 changes: 2 additions & 6 deletions src/args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::{Arg, ArgAction, Command as App};

/* ASCII format of the project logo */
/// ASCII format of the project logo
const ASCII_LOGO: &str = "
`` ```````````` ```` ``````````` ```````````
:NNs `hNNNNNNNNNNNNh` sNNNy yNNNNNNNNNN+ dNNNNNNNNNN:
Expand All @@ -10,11 +10,7 @@ const ASCII_LOGO: &str = "
:mmm/ dmmh +mmm- `mmmmmmmmmmmmmmmmmmmmmmmmmd /mmm:
``` ``` ``` `````````````````````````` ```";

/**
* Parse command line arguments using clap.
*
* @return App
*/
/// Parse command line arguments using clap.
pub fn get_args() -> App {
App::new(env!("CARGO_PKG_NAME"))
.version(env!("CARGO_PKG_VERSION"))
Expand Down
Loading

0 comments on commit 90b30cb

Please sign in to comment.