fn parse_line(line: &str, columns: i32, align: bool, gather_valid: bool, settings: &Settings) -> String {
    let mut ret = String::new();
    let mut build_key = false;
    let mut key = String::new();
    let width = size().unwrap().0 as i32;
    let mut col_width = 0;
    if columns > 0 {
        col_width = width / (columns + 1);
    }
    let mut ignore = false;
    let mut col_contents_len = 0;
    for c in line.chars() {
        if build_key {
            match c {
                // end of key
                '{' | '[' => {
                    build_key = false;
                    //                    build_name = true;
                    if !gather_valid {
                        match key.as_str() {
                            "text" => ret.push_str(&settings.bg_col_info),
                            "textbf" => ret.push_str("\x1B[1m"),
                            "emph" => ret.push_str("\x1B[7m"),
                            "texttt" => ret.push_str("\x1B[4m"),
                            "href" => {
                                if settings.show_info_url {
                                    ret.push_str("\x1B[34m");
                                } else {
                                    ignore = true;
                                }
                            }
                            //                            "hyperref" => ret.push_str("\x1B[4m"),
                            //                            "hyperlink" => build_key = true, // ignore link text
                            _ => ignore = true,
                        };
                    }
                    if &key != "href" {
                        // hold href key to insert space after it
                        key.clear();
                    }
                }
                // end of key - may be special character or formatting
                ' ' | ',' | '(' | ')' | '\\' | '0'..='9' | '$' | '&' => {
                    build_key = false;
                    if &key == "item" {
                        if !gather_valid {
                            ret.push('•');
                        }
                    }
                    ret.push(special_char(&key));
                    col_contents_len += 1;
                    if c == ',' || c == '(' || c == ')' || (c >= '0' && c <= '9') || c == '$' {
                        ret.push(c);
                    }
                    if c == '\\' {
                        if key.len() > 0 {
                            // check for double \
                            build_key = true; // or start of new key
                        }
                    }
                    key.clear();
                }
                // found escaped character
                '_' | '^' | '#' => {
                    build_key = false;
                    ret.push(c);
                    col_contents_len += 1;
                    key.clear();
                }
                _ => key.push(c),
            }
        } else {
            match c {
                '\\' => build_key = true,
                '}' | ']' => {
                    if !ignore {
                        if !gather_valid {
                            ret.push_str(&settings.bg_col_info);
                            if &key == "href" {
                                ret.push(' ');
                                key.clear();
                            } else if c == ']' {
                                ret.push(']');
                            }
                        }
                    }
                    ignore = false;
                }
                '{' => {
                    if !gather_valid {
                        ret.push_str("\x1B[4m");
                    }
                }
                '&' => {
                    if columns > 0 {
                        let fill = col_width - col_contents_len - 1;
                        if fill > 0 {
                            ret.push_str(&" ".repeat(fill as usize));
                        }
                        ret.push_str("|");
                        col_contents_len = 0;
                    } else {
                        if !align {
                            ret.push('&');
                        }
                    }
                }
                _ => {
                    if !ignore {
                        ret.push(c);
                        col_contents_len += 1;
                    }
                }
            }
        }
    }
    if key.len() > 0 {
        ret.push(special_char(&key));
    }
    if !gather_valid {
        if key == "tightlist" {
            // ignore
            ret.clear();
        } else {
            if key == "hline" {
                ret.push_str(&"-".repeat(width as usize - 4));
            }
            ret.push_str("\r\n");
        }
    }

    ret
}
/// Go through line 1 character at a time to apply .tex formatting
///
/// TODO: pass back attributes so formatting/mode can exist for more than 1 line
///
Go through line 1 character at a time to apply .tex formatting
TODO: pass back attributes so formatting/mode can exist for more than 1 line
Go through line 1 character at a time to apply . tex formatting TODO : pass back attributes so formatting / mode can exist for more than 1 line
fn parse_line(line: &str, columns: i32, align: bool, gather_valid: bool, settings: &Settings) -> String {
    let mut ret = String::new();
    let mut build_key = false;
    let mut key = String::new();
    let width = size().unwrap().0 as i32;
    let mut col_width = 0;
    if columns > 0 {
        col_width = width / (columns + 1);
    }
    let mut ignore = false;
    let mut col_contents_len = 0;
    for c in line.chars() {
        if build_key {
            match c {
                // end of key
                '{' | '[' => {
                    build_key = false;
                    //                    build_name = true;
                    if !gather_valid {
                        match key.as_str() {
                            "text" => ret.push_str(&settings.bg_col_info),
                            "textbf" => ret.push_str("\x1B[1m"),
                            "emph" => ret.push_str("\x1B[7m"),
                            "texttt" => ret.push_str("\x1B[4m"),
                            "href" => {
                                if settings.show_info_url {
                                    ret.push_str("\x1B[34m");
                                } else {
                                    ignore = true;
                                }
                            }
                            //                            "hyperref" => ret.push_str("\x1B[4m"),
                            //                            "hyperlink" => build_key = true, // ignore link text
                            _ => ignore = true,
                        };
                    }
                    if &key != "href" {
                        // hold href key to insert space after it
                        key.clear();
                    }
                }
                // end of key - may be special character or formatting
                ' ' | ',' | '(' | ')' | '\\' | '0'..='9' | '$' | '&' => {
                    build_key = false;
                    if &key == "item" {
                        if !gather_valid {
                            ret.push('•');
                        }
                    }
                    ret.push(special_char(&key));
                    col_contents_len += 1;
                    if c == ',' || c == '(' || c == ')' || (c >= '0' && c <= '9') || c == '$' {
                        ret.push(c);
                    }
                    if c == '\\' {
                        if key.len() > 0 {
                            // check for double \
                            build_key = true; // or start of new key
                        }
                    }
                    key.clear();
                }
                // found escaped character
                '_' | '^' | '#' => {
                    build_key = false;
                    ret.push(c);
                    col_contents_len += 1;
                    key.clear();
                }
                _ => key.push(c),
            }
        } else {
            match c {
                '\\' => build_key = true,
                '}' | ']' => {
                    if !ignore {
                        if !gather_valid {
                            ret.push_str(&settings.bg_col_info);
                            if &key == "href" {
                                ret.push(' ');
                                key.clear();
                            } else if c == ']' {
                                ret.push(']');
                            }
                        }
                    }
                    ignore = false;
                }
                '{' => {
                    if !gather_valid {
                        ret.push_str("\x1B[4m");
                    }
                }
                '&' => {
                    if columns > 0 {
                        let fill = col_width - col_contents_len - 1;
                        if fill > 0 {
                            ret.push_str(&" ".repeat(fill as usize));
                        }
                        ret.push_str("|");
                        col_contents_len = 0;
                    } else {
                        if !align {
                            ret.push('&');
                        }
                    }
                }
                _ => {
                    if !ignore {
                        ret.push(c);
                        col_contents_len += 1;
                    }
                }
            }
        }
    }
    if key.len() > 0 {
        ret.push(special_char(&key));
    }
    if !gather_valid {
        if key == "tightlist" {
            // ignore
            ret.clear();
        } else {
            if key == "hline" {
                ret.push_str(&"-".repeat(width as usize - 4));
            }
            ret.push_str("\r\n");
        }
    }
    ret
}
fn parse_line ( line : & str , columns : i32 , align : bool , gather_valid : bool , settings : & Settings ) -> String { let mut ret = String :: new ( ) ; let mut build_key = false ; let mut key = String :: new ( ) ; let width = size ( ) . unwrap ( ) . 0 as i32 ; let mut col_width = 0 ; if columns > 0 { col_width = width / ( columns + 1 ) ; } let mut ignore = false ; let mut col_contents_len = 0 ; for c in line . chars ( ) { if build_key { match c { // end of key '{' | '[' => { build_key = false ; //                    build_name = true; if ! gather_valid { match key . as_str ( ) { " " => ret . push_str ( & settings . bg_col_info ) , " " => ret . push_str ( " \x1B " ) , " " => ret . push_str ( " \x1B " ) , " " => ret . push_str ( " \x1B " ) , " " => { if settings . show_info_url { ret . push_str ( " \x1B " ) ; } else { ignore = true ; } } //                            "hyperref" => ret.push_str("\x1B[4m"), //                            "hyperlink" => build_key = true, // ignore link text _ => ignore = true , } ; } if & key != " " { // hold href key to insert space after it key . clear ( ) ; } } // end of key - may be special character or formatting ' ' | ',' | '(' | ')' | '\\' | '0' ..= '9' | '$' | '&' => { build_key = false ; if & key == " " { if ! gather_valid { ret . push ( '•'); } } ret . push ( special_char ( & key ) ) ; col_contents_len += 1 ; if c == ',' || c == '(' || c == ')' || ( c >= '0' && c <= '9' ) || c == '$' { ret . push ( c ) ; } if c == '\\' { if key . len ( ) > 0 { // check for double \ build_key = true ; // or start of new key } } key . clear ( ) ; } // found escaped character '_' | '^' | '#' => { build_key = false ; ret . push ( c ) ; col_contents_len += 1 ; key . clear ( ) ; } _ => key . push ( c ) , } } else { match c { '\\' => build_key = true , '}' | ']' => { if ! ignore { if ! gather_valid { ret . push_str ( & settings . bg_col_info ) ; if & key == " " { ret . push ( ' ' ) ; key . clear ( ) ; } else if c == ']' { ret . push ( ']' ) ; } } } ignore = false ; } '{' => { if ! gather_valid { ret . push_str ( " \x1B " ) ; } } '&' => { if columns > 0 { let fill = col_width - col_contents_len - 1 ; if fill > 0 { ret . push_str ( & " " . repeat ( fill as usize ) ) ; } ret . push_str ( " " ) ; col_contents_len = 0 ; } else { if ! align { ret . push ( '&' ) ; } } } _ => { if ! ignore { ret . push ( c ) ; col_contents_len += 1 ; } } } } } if key . len ( ) > 0 { ret . push ( special_char ( & key ) ) ; } if ! gather_valid { if key == " " { // ignore ret . clear ( ) ; } else { if key == " " { ret . push_str ( & " " . repeat ( width as usize - 4 ) ) ; } ret . push_str ( " \r \n " ) ; } } ret }
Go through line 1 character at a time to apply .tex formatting
TODO: pass back attributes so formatting/mode can exist for more than 1 line
Go through line 1 character at a time to apply . tex formatting TODO : pass back attributes so formatting / mode can exist for more than 1 line
line
&str
columns
i32
align
bool
gather_valid
bool
settings
&Settings
line
&str
columns
i32
align
bool
gather_valid
bool
settings
&Settings