diff --git a/src/args.rs b/src/args.rs index 988f0a4..14c4a61 100644 --- a/src/args.rs +++ b/src/args.rs @@ -18,6 +18,8 @@ pub struct ArgError { } impl ArgError { + /// An ArgError represents an error in the user-supplied command + /// line arguments. pub fn new(err: impl fmt::Display) -> ArgError { ArgError { details: format!("{}", err), diff --git a/src/color.rs b/src/color.rs index d541566..e0d6fe0 100644 --- a/src/color.rs +++ b/src/color.rs @@ -30,6 +30,7 @@ macro_rules! color { /// println!("{}Error: {}{}", color::Red, msg, color::Reset); macro_rules! define_color { ($color:ident, $code:literal) => { + #[allow(missing_docs)] pub struct $color; impl fmt::Display for $color { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/config.rs b/src/config.rs index 90f7410..96b686a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -41,12 +41,18 @@ emoji no /// such as the UI mode (Print, Run, Raw, etc). #[derive(Debug)] pub struct Config { + /// Gopher URL to open on bare launch pub start: String, + /// Whether to use TLS or not pub tls: bool, + /// Using Tor proxy? pub tor: bool, + /// Wide mode pub wide: bool, + /// Render connection status as emoji pub emoji: bool, - pub mode: ui::Mode, // can't be set in conf file + /// UI mode. Can't be set in conf file. + pub mode: ui::Mode, } impl Default for Config { diff --git a/src/gopher.rs b/src/gopher.rs index d302edf..7261c00 100644 --- a/src/gopher.rs +++ b/src/gopher.rs @@ -25,6 +25,7 @@ pub use self::r#type::Type; /// Some Gopher servers can be kind of slow, we may want to up this or /// make it configurable eventually. pub const TCP_TIMEOUT_IN_SECS: u64 = 8; +/// Based on `TCP_TIMEOUT_IN_SECS` but a `Duration` type. pub const TCP_TIMEOUT_DURATION: Duration = Duration::from_secs(TCP_TIMEOUT_IN_SECS); trait ReadWrite: Read + Write {} diff --git a/src/gopher/type.rs b/src/gopher/type.rs index ae76c76..1d05d6c 100644 --- a/src/gopher/type.rs +++ b/src/gopher/type.rs @@ -1,4 +1,5 @@ /// Gopher types are defined according to RFC 1436. +#[allow(missing_docs)] #[derive(Copy, Clone, PartialEq, Debug)] pub enum Type { Text, // 0 | cyan diff --git a/src/menu.rs b/src/menu.rs index 05d0969..6dbf371 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -21,20 +21,34 @@ use termion::{clear, cursor}; /// navigation" feature using number entry and the "incremental search" /// (over menu links) feature using text entry. pub struct Menu { - pub url: String, // gopher url - pub lines: Vec, // lines - pub links: Vec, // links (index of line in lines vec) - pub longest: usize, // size of the longest line - pub raw: String, // raw response - pub input: String, // user's inputted value - pub mode: ui::Mode, // interactive or print mode? - pub link: usize, // selected link - pub scroll: usize, // scrolling offset - pub searching: bool, // search mode? - pub tls: bool, // retrieved via tls? - pub tor: bool, // retrieved via tor? - pub size: (usize, usize), // cols, rows - pub wide: bool, // in wide mode? + /// Gopher URL + pub url: String, + /// Lines in the menu. Not all are links. + pub lines: Vec, + /// Indexes of links in the `lines` vector. Pauper's pointers. + pub links: Vec, + /// Currently selected link. Index of the `links` vec. + pub link: usize, + /// Size of the longest line, for wrapping purposes + pub longest: usize, + /// Actual Gopher response + pub raw: String, + /// User input on a prompt() line + pub input: String, + /// UI mode. Interactive (Run), Printing, Raw mode... + pub mode: ui::Mode, + /// Scrolling offset, in rows. + pub scroll: usize, + /// Incremental search mode? + pub searching: bool, + /// Was this menu retrieved via TLS? + pub tls: bool, + /// Retrieved via Tor? + pub tor: bool, + /// Size of the screen currently, cols and rows + pub size: (usize, usize), + /// Wide mode? + pub wide: bool, } /// The Line represents a single line in a Gopher menu. diff --git a/src/text.rs b/src/text.rs index 0460c6f..549413b 100644 --- a/src/text.rs +++ b/src/text.rs @@ -12,15 +12,24 @@ use termion::clear; /// The Text View holds the raw Gopher response as well as information /// about which lines should currently be displayed on screen. pub struct Text { + /// Gopher URL url: String, + /// Gopher response raw_response: String, - scroll: usize, // offset - lines: usize, // # of lines - longest: usize, // longest line - size: (usize, usize), // cols, rows - pub tls: bool, // retrieved via tls? - pub tor: bool, // retrieved via tor? - pub wide: bool, // in wide mode? turns off margins + /// Current scroll offset, in rows + scroll: usize, + /// Number of lines + lines: usize, + /// Size of longest line + longest: usize, + /// Current screen size, cols and rows + size: (usize, usize), + /// Was this page retrieved view TLS? + pub tls: bool, + /// Retrieved via Tor? + pub tor: bool, + /// Currently in wide mode? + pub wide: bool, } impl fmt::Display for Text { @@ -151,6 +160,7 @@ impl View for Text { } impl Text { + /// Create a Text View from a raw Gopher response and a few options. pub fn from(url: String, response: String, tls: bool, tor: bool) -> Text { let mut lines = 0; let mut longest = 0; diff --git a/src/ui.rs b/src/ui.rs index fa281d0..5532ce0 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -41,7 +41,10 @@ use termion::{ terminal_size, }; +/// Alias for a termion Key event. pub type Key = termion::event::Key; + +/// Alias for either a Menu or Text View. pub type Page = Box; /// How many lines to jump by when using page up/down. @@ -54,17 +57,25 @@ pub const MAX_COLS: usize = 77; /// UI is mainly concerned with drawing to the screen, managing the /// active Views/pages, and responding to user input. pub struct UI { - views: Vec, // loaded views - focused: usize, // currently focused view - dirty: bool, // redraw? - running: bool, // main ui loop running? - pub size: (usize, usize), // cols, rows - status: String, // status message, if any - config: Config, // user config + /// Current loaded Gopher views. Menu or Text + views: Vec, + /// Index of currently focused View + focused: usize, + /// Does the UI need to be entirely redrawn? + dirty: bool, + /// Is the UI running? + running: bool, + /// Size of screen (cols, rows) + pub size: (usize, usize), + /// Status message to display on screen, if any + status: String, + /// User config. Command line options + phetch.conf + config: Config, out: RefCell>, } impl UI { + /// Create a new phetch application from a user provided config. pub fn new(config: Config) -> UI { let mut size = (0, 0); if let Ok((cols, rows)) = terminal_size() {