august 2.4.0

A crate & program for converting HTML to plain text.
Documentation
/// Command line interface for August
///
/// Text goes into stdin,
// use the system allocator so valgrind works
use std::alloc::System;
#[global_allocator]
static A: System = System;

use std::io;

use html5ever::{parse_document, rcdom::RcDom, tendril::TendrilSink};

const DEFAULT_WIDTH: august::Width = 79;

#[cfg(feature = "term-size")]
fn default_width() -> august::Width {
    if let Some((w, _)) = term_size::dimensions() {
        w
    } else {
        DEFAULT_WIDTH
    }
}

#[cfg(not(feature = "term-size"))]
fn default_width() -> august::Width {
    DEFAULT_WIDTH
}

fn main() -> io::Result<()> {
    let mut width: Option<august::Width> = None;
    let mut unstyled: bool = false;
    {
        let width_help: &'static str = if cfg!(feature = "term-size") {
            "Set document width, defaults to terminal width"
        } else {
            "Set document width, defaults to 79"
        };

        let mut ap = argparse::ArgumentParser::new();
        ap.set_description("Convert an HTML document into plain text.");
        ap.refer(&mut unstyled).add_option(
            &["--unstyled"],
            argparse::StoreTrue,
            "If set, styling will be ignored.",
        );
        ap.refer(&mut width)
            .add_option(&["-w", "--width"], argparse::StoreOption, width_help);
        ap.parse_args_or_exit();
    }
    let width = width.unwrap_or_else(default_width);
    let dom = parse_document(RcDom::default(), Default::default())
        .from_utf8()
        .read_from(&mut io::stdin().lock())?;
    if unstyled {
        august::convert_dom_io_unstyled(&dom, width, io::stdout().lock())?
    } else {
        august::convert_dom_io(&dom, width, io::stdout().lock())?
    }

    Ok(())
}