diff --git a/src/core.rs b/src/core.rs index a0308e2e..8bbc65dc 100644 --- a/src/core.rs +++ b/src/core.rs @@ -5,7 +5,8 @@ pub mod text; pub mod text_editor; pub mod tree; -/// Defines a `Len` trait for obtaining the length of a collection and checking if it is empty. +/// Defines a `Len` trait for obtaining the length of a collection +/// and checking if it is empty. pub trait Len { /// Returns the length of the collection. fn len(&self) -> usize; diff --git a/src/core/checkbox.rs b/src/core/checkbox.rs index 94e3c866..3e6e095c 100644 --- a/src/core/checkbox.rs +++ b/src/core/checkbox.rs @@ -5,8 +5,11 @@ use crate::core::listbox::Listbox; mod render; pub use render::Renderer; -/// A `Checkbox` struct that encapsulates a listbox for item selection and a set of picked (selected) indices. -/// It allows for multiple selections, toggling the selection state of items, and navigating through the items. +/// A `Checkbox` struct that encapsulates a listbox +/// for item selection and a set of picked (selected) indices. +/// It allows for multiple selections, +/// toggling the selection state of items, +/// and navigating through the items. #[derive(Clone)] pub struct Checkbox { listbox: Listbox, @@ -14,8 +17,10 @@ pub struct Checkbox { } impl FromIterator for Checkbox { - /// Creates a `Checkbox` from an iterator of items that implement the `Display` trait. - /// Each item is added to the listbox, and the set of picked indices is initialized as empty. + /// Creates a `Checkbox` from an iterator of items + /// that implement the `Display` trait. + /// Each item is added to the listbox, + /// and the set of picked indices is initialized as empty. fn from_iter>(iter: I) -> Self { Self { listbox: Listbox::from_iter(iter), diff --git a/src/core/checkbox/render.rs b/src/core/checkbox/render.rs index 6b85ed07..e2c078db 100644 --- a/src/core/checkbox/render.rs +++ b/src/core/checkbox/render.rs @@ -12,9 +12,12 @@ use crate::{ use super::Checkbox; -/// Represents a renderer for the `Checkbox` component, capable of visualizing checkboxes in a pane. -/// It supports custom symbols for the cursor and checkmark, styles for active and inactive items, -/// and a configurable number of lines for rendering. It also handles key events for navigation and toggling checkboxes. +/// Represents a renderer for the `Checkbox` component, +/// capable of visualizing checkboxes in a pane. +/// It supports custom symbols for the cursor and checkmark, +/// styles for active and inactive items, +/// and a configurable number of lines for rendering. +/// It also handles key events for navigation and toggling checkboxes. #[derive(Clone)] pub struct Renderer { /// The `Checkbox` component to be rendered. diff --git a/src/core/cursor.rs b/src/core/cursor.rs index 15c788a5..63e7d230 100644 --- a/src/core/cursor.rs +++ b/src/core/cursor.rs @@ -1,8 +1,10 @@ use crate::core::Len; /// A generic cursor structure for navigating and manipulating collections. -/// It maintains a position within the collection and provides methods to move forward, backward, -/// to the head, and to the tail of the collection. It requires the collection to implement the `Len` trait. +/// It maintains a position within the collection +/// and provides methods to move forward, backward, +/// to the head, and to the tail of the collection. +/// It requires the collection to implement the `Len` trait. #[derive(Clone)] pub struct Cursor { contents: C, diff --git a/src/core/listbox.rs b/src/core/listbox.rs index d0371943..9263c8ba 100644 --- a/src/core/listbox.rs +++ b/src/core/listbox.rs @@ -5,15 +5,20 @@ use crate::core::cursor::Cursor; mod render; pub use render::Renderer; -/// A `Listbox` struct that encapsulates a list of strings, allowing for navigation and manipulation -/// through a cursor. It supports basic operations such as moving the cursor forward and backward, -/// retrieving the current item, and initializing from an iterator of displayable items. +/// A `Listbox` struct that encapsulates a list of strings, +/// allowing for navigation and manipulation through a cursor. +/// It supports basic operations +/// such as moving the cursor forward and backward, +/// retrieving the current item, +/// and initializing from an iterator of displayable items. #[derive(Clone)] pub struct Listbox(Cursor>); impl FromIterator for Listbox { - /// Creates a `Listbox` from an iterator of items that implement the `Display` trait. - /// Each item is converted to a `String` and collected into a `Vec`. + /// Creates a `Listbox` from an iterator of items + /// that implement the `Display` trait. + /// Each item is converted to a `String` + /// and collected into a `Vec`. fn from_iter>(iter: I) -> Self { Self(Cursor::new( iter.into_iter().map(|e| format!("{}", e)).collect(), @@ -33,7 +38,8 @@ impl Listbox { } /// Retrieves the item at the current cursor position as a `String`. - /// If the cursor is at a position without an item, returns an empty `String`. + /// If the cursor is at a position without an item, + /// returns an empty `String`. pub fn get(&self) -> String { self.items() .get(self.position()) diff --git a/src/core/listbox/render.rs b/src/core/listbox/render.rs index 5495aeb3..0d69428f 100644 --- a/src/core/listbox/render.rs +++ b/src/core/listbox/render.rs @@ -12,8 +12,10 @@ use crate::{ use super::Listbox; -/// Represents a renderer for the `Listbox` component, capable of visualizing a list of items in a pane. -/// It supports a custom symbol for the selected line, styles for active and inactive items, +/// Represents a renderer for the `Listbox` component, +/// capable of visualizing a list of items in a pane. +/// It supports a custom symbol for the selected line, +/// styles for active and inactive items, /// and a configurable number of lines for rendering. #[derive(Clone)] pub struct Renderer { diff --git a/src/core/text_editor.rs b/src/core/text_editor.rs index 5dbf3114..80c25ea5 100644 --- a/src/core/text_editor.rs +++ b/src/core/text_editor.rs @@ -9,7 +9,8 @@ pub use suggest::Suggest; mod mode; pub use mode::Mode; -/// A text editor that supports basic editing operations such as insert, delete, and overwrite. +/// A text editor that supports basic editing operations +/// such as insert, delete, and overwrite. /// It utilizes a cursor to navigate and manipulate the text. #[derive(Clone)] pub struct TextEditor(Cursor); diff --git a/src/core/text_editor/history.rs b/src/core/text_editor/history.rs index eb3c720c..3d08d017 100644 --- a/src/core/text_editor/history.rs +++ b/src/core/text_editor/history.rs @@ -1,6 +1,8 @@ /// Manages the history of user inputs for a text editor. -/// This structure allows for the storage, retrieval, and navigation through past inputs. -/// It supports adding new entries, checking for the existence of specific entries, +/// This structure allows for the storage, +/// retrieval, and navigation through past inputs. +/// It supports adding new entries, +/// checking for the existence of specific entries, /// and moving through the history in both forward and backward directions. #[derive(Clone)] pub struct History { @@ -24,9 +26,12 @@ impl Default for History { impl History { /// Inserts a new item into the history. /// - /// If the item does not already exist in the buffer, it is inserted just before the last item. - /// This method ensures there is always an empty string at the end of the buffer to represent - /// a new input line. After insertion, the current position is moved to the end of the buffer. + /// If the item does not already exist in the buffer, + /// it is inserted just before the last item. + /// This method ensures there is always an empty string + /// at the end of the buffer to represent + /// a new input line. After insertion, + /// the current position is moved to the end of the buffer. /// /// # Arguments /// @@ -50,7 +55,8 @@ impl History { } } - /// Retrieves the current item from the history based on the current position. + /// Retrieves the current item from the history + /// based on the current position. /// Returns an empty string if the position is out of bounds. pub fn get(&self) -> String { self.buf diff --git a/src/core/text_editor/render.rs b/src/core/text_editor/render.rs index a05b3e2a..4375afc7 100644 --- a/src/core/text_editor/render.rs +++ b/src/core/text_editor/render.rs @@ -12,10 +12,14 @@ use crate::{ use super::{History, Mode, Suggest, TextEditor}; -/// Represents a renderer for the `TextEditor` component, capable of visualizing text input in a pane. -/// It supports a variety of features including history navigation, input suggestions, input masking, -/// customizable prompt strings, and styles for different parts of the input. It also handles different -/// edit modes such as insert and overwrite, and can be configured to render a specific number of lines. +/// Represents a renderer for the `TextEditor` component, +/// capable of visualizing text input in a pane. +/// It supports a variety of features including history navigation, +/// input suggestions, input masking, +/// customizable prompt strings, +/// and styles for different parts of the input. It also handles different +/// edit modes such as insert and overwrite, +/// and can be configured to render a specific number of lines. #[derive(Clone)] pub struct Renderer { /// The `TextEditor` component to be rendered. diff --git a/src/core/tree/node.rs b/src/core/tree/node.rs index 6626643c..2313dc40 100644 --- a/src/core/tree/node.rs +++ b/src/core/tree/node.rs @@ -1,5 +1,6 @@ /// A `Node` struct that represents a single node in a tree structure. -/// It contains data as a `String`, a list of child nodes, and a visibility flag for its children. +/// It contains data as a `String`, +/// a list of child nodes, and a visibility flag for its children. #[derive(Clone, Debug, Default, PartialEq)] pub struct Node { data: String, @@ -7,7 +8,8 @@ pub struct Node { children_visible: bool, } -/// A `NodeWithDepth` struct that represents a node along with its depth information. +/// A `NodeWithDepth` struct that represents a node +/// along with its depth information. /// It is used for flattening a tree structure into a linear representation. #[derive(Clone, Debug, PartialEq)] pub struct NodeWithDepth { diff --git a/src/core/tree/render.rs b/src/core/tree/render.rs index 524392ad..15823a83 100644 --- a/src/core/tree/render.rs +++ b/src/core/tree/render.rs @@ -11,9 +11,12 @@ use crate::{ tree::{NodeWithDepth, Tree}, }; -/// Represents a renderer for a tree structure, capable of visualizing the tree in a pane. -/// It supports custom symbols for folded and unfolded items, styles for active and inactive items, -/// and a configurable number of lines for rendering. It also handles key events for navigation and folding/unfolding. +/// Represents a renderer for a tree structure, +/// capable of visualizing the tree in a pane. +/// It supports custom symbols for folded and unfolded items, +/// styles for active and inactive items, +/// and a configurable number of lines for rendering. +/// It also handles key events for navigation and folding/unfolding. #[derive(Clone)] pub struct Renderer { pub tree: Tree, diff --git a/src/engine.rs b/src/engine.rs index 06b9b784..560ab9b8 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -10,10 +10,13 @@ use crate::{ error::{Error, Result}, }; -/// Provides functionality for executing terminal commands and managing terminal state. +/// Provides functionality for executing terminal commands +/// and managing terminal state. /// -/// The `Engine` struct encapsulates methods for interacting with the terminal, such as moving the cursor, -/// clearing the screen, writing text, and more. It leverages the `crossterm` crate to provide cross-platform +/// The `Engine` struct encapsulates methods for interacting +/// with the terminal, such as moving the cursor, +/// clearing the screen, writing text, and more. +/// It leverages the `crossterm` crate to provide cross-platform /// terminal operations. #[derive(Clone)] pub struct Engine { @@ -54,16 +57,19 @@ impl Engine { /// /// # Returns /// - /// Returns a `Result` indicating the success of the operation, or an `Error` if it fails. + /// Returns a `Result` indicating the success of the operation, + /// or an `Error` if it fails. pub fn clear_from_cursor_down(&mut self) -> Result { execute!(self.out, Clear(ClearType::FromCursorDown)).map_err(Error::from) } - /// Clears the entire terminal screen and moves the cursor to the top-left position. + /// Clears the entire terminal screen + /// and moves the cursor to the top-left position. /// /// # Returns /// - /// Returns a `Result` indicating the success of the operation, or an `Error` if it fails. + /// Returns a `Result` indicating the success of the operation, + /// or an `Error` if it fails. pub fn clear(&mut self) -> Result { execute!(self.out, Clear(ClearType::All), MoveTo(0, 0)).map_err(Error::from) } @@ -76,7 +82,8 @@ impl Engine { /// /// # Returns /// - /// Returns a `Result` indicating the success of the operation, or an `Error` if it fails. + /// Returns a `Result` indicating the success of the operation, + /// or an `Error` if it fails. pub fn write(&mut self, string: D) -> Result { execute!(self.out, Print(string)).map_err(Error::from) } @@ -89,7 +96,8 @@ impl Engine { /// /// # Returns /// - /// Returns a `Result` indicating the success of the operation, or an `Error` if it fails. + /// Returns a `Result` indicating the success of the operation, + /// or an `Error` if it fails. pub fn move_to(&mut self, pos: (u16, u16)) -> Result { execute!(self.out, MoveTo(pos.0, pos.1)).map_err(Error::from) } @@ -98,7 +106,8 @@ impl Engine { /// /// # Returns /// - /// Returns a `Result` containing `true` if the cursor is at the bottom, otherwise `false`. + /// Returns a `Result` containing `true` + /// if the cursor is at the bottom, otherwise `false`. pub fn is_bottom(&self) -> Result { Ok(cursor::position()?.1 + 1 == terminal::size()?.1) } @@ -111,7 +120,8 @@ impl Engine { /// /// # Returns /// - /// Returns a `Result` indicating the success of the operation, or an `Error` if it fails. + /// Returns a `Result` indicating the success of the operation, + /// or an `Error` if it fails. pub fn scroll_up(&mut self, times: u16) -> Result { execute!(self.out, ScrollUp(times)).map_err(Error::from) } @@ -120,7 +130,8 @@ impl Engine { /// /// # Returns /// - /// Returns a `Result` indicating the success of the operation, or an `Error` if it fails. + /// Returns a `Result` indicating the success of the operation, + /// or an `Error` if it fails. pub fn move_to_next_line(&mut self) -> Result { execute!(self.out, cursor::MoveToNextLine(1)).map_err(Error::from) } diff --git a/src/grapheme.rs b/src/grapheme.rs index 529e5a14..8441b835 100644 --- a/src/grapheme.rs +++ b/src/grapheme.rs @@ -1,23 +1,35 @@ //! Manages characters and their display widths within a terminal interface. //! -//! This module provides structures and functions for handling graphemes (characters and their associated display widths) -//! in terminal applications. It is designed to accurately manage cursor positions and text rendering, especially when dealing -//! with wide characters such as emojis or special symbols that occupy more than one column in terminal displays. +//! This module provides structures +//! and functions for handling graphemes +//! (characters and their associated display widths) +//! in terminal applications. +//! It is designed to accurately manage cursor positions +//! and text rendering, especially when dealing +//! with wide characters such as emojis +//! or special symbols that occupy more than one column in terminal displays. //! //! # Structures //! -//! - `Grapheme`: Represents a single character, its display width, and optional styling. -//! - `Graphemes`: A collection of `Grapheme` instances, supporting operations like total width calculation and styling. +//! - `Grapheme`: Represents a single character, +//! its display width, and optional styling. +//! - `Graphemes`: A collection of `Grapheme` instances, +//! supporting operations like total width calculation and styling. //! //! # Utility Functions //! -//! - `matrixify`: Splits a collection of graphemes into lines that fit within a specified width, useful for text wrapping. -//! - `trim`: Trims a collection of graphemes to fit within a specified width, discarding any excess graphemes. +//! - `matrixify`: Splits a collection of graphemes into lines +//! that fit within a specified width, useful for text wrapping. +//! - `trim`: Trims a collection of graphemes +//! to fit within a specified width, discarding any excess graphemes. //! //! # Usage //! -//! This module is intended for use in terminal applications where accurate text rendering and cursor movement are crucial. -//! It leverages the `unicode_width` crate to calculate the display width of characters, ensuring compatibility with a wide +//! This module is intended for use in terminal applications +//! where accurate text rendering and cursor movement are crucial. +//! It leverages the `unicode_width` crate +//! to calculate the display width of characters, +//! ensuring compatibility with a wide //! range of Unicode characters. use std::{ fmt::{self, Debug}, diff --git a/src/lib.rs b/src/lib.rs index 82173b2a..921d439d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -140,17 +140,26 @@ pub struct Prompt { static ONCE: Once = Once::new(); impl Prompt { - /// Creates a new `Prompt` instance with specified renderables, evaluator, and output functions. + /// Creates a new `Prompt` instance + /// with specified renderables, evaluator, and output functions. /// /// # Arguments /// - /// * `renderables` - A vector of boxed objects implementing the `Renderable` trait. These are the UI components that will be rendered. - /// * `evaluator` - A function that takes an event and the current state of renderables, returning a `Result` indicating whether the prompt is ready to produce an output. - /// * `output` - A function that takes the current state of renderables and returns a `Result`, where `T` is the type of the output produced by the prompt. + /// * `renderables` - A vector of boxed objects implementing + /// the `Renderable` trait. + /// These are the UI components that will be rendered. + /// * `evaluator` - A function that takes an event + /// and the current state of renderables, + /// returning a `Result` indicating + /// whether the prompt is ready to produce an output. + /// * `output` - A function that takes the current state of renderables + /// and returns a `Result`, where `T` is the type of the output + /// produced by the prompt. /// /// # Returns /// - /// Returns a `Result` wrapping a new `Prompt` instance if successful, or an error if the creation fails. + /// Returns a `Result` wrapping a new `Prompt` instance + /// if successful, or an error if the creation fails. pub fn try_new( renderables: Vec>, evaluator: E, @@ -167,15 +176,20 @@ impl Prompt { }) } - /// Runs the prompt, handling events and rendering UI components until an output is produced or an error occurs. + /// Runs the prompt, handling events and rendering UI components + /// until an output is produced or an error occurs. /// - /// This method initializes the terminal in raw mode, hides the cursor, and enters a loop to handle events. - /// It continuously renders the UI components based on the current state and events until the evaluator function - /// indicates that the prompt is ready to produce an output or an interrupt signal (e.g., Ctrl+C) is received. + /// This method initializes the terminal + /// in raw mode, hides the cursor, and enters a loop to handle events. + /// It continuously renders the UI components + /// based on the current state and events until the evaluator function + /// indicates that the prompt is ready to produce + /// an output or an interrupt signal (e.g., Ctrl+C) is received. /// /// # Returns /// - /// Returns a `Result`, where `T` is the type of the output produced by the prompt, or an error if the prompt fails to run. + /// Returns a `Result`, where `T` is the type of the output + /// produced by the prompt, or an error if the prompt fails to run. pub fn run(&mut self) -> Result { let mut engine = Engine::new(io::stdout()); diff --git a/src/pane.rs b/src/pane.rs index a4c545b1..c67695dd 100644 --- a/src/pane.rs +++ b/src/pane.rs @@ -1,10 +1,14 @@ use crate::grapheme::Graphemes; -/// Represents a pane within a terminal interface, managing a layout of graphemes. +/// Represents a pane within a terminal interface, +/// managing a layout of graphemes. /// -/// A `Pane` is essentially a container for text, where the text is represented as a vector of `Graphemes`. -/// It supports operations such as checking if the pane is empty and extracting a subset of graphemes -/// based on the viewport height and other parameters like offset and fixed height. +/// A `Pane` is essentially a container for text, +/// where the text is represented as a vector of `Graphemes`. +/// It supports operations such as checking +/// if the pane is empty and extracting a subset of graphemes +/// based on the viewport height +/// and other parameters like offset and fixed height. pub struct Pane { /// The layout of graphemes within the pane. layout: Vec, @@ -15,11 +19,13 @@ pub struct Pane { } impl Pane { - /// Constructs a new `Pane` with the specified layout, offset, and optional fixed height. + /// Constructs a new `Pane` + /// with the specified layout, offset, and optional fixed height. /// /// # Arguments /// - /// * `layout` - A vector of `Graphemes` representing the content of the pane. + /// * `layout` - A vector of `Graphemes` representing + /// the content of the pane. /// * `offset` - The initial offset from the top of the pane. /// * `fixed_height` - An optional fixed height for the pane. pub fn new(layout: Vec, offset: usize, fixed_height: Option) -> Self { @@ -30,7 +36,9 @@ impl Pane { } } - /// Checks if the pane is empty. A pane is considered empty if it contains a single grapheme with no width. + /// Checks if the pane is empty. + /// A pane is considered empty + /// if it contains a single grapheme with no width. /// /// # Returns /// @@ -39,18 +47,22 @@ impl Pane { self.layout.len() == 1 && self.layout[0].widths() == 0 } - /// Extracts a subset of graphemes to fit within a specified viewport height. + /// Extracts a subset of graphemes + /// to fit within a specified viewport height. /// - /// This method takes into account the pane's offset and fixed height (if any) to determine + /// This method takes into account the pane's offset + /// and fixed height (if any) to determine /// which graphemes to include in the returned vector. /// /// # Arguments /// - /// * `viewport_height` - The height of the viewport in which the graphemes are to be displayed. + /// * `viewport_height` - The height of the viewport + /// in which the graphemes are to be displayed. /// /// # Returns /// - /// Returns a vector of `Graphemes` that fit within the specified viewport height. + /// Returns a vector of `Graphemes` that fit + /// within the specified viewport height. pub fn extract(&self, viewport_height: usize) -> Vec { let lines = self.layout.len().min( self.fixed_height diff --git a/src/preset.rs b/src/preset.rs index 6290998a..87fbd04c 100644 --- a/src/preset.rs +++ b/src/preset.rs @@ -1,18 +1,25 @@ -//! This module provides a collection of preset components for building interactive command-line interfaces. -//! It includes a variety of common UI elements such as checkboxes, text input fields, selection lists, and trees. +//! This module provides a collection of preset components +//! for building interactive command-line interfaces. +//! It includes a variety of common UI elements +//! such as checkboxes, text input fields, selection lists, and trees. //! -//! Each component is designed to be easy to use and integrate into CLI applications, providing a quick way +//! Each component is designed to be easy to use +//! and integrate into CLI applications, providing a quick way //! to add interactivity and collect input from users. //! //! ## Components //! //! - `Checkbox`: For creating and managing a list of selectable options. -//! - `Readline`: For reading a line of text from the user. Includes variations like `Confirm` for yes/no questions, and `Password` for masked input. +//! - `Readline`: For reading a line of text from the user. +//! Includes variations like `Confirm` for yes/no questions, +//! and `Password` for masked input. //! - `Select`: For allowing the user to select from a list of options. -//! - `QuerySelect`: Similar to `Select`, but with support for filtering options through user input. +//! - `QuerySelect`: Similar to `Select`, +//! but with support for filtering options through user input. //! - `Tree`: For displaying and navigating hierarchical data. //! -//! These components can be used individually or combined to create complex user interfaces in terminal applications. +//! These components can be used individually +//! or combined to create complex user interfaces in terminal applications. mod checkbox; pub use checkbox::Checkbox; diff --git a/src/preset/checkbox.rs b/src/preset/checkbox.rs index 21a53d2d..afafce7a 100644 --- a/src/preset/checkbox.rs +++ b/src/preset/checkbox.rs @@ -9,7 +9,8 @@ use crate::{ text, Prompt, }; -/// Represents a checkbox component for creating and managing a list of selectable options. +/// Represents a checkbox component for creating +/// and managing a list of selectable options. pub struct Checkbox { /// Renderer for the title displayed above the checkbox list. title_renderer: text::Renderer, @@ -18,11 +19,13 @@ pub struct Checkbox { } impl Checkbox { - /// Constructs a new `Checkbox` instance with a list of items to be displayed as selectable options. + /// Constructs a new `Checkbox` instance with a list of items + /// to be displayed as selectable options. /// /// # Arguments /// - /// * `items` - An iterator over items that implement the `Display` trait, to be used as options. + /// * `items` - An iterator over items + /// that implement the `Display` trait, to be used as options. pub fn new>(items: I) -> Self { Self { title_renderer: text::Renderer { @@ -85,7 +88,8 @@ impl Checkbox { } /// Displays the checkbox prompt and waits for user input. - /// Returns a `Result` containing the `Prompt` result, which is a list of selected options. + /// Returns a `Result` containing the `Prompt` result, + /// which is a list of selected options. pub fn prompt(self) -> Result>> { Prompt::try_new( vec![ diff --git a/src/preset/queryselect.rs b/src/preset/queryselect.rs index b29cee08..1bbd04f4 100644 --- a/src/preset/queryselect.rs +++ b/src/preset/queryselect.rs @@ -14,10 +14,13 @@ use crate::{ Prompt, }; -/// Used to process and filter a list of options based on the input text in the `QuerySelect` component. +/// Used to process and filter a list of options +/// based on the input text in the `QuerySelect` component. type Filter = dyn Fn(&str, &Vec) -> Vec; -/// Represents a query selection component that combines a text editor for input and a list box for displaying filtered options based on the input. +/// Represents a query selection component that combines a text editor +/// for input and a list box +/// for displaying filtered options based on the input. pub struct QuerySelect { /// Renderer for the title displayed above the query selection. title_renderer: text::Renderer, @@ -25,17 +28,22 @@ pub struct QuerySelect { text_editor_renderer: text_editor::Renderer, /// Renderer for the list box component. listbox_renderer: listbox::Renderer, - /// A filter function to apply to the list box items based on the text editor input. + /// A filter function to apply to the list box items + /// based on the text editor input. filter: Box, } impl QuerySelect { - /// Constructs a new `QuerySelect` instance with a list of items and a filter function. + /// Constructs a new `QuerySelect` instance + /// with a list of items and a filter function. /// /// # Arguments /// - /// * `items` - An iterator over items that implement the `Display` trait, to be used as options in the list box. - /// * `filter` - A function that takes the current input from the text editor and the list of items, returning a filtered list of items to display. + /// * `items` - An iterator over items that implement the `Display` trait, + /// to be used as options in the list box. + /// * `filter` - A function that takes the current input + /// from the text editor and the list of items, + /// returning a filtered list of items to display. pub fn new(items: I, filter: F) -> Self where T: Display, @@ -151,7 +159,8 @@ impl QuerySelect { } /// Displays the query select prompt and waits for user input. - /// Returns a `Result` containing the `Prompt` result, which is the selected option. + /// Returns a `Result` containing the `Prompt` result, + /// which is the selected option. pub fn prompt(self) -> Result> { let filter = self.filter; diff --git a/src/preset/readline.rs b/src/preset/readline.rs index c1a64eca..a8c05af5 100644 --- a/src/preset/readline.rs +++ b/src/preset/readline.rs @@ -17,8 +17,10 @@ pub use confirm::Confirm; mod password; pub use password::Password; -/// The `Readline` struct provides functionality for reading a single line of input from the user. -/// It supports various configurations such as input masking, history, suggestions, and custom styles. +/// `Readline` struct provides functionality +/// for reading a single line of input from the user. +/// It supports various configurations +/// such as input masking, history, suggestions, and custom styles. pub struct Readline { /// Renderer for the title displayed above the input field. title_renderer: text::Renderer, @@ -140,7 +142,8 @@ impl Readline { self } - /// Initiates the prompt process, displaying the configured UI elements and handling user input. + /// Initiates the prompt process, + /// displaying the configured UI elements and handling user input. pub fn prompt(self) -> Result> { let validator = self.validator; diff --git a/src/preset/readline/confirm.rs b/src/preset/readline/confirm.rs index ded29ace..e391765f 100644 --- a/src/preset/readline/confirm.rs +++ b/src/preset/readline/confirm.rs @@ -7,7 +7,8 @@ pub struct Confirm(Readline); impl Confirm { /// Creates a new `Confirm` instance with a specified prompt text. - /// The prompt text is formatted to include "(y/n)" to indicate the expected input. + /// The prompt text is formatted + /// to include "(y/n)" to indicate the expected input. /// /// # Arguments /// @@ -28,7 +29,8 @@ impl Confirm { } /// Displays the confirmation prompt and waits for user input. - /// Returns a `Result` containing the `Prompt` result, which is the user's input. + /// Returns a `Result` containing the `Prompt` result, + /// which is the user's input. pub fn prompt(self) -> Result> { self.0.prompt() } diff --git a/src/preset/readline/password.rs b/src/preset/readline/password.rs index 431dfac9..30acb110 100644 --- a/src/preset/readline/password.rs +++ b/src/preset/readline/password.rs @@ -61,7 +61,8 @@ impl Password { } /// Displays the password prompt and waits for user input. - /// Returns a `Result` containing the `Prompt` result, which is the user's input. + /// Returns a `Result` containing the `Prompt` result, + /// which is the user's input. pub fn prompt(self) -> Result> { self.0.prompt() } diff --git a/src/preset/select.rs b/src/preset/select.rs index a1c2be0b..bcc43ccf 100644 --- a/src/preset/select.rs +++ b/src/preset/select.rs @@ -18,11 +18,13 @@ pub struct Select { } impl Select { - /// Constructs a new `Select` instance with a list of items to be displayed as selectable options. + /// Constructs a new `Select` instance + /// with a list of items to be displayed as selectable options. /// /// # Arguments /// - /// * `items` - An iterator over items that implement the `Display` trait, to be used as options. + /// * `items` - An iterator over items + /// that implement the `Display` trait, to be used as options. pub fn new>(items: I) -> Self { Self { title_renderer: text::Renderer { @@ -78,7 +80,8 @@ impl Select { } /// Displays the select prompt and waits for user input. - /// Returns a `Result` containing the `Prompt` result, which is the selected option. + /// Returns a `Result` containing the `Prompt` result, + /// which is the selected option. pub fn prompt(self) -> Result> { Prompt::try_new( vec![ diff --git a/src/preset/tree.rs b/src/preset/tree.rs index 960ff2c5..09f78ba9 100644 --- a/src/preset/tree.rs +++ b/src/preset/tree.rs @@ -8,7 +8,8 @@ use crate::{ Prompt, }; -/// Represents a tree component for creating and managing a hierarchical list of options. +/// Represents a tree component for creating +/// and managing a hierarchical list of options. pub struct Tree { /// Renderer for the title displayed above the tree. title_renderer: text::Renderer, @@ -84,7 +85,8 @@ impl Tree { } /// Displays the tree prompt and waits for user input. - /// Returns a `Result` containing the `Prompt` result, which is a list of selected options. + /// Returns a `Result` containing the `Prompt` result, + /// which is a list of selected options. pub fn prompt(self) -> Result>> { Prompt::try_new( vec![ diff --git a/src/render.rs b/src/render.rs index efeb2d92..56a75a6d 100644 --- a/src/render.rs +++ b/src/render.rs @@ -3,7 +3,8 @@ use std::{any::Any, cell::RefCell}; use crate::{crossterm::event::Event, pane::Pane}; /// A trait for objects that can be rendered in the terminal. -/// It requires the ability to create a pane, handle events, and perform cleanup. +/// It requires the ability to create a pane, handle events, +/// and perform cleanup. pub trait Renderable: AsAny { /// Creates a pane with the given width. fn make_pane(&self, width: u16) -> Pane; @@ -44,13 +45,15 @@ impl Renderable for State { self.after.borrow().make_pane(width) } - /// Updates the `before` state and delegates event handling to the `after` state. + /// Updates the `before` state and delegates event handling + /// to the `after` state. fn handle_event(&mut self, event: &Event) { self.before = self.after.borrow().clone(); self.after.borrow_mut().handle_event(event); } - /// Performs cleanup on the `after` state and updates the `init` and `before` states. + /// Performs cleanup on the `after` state + /// and updates the `init` and `before` states. fn postrun(&mut self) { self.after.borrow_mut().postrun(); self.init = self.after.borrow().clone(); diff --git a/src/style.rs b/src/style.rs index 7743bccc..0c6dc055 100644 --- a/src/style.rs +++ b/src/style.rs @@ -2,9 +2,11 @@ use crate::crossterm::style::{Attributes, Color, ContentStyle}; /// A struct for defining and building styles for terminal text. /// -/// This struct allows for the customization of text appearance in the terminal, -/// including foreground, background, and underline colors, as well as text attributes -/// like bold, italic, etc. It provides a fluent interface for setting these properties, +/// This struct allows for the customization of text appearance +/// in the terminal, including foreground, background, +/// and underline colors, as well as text attributes +/// like bold, italic, etc. +/// It provides a fluent interface for setting these properties, /// and a method to build a `ContentStyle` that can be applied to text. #[derive(Default)] pub struct Style { diff --git a/src/terminal.rs b/src/terminal.rs index 68b96821..17837190 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -2,7 +2,8 @@ use std::io::Write; use crate::{engine::Engine, error::Result, pane::Pane}; -/// Represents a terminal session, managing the display of panes within the terminal window. +/// Represents a terminal session, +/// managing the display of panes within the terminal window. pub struct Terminal { /// The current cursor position within the terminal. position: (u16, u16), @@ -13,7 +14,8 @@ impl Terminal { /// /// # Arguments /// - /// * `engine` - A mutable reference to the Engine, which manages terminal operations. + /// * `engine` - A mutable reference to the Engine, + /// which manages terminal operations. /// /// # Returns /// @@ -28,7 +30,8 @@ impl Terminal { /// /// # Arguments /// - /// * `engine` - A mutable reference to the Engine, which manages terminal operations. + /// * `engine` - A mutable reference to the Engine, + /// which manages terminal operations. /// * `panes` - A vector of Pane instances to be displayed. /// /// # Returns @@ -37,7 +40,8 @@ impl Terminal { /// /// # Errors /// - /// Returns an error if the terminal window does not have enough vertical space to render the UI. + /// Returns an error if the terminal window + /// does not have enough vertical space to render the UI. pub fn draw(&mut self, engine: &mut Engine, panes: Vec) -> Result { let terminal_height = engine.size()?.1 as usize; let viewable_panes = panes diff --git a/src/validate.rs b/src/validate.rs index fe0f35e3..9c9c99cd 100644 --- a/src/validate.rs +++ b/src/validate.rs @@ -1,25 +1,31 @@ /// A generic structure for validating inputs of any type. /// -/// This structure allows for the definition of custom validation logic and error message generation -/// for inputs of a specified type. It encapsulates a validator function and an error message builder +/// This structure allows for the definition of custom validation logic +/// and error message generation for inputs of a specified type. +/// It encapsulates a validator function and an error message builder /// function, both of which operate on references to the input. pub struct Validator { - /// A boxed function that takes a reference to an input of type `T` and returns a boolean + /// A boxed function that takes a reference + /// to an input of type `T` and returns a boolean /// indicating whether the input passes the validation. validator: Box bool>, - /// A boxed function that takes a reference to an input of type `T` and returns a `String` + /// A boxed function that takes a reference + /// to an input of type `T` and returns a `String` /// that describes the validation error. error_message_builder: Box String>, } impl Validator { - /// Constructs a new `Validator` instance with the specified validator and error message builder functions. + /// Constructs a new `Validator` instance + /// with the specified validator and error message builder functions. /// /// # Arguments /// - /// * `validator` - A function that takes a reference to an input of type `T` and returns a boolean + /// * `validator` - A function that takes a reference + /// to an input of type `T` and returns a boolean /// indicating whether the input passes the validation. - /// * `error_message_builder` - A function that takes a reference to an input of type `T` and returns a `String` + /// * `error_message_builder` - A function that takes a reference + /// to an input of type `T` and returns a `String` /// that describes the validation error. /// /// # Returns @@ -36,24 +42,29 @@ impl Validator { } } - /// Validates the given input using the encapsulated validator function. + /// Validates the given input + /// using the encapsulated validator function. /// /// # Arguments /// - /// * `input` - A reference to the input of type `T` to be validated. + /// * `input` - A reference + /// to the input of type `T` to be validated. /// /// # Returns /// - /// Returns `true` if the input passes the validation, otherwise `false`. + /// Returns `true` if the input passes the validation, + /// otherwise `false`. pub fn validate(&self, input: &T) -> bool { (self.validator)(input) } - /// Generates an error message for the given input using the encapsulated error message builder function. + /// Generates an error message for the given input + /// using the encapsulated error message builder function. /// /// # Arguments /// - /// * `input` - A reference to the input of type `T` for which to generate an error message. + /// * `input` - A reference to the input of type `T` + /// for which to generate an error message. /// /// # Returns ///