X-Git-Url: http://git.scottworley.com/tablify/blobdiff_plain/12e913005080a9f60750d807c220a58704429361..586b332ada9b821cbc7838ffa9151c9886387918:/src/lib.rs?ds=inline diff --git a/src/lib.rs b/src/lib.rs index dbcfc7b..5c994c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -170,8 +170,13 @@ impl>> Iterator for Reader } } -fn read_rows(input: impl std::io::Read) -> Result, std::io::Error> { - Reader::new(std::io::BufReader::new(input).lines()).collect::, _>>() +fn read_input(input: impl std::io::Read) -> Result<(Vec, Config), std::io::Error> { + let default_config = Config { + column_threshold: 2, + }; + Reader::new(std::io::BufReader::new(input).lines()) + .collect::, _>>() + .map(|rows| (rows, default_config)) } fn column_counts(rows: &[Rowlike]) -> Vec<(usize, String)> { @@ -303,9 +308,9 @@ fn render_column_headers(columns: &[String]) -> HTML { /// * there's an i/o error while reading `input` /// * the log has invalid syntax: /// * an indented line with no preceding non-indented line -pub fn tablify(config: &Config, input: impl std::io::Read) -> Result { - let rows = read_rows(input)?; - let columns = column_order(config, &rows); +pub fn tablify(input: impl std::io::Read) -> Result { + let (rows, config) = read_input(input)?; + let columns = column_order(&config, &rows); Ok(HTML(format!( "{HEADER}{}{}{FOOTER}", render_column_headers(&columns), @@ -348,6 +353,9 @@ mod tests { ); } + fn read_rows(input: impl std::io::Read) -> Result, std::io::Error> { + read_input(input).map(|(rows, _)| rows) + } #[test] fn test_read_rows() { assert_eq!(