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

Write more docs in the pager module #124

Merged
merged 8 commits into from
Dec 29, 2023
49 changes: 42 additions & 7 deletions src/pager.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,52 @@
//! Proivdes the [Pager] type

use crate::{error::MinusError, input, minus_core::commands::Command, ExitStrategy, LineNumbers};
use crossbeam_channel::{Receiver, Sender};
use std::fmt;

#[cfg(feature = "search")]
use crate::search::SearchOpts;

/// A pager acts as a middleman for communication between the main application
/// and the user with the core functions of minus
/// A communicationA bridge between the main application and the pager.
AMythicDev marked this conversation as resolved.
Show resolved Hide resolved
///
/// The [Pager] type which is a bridge between your application and running
/// the running pager. Its the single most important type with which you will be interacting the
/// most while working with minus. It allows you to send data, configure UI settings and also
/// configure the key/mouse bindings.
///
/// It consists of a [`crossbeam_channel::Sender`] and [`crossbeam_channel::Receiver`]
/// This neat thing about this is that not allows you to trasmits data while the pager is running
/// but also if the pager hsen't been started. This means that you can preconfigure the pager
/// before calling the initialization methods which most applications likely want to do.
AMythicDev marked this conversation as resolved.
Show resolved Hide resolved
///
/// It consists of a [`crossbeam_channel::Sender`] and [`crossbeam_channel::Receiver`]
/// pair. When a method like [`set_text`](Pager::set_text) or [`push_str`](Pager::push_str)
/// is called, the function takes the input. wraps it in the appropriate event
/// type and transmits it through the sender held inside the this.
/// is called, the function takes the input. wraps it in the appropriate command
/// variant and transmits it through the sender held inside the this.
///
/// The receiver part of the channel is continuously polled by the pager for events. Depending
/// on the type of event that occurs, the pager will either redraw the screen or update
/// the [PagerState](crate::state::PagerState)
/// on the type of event that occurs, the pager will perform the required action.
///
/// [Pager] also implements the [std::fmt::Write] trait which means you can directly call [write!] and
/// [writeln!] macros on it. For example, you can easily do this
///
/// ```
/// use minus::Pager;
/// use std::fmt::Write;
///
/// const WHO: &str = "World";
/// let mut pager = Pager::new();
/// writeln!(pager, "Hello {WHO}").unwrap();
/// ```
/// This appends `Hello World` to the end of minus's buffer. You can achieve the same using the
/// [Pager::push_str] function like this
/// ```
/// use minus::Pager;
/// use std::fmt::Write;
///
/// const WHO: &str = "World";
/// let pager = Pager::new();
/// pager.push_str(format!("Hello {WHO}\n")).unwrap();
/// ```
AMythicDev marked this conversation as resolved.
Show resolved Hide resolved
AMythicDev marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Clone)]
pub struct Pager {
pub(crate) tx: Sender<Command>,
Expand Down Expand Up @@ -125,6 +156,10 @@ impl Pager {

/// Display a temporary message at the prompt area
///
/// A message is a piece of text that the main application can ask minus to display at the
/// prompt location. The text message is temporary and will get cleared whenever the use
/// rdoes a action on the terminal like pressing a key or scrolling using the mouse.
///
AMythicDev marked this conversation as resolved.
Show resolved Hide resolved
/// # Panics
/// This function panics if the given text contains newline characters.
/// This is because, the pager reserves only one line for showing the prompt
Expand Down
Loading