jsonc_tools 0.0.1

jsonc_tools: Tools to deal with `jsonc` files. See, [JSON with Comments](https://code.visualstudio.com/docs/languages/json#_json-with-comments) and [jsonc](https://komkom.github.io/) (A Json like file format with comments). See, [User and Workspace Settings](https://code.visualstudio.com/docs/getstarted/settings) and [Settings - vscode](https://vscode.readthedocs.io/en/latest/getstarted/settings/) for example files.
Documentation
use better_panic;
use log::{debug, info, trace};
use std::error::Error;
extern crate jsonc_tools;

pub mod lib;

type ErrorType = Box<dyn Error + 'static>;

fn main() -> Result<(), ErrorType> {
    std::env::set_var("RUST_BACKTRACE", "1");
    std::env::set_var("RUST_LOG", "trace");

    better_panic::Settings::debug()
        .most_recent_first(true)
        .backtrace_first(true)
        .lineno_suffix(true)
        .verbosity(better_panic::Verbosity::Full)
        .install();

    let cli = lib::cli::new();

    let log_level = cli.log_level.as_str();
    let rust_log = format!("{}", log_level);
    std::env::set_var("RUST_LOG", rust_log);
    env_logger::builder().format_timestamp(None).init();
    // env_logger::from_env(Env::default().format_timestamp(None).
    // default_filter_or("warn")).init();

    print_separator();
    print_library_info();
    info!("cli={:?}", cli);

    // let lines: Vec<String> = read_lines()?;
    // trace!("lines={:?}", lines);

    let parser = jsonc_tools::parser::Parser::new()?;
    // for line in lines {
    //     parser.add(line)?;
    // }

    debug!("parser={:?}", parser);

    print_separator();

    Ok(())
}

fn _read_lines() -> std::io::Result<Vec<String>> {
    use std::{
        fs::File,
        io::{prelude::*, BufReader},
    };

    let file = File::open(".vscode/settings.json")?;
    let reader = BufReader::new(file);

    let mut lines: Vec<String> = Vec::new();
    for line in reader.lines() {
        let l = line?;
        trace!("line={}", l);
        lines.push(l);
    }

    Ok(lines)
}

fn print_separator() {
    let (width, _height) = lib::terminal_utils::dimensions_or_exit();
    let separator: String = "-"
        .repeat((width - "[2020-08-20T10:11:28Z INFO  main] ".len()) as usize);
    // https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html
    const COLOUR_BORDER: &str = "\x1b[44m";
    const RESET: &str = "\x1b[0m";
    trace!("{}{}{}", COLOUR_BORDER, separator, RESET);
}

fn print_library_info() {
    let pkg_name = env!("CARGO_PKG_NAME");
    let pkg_version = env!("CARGO_PKG_VERSION");
    let pkg_description = env!("CARGO_PKG_DESCRIPTION");
    let pkg_repository = env!("CARGO_PKG_REPOSITORY");
    trace!(
        "main: {}@{}, description={}, repository={}",
        pkg_name,
        pkg_version,
        pkg_description,
        pkg_repository
    );
}