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

doc: Use the conventional comment syntax #174

Merged
merged 6 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
194 changes: 84 additions & 110 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,10 @@ pub enum ScrollDirection {
}

impl ScrollDirection {
/**
* Return iterator of the available scroll directions.
*
* @return Iter
*/

/// Return iterator of the available scroll directions.


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also remove these extra newlines?

#[allow(dead_code)]
pub fn iter() -> Iter<'static, ScrollDirection> {
[
Expand All @@ -67,7 +66,7 @@ impl ScrollDirection {
}
}

/* Main blocks of the terminal */
/// Main blocks of the terminal

#[derive(Clone, Copy, Debug, PartialEq, Eq, Sequence)]
pub enum Block {
Expand All @@ -77,14 +76,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 +94,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 +103,16 @@ pub enum InputMode {
}

impl InputMode {
/**
* Check if input mode is set.
*
* @return bool
*/

/// Check if input mode is set.


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary newlines

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pushed , please check , hope I have not missed anything now 😅

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 +126,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 +141,10 @@ 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 +173,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 +184,10 @@ 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 +198,11 @@ 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 +211,10 @@ 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 +224,10 @@ 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 +236,10 @@ 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 +265,10 @@ 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 +306,11 @@ 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 +329,11 @@ 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 +372,11 @@ 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 +400,18 @@ 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 +423,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 +432,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 @@ -520,12 +501,11 @@ 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 +583,10 @@ 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 +628,10 @@ 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
Loading