mirror of
https://github.com/tealdeer-rs/tealdeer.git
synced 2026-08-27 10:30:41 +02:00
Move formatter to separate module
This commit is contained in:
parent
9343c52f13
commit
d4a43212cd
2 changed files with 25 additions and 18 deletions
22
src/formatter.rs
Normal file
22
src/formatter.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
//! Functions related to formatting and printing lines from a `Tokenizer`.
|
||||
|
||||
use std::io::BufRead;
|
||||
|
||||
use ansi_term::Colour;
|
||||
|
||||
use tokenizer::Tokenizer;
|
||||
use types::LineType;
|
||||
|
||||
/// Print a token stream to an ANSI terminal.
|
||||
pub fn print_lines<R>(tokenizer: &mut Tokenizer<R>) where R: BufRead {
|
||||
while let Some(token) = tokenizer.next() {
|
||||
match token {
|
||||
LineType::Empty => println!(""),
|
||||
LineType::Title(_) => debug!("Ignoring title"),
|
||||
LineType::Description(text) => println!(" {}", text),
|
||||
LineType::ExampleText(text) => println!(" {}", Colour::Green.paint(format!("- {}", text))),
|
||||
LineType::ExampleCode(text) => println!(" {}", Colour::Cyan.paint(format!(" {}", text))),
|
||||
LineType::Other(text) => debug!("Unknown line type: {:?}", text),
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/main.rs
21
src/main.rs
|
|
@ -10,22 +10,22 @@ extern crate tempdir;
|
|||
extern crate curl;
|
||||
extern crate rustc_serialize;
|
||||
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::io::BufReader;
|
||||
use std::fs::File;
|
||||
use std::process;
|
||||
|
||||
use ansi_term::Colour;
|
||||
use docopt::Docopt;
|
||||
|
||||
mod types;
|
||||
mod tokenizer;
|
||||
mod formatter;
|
||||
mod updater;
|
||||
mod error;
|
||||
|
||||
use types::LineType;
|
||||
use tokenizer::Tokenizer;
|
||||
use updater::Updater;
|
||||
use error::TldrError;
|
||||
use formatter::print_lines;
|
||||
|
||||
|
||||
const USAGE: &'static str = "
|
||||
|
|
@ -83,21 +83,6 @@ fn get_file_reader(filepath: &str) -> Result<BufReader<File>, String> {
|
|||
}
|
||||
|
||||
|
||||
/// Print a token stream to an ANSI terminal.
|
||||
fn print_lines<R>(tokenizer: &mut Tokenizer<R>) where R: BufRead {
|
||||
while let Some(token) = tokenizer.next() {
|
||||
match token {
|
||||
LineType::Empty => println!(""),
|
||||
LineType::Title(_) => debug!("Ignoring title"),
|
||||
LineType::Description(text) => println!(" {}", text),
|
||||
LineType::ExampleText(text) => println!(" {}", Colour::Green.paint(format!("- {}", text))),
|
||||
LineType::ExampleCode(text) => println!(" {}", Colour::Cyan.paint(format!(" {}", text))),
|
||||
LineType::Other(text) => debug!("Unknown line type: {:?}", text),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "logging")]
|
||||
fn init_log() {
|
||||
env_logger::init().unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue