Start making `missing_docs` happy

pull/14/head
chris west 4 years ago
parent eecaf79d8a
commit 537be056cb

@ -18,6 +18,8 @@ pub struct ArgError {
} }
impl ArgError { impl ArgError {
/// An ArgError represents an error in the user-supplied command
/// line arguments.
pub fn new(err: impl fmt::Display) -> ArgError { pub fn new(err: impl fmt::Display) -> ArgError {
ArgError { ArgError {
details: format!("{}", err), details: format!("{}", err),

@ -30,6 +30,7 @@ macro_rules! color {
/// println!("{}Error: {}{}", color::Red, msg, color::Reset); /// println!("{}Error: {}{}", color::Red, msg, color::Reset);
macro_rules! define_color { macro_rules! define_color {
($color:ident, $code:literal) => { ($color:ident, $code:literal) => {
#[allow(missing_docs)]
pub struct $color; pub struct $color;
impl fmt::Display for $color { impl fmt::Display for $color {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

@ -41,12 +41,18 @@ emoji no
/// such as the UI mode (Print, Run, Raw, etc). /// such as the UI mode (Print, Run, Raw, etc).
#[derive(Debug)] #[derive(Debug)]
pub struct Config { pub struct Config {
/// Gopher URL to open on bare launch
pub start: String, pub start: String,
/// Whether to use TLS or not
pub tls: bool, pub tls: bool,
/// Using Tor proxy?
pub tor: bool, pub tor: bool,
/// Wide mode
pub wide: bool, pub wide: bool,
/// Render connection status as emoji
pub emoji: bool, 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 { impl Default for Config {

@ -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 /// Some Gopher servers can be kind of slow, we may want to up this or
/// make it configurable eventually. /// make it configurable eventually.
pub const TCP_TIMEOUT_IN_SECS: u64 = 8; 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); pub const TCP_TIMEOUT_DURATION: Duration = Duration::from_secs(TCP_TIMEOUT_IN_SECS);
trait ReadWrite: Read + Write {} trait ReadWrite: Read + Write {}

@ -1,4 +1,5 @@
/// Gopher types are defined according to RFC 1436. /// Gopher types are defined according to RFC 1436.
#[allow(missing_docs)]
#[derive(Copy, Clone, PartialEq, Debug)] #[derive(Copy, Clone, PartialEq, Debug)]
pub enum Type { pub enum Type {
Text, // 0 | cyan Text, // 0 | cyan

@ -21,20 +21,34 @@ use termion::{clear, cursor};
/// navigation" feature using number entry and the "incremental search" /// navigation" feature using number entry and the "incremental search"
/// (over menu links) feature using text entry. /// (over menu links) feature using text entry.
pub struct Menu { pub struct Menu {
pub url: String, // gopher url /// Gopher URL
pub lines: Vec<Line>, // lines pub url: String,
pub links: Vec<usize>, // links (index of line in lines vec) /// Lines in the menu. Not all are links.
pub longest: usize, // size of the longest line pub lines: Vec<Line>,
pub raw: String, // raw response /// Indexes of links in the `lines` vector. Pauper's pointers.
pub input: String, // user's inputted value pub links: Vec<usize>,
pub mode: ui::Mode, // interactive or print mode? /// Currently selected link. Index of the `links` vec.
pub link: usize, // selected link pub link: usize,
pub scroll: usize, // scrolling offset /// Size of the longest line, for wrapping purposes
pub searching: bool, // search mode? pub longest: usize,
pub tls: bool, // retrieved via tls? /// Actual Gopher response
pub tor: bool, // retrieved via tor? pub raw: String,
pub size: (usize, usize), // cols, rows /// User input on a prompt() line
pub wide: bool, // in wide mode? 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. /// The Line represents a single line in a Gopher menu.

@ -12,15 +12,24 @@ use termion::clear;
/// The Text View holds the raw Gopher response as well as information /// The Text View holds the raw Gopher response as well as information
/// about which lines should currently be displayed on screen. /// about which lines should currently be displayed on screen.
pub struct Text { pub struct Text {
/// Gopher URL
url: String, url: String,
/// Gopher response
raw_response: String, raw_response: String,
scroll: usize, // offset /// Current scroll offset, in rows
lines: usize, // # of lines scroll: usize,
longest: usize, // longest line /// Number of lines
size: (usize, usize), // cols, rows lines: usize,
pub tls: bool, // retrieved via tls? /// Size of longest line
pub tor: bool, // retrieved via tor? longest: usize,
pub wide: bool, // in wide mode? turns off margins /// 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 { impl fmt::Display for Text {
@ -151,6 +160,7 @@ impl View for Text {
} }
impl 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 { pub fn from(url: String, response: String, tls: bool, tor: bool) -> Text {
let mut lines = 0; let mut lines = 0;
let mut longest = 0; let mut longest = 0;

@ -41,7 +41,10 @@ use termion::{
terminal_size, terminal_size,
}; };
/// Alias for a termion Key event.
pub type Key = termion::event::Key; pub type Key = termion::event::Key;
/// Alias for either a Menu or Text View.
pub type Page = Box<dyn View>; pub type Page = Box<dyn View>;
/// How many lines to jump by when using page up/down. /// 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 /// UI is mainly concerned with drawing to the screen, managing the
/// active Views/pages, and responding to user input. /// active Views/pages, and responding to user input.
pub struct UI { pub struct UI {
views: Vec<Page>, // loaded views /// Current loaded Gopher views. Menu or Text
focused: usize, // currently focused view views: Vec<Page>,
dirty: bool, // redraw? /// Index of currently focused View
running: bool, // main ui loop running? focused: usize,
pub size: (usize, usize), // cols, rows /// Does the UI need to be entirely redrawn?
status: String, // status message, if any dirty: bool,
config: Config, // user config /// 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<RawTerminal<Stdout>>, out: RefCell<RawTerminal<Stdout>>,
} }
impl UI { impl UI {
/// Create a new phetch application from a user provided config.
pub fn new(config: Config) -> UI { pub fn new(config: Config) -> UI {
let mut size = (0, 0); let mut size = (0, 0);
if let Ok((cols, rows)) = terminal_size() { if let Ok((cols, rows)) = terminal_size() {

Loading…
Cancel
Save