pub fn add_to_canvas(args: &[String]) -> Option<String> {
    ////println!("\n\tfunction::add_to_canvas called... ");
    //println!("Printing passed in args: \n {:?} \n", args);
    //get dims
    let mut args = args.to_owned();
    let mut dims = String::new();
    let mut xydims: Vec<i32> = Vec::new();
    let mut canvas = String::new();
    let mut count = 0;
    if !args.is_empty() {
        for slice in &args[..] { //println!("slice={:?}", slice);
            for arg in slice.lines(){
                let line = arg.to_string(); //println!("line=\n{}", line);
                if count == 0 {  //--println!("if count == 0...\n");
                    // build_base_canvas
                    dims = line.to_string();
                    canvas = draw_canvas(&[dims]).unwrap(); //println!("base returned =\n{}", canvas);
                    for dim in get_dims(&[line]).unwrap().lines() {
                        xydims.push(dim.parse().unwrap());
                    }
                    count +=1;
                } else {
                    let mut new_canvas = String::new();
                    let mut position = 0;
                    let mut iter = line.split_ascii_whitespace(); // separate args by spaces
                    let curr_command = Command {
                        sym: iter.next().unwrap().to_string(),
                        rs: iter.next().unwrap().to_string().parse().unwrap(),
                        cs: iter.next().unwrap().to_string().parse().unwrap(),
                        dir: iter.next().unwrap().to_string(),
                        dis: iter.next().unwrap().to_string().parse().unwrap(),
                    };  //println!("{:?}\n", iter.next());
                    //get canvas info
                    //println!("\n\tcurr_command:\n\t{:?}", curr_command);
                    // check for valid indices
                    // rs==ys ; xs==cs
                    let min = 0;
                    let cmax = if xydims[1]-1 < 0 { min } else { xydims[1]-1 };// check #col ==> x dimension
                    let xs = if curr_command.cs > cmax { cmax } else if curr_command.cs < 0 { min } else { curr_command.cs };
                    let rmax = if xydims[0]-1 < 0 { min } else { xydims[0]-1 };// check #row ==> y dimension
                    let ys = if curr_command.rs > rmax { rmax } else if curr_command.rs < 0 { min } else { curr_command.rs };
                    let idist = curr_command.dis;
                    let isym = curr_command.sym;
                    //println!("\n\tcolmax={}, colstart={}, rowmax={}, rowstart={}, dist={}\n", cmax, xs, rmax, ys, idist);
                    if curr_command.dir == "h" { //get direction  //println!("\thorizontal movement"); // horizontal calc
                        let hdist = if cmax-xs+1 > idist { idist } else { cmax+1-xs }; //xs == cs
                        //println!("\thorizontal path length from ({}-{} , {}) = {}\n", xs, cmax, ys, hdist);
                        let pmax = if cmax+1 > hdist {hdist-1} else {cmax};
                        for row in 0..xydims[0] {  //render canvas rs==row to care about
                            let mut curr_str = String::new();
                            curr_str = "".to_string();
                            for col in 0..xydims[1] {
                                let element = canvas.as_bytes()[position] as char;
                                let element = element.to_string();  //println!("current element: {} ", element);
                                let curr_char: &String  = if row==ys && col >= xs && col <=pmax && hdist > 0 { &isym } else { &element };
                                //println!("current_char = {}\n", curr_char);
                                curr_str = curr_str + curr_char;
                                position +=1;
                            }
                            writeln!(&mut new_canvas, "{}", curr_str).unwrap();
                            position+=1;
                        }
                    } else {  //println!("\tvertical movement"); // vertical
                        let vdist = if rmax-ys+1 > idist { idist } else { rmax+1-ys };
                        //println!("vertical path length from ({} , {}-{}) = {}\n", xs, ys, rmax, vdist);
                        let pmax = if rmax+1 > vdist {vdist-1} else {rmax};
                        for row in 0..xydims[0] {  //render canvas cs==col to care about
                            let mut curr_str = String::new();
                            curr_str = "".to_string();
                            for col in 0..xydims[1] {  //let element: String = (canvas.as_bytes()[position] as char).to_string();
                                let element = canvas.as_bytes()[position] as char;
                                let element = element.to_string();  // println!("current element: {}", element);
                                let curr_char: &String  = if ((col==xs) && (row >= ys) && (row <= pmax) && (count < vdist)) { &isym } else { &element };
                                //println!("current_char = {}", curr_char);
                                curr_str = curr_str + curr_char;
                                position +=1;
                            }
                            position+=1;
                            writeln!(&mut new_canvas, "{}", curr_str).unwrap();
                        }
                    } // end if curr_command.dir == h or v
                    canvas = new_canvas;
                }  // end if count == 0 
            }  // end for arg in slice.lines() 
        }  // end for slice in &args[..] 
    } else {
        canvas = "".to_string();
    }  // end if!args.is_empty()
    ////println!("\tRETURNING new canvas from add_to_canvas: \n{}", canvas);
    Some(canvas)
}
/// Builds canvas from tvg file rendering commands  
/// 1. Gets canvas dimensions from first line  
/// 2. Parses rendering commands into a struct for each successive line  
/// 3. Adds characters to canvas as given by each command  
/// num_rows num_cols  
/// char rowstart colstart direction length  
///
/// # Examples:  
///
/// ```
/// # use asciilines::*;  
/// assert_eq!(Some(".**.\n....\n....\n....\n".to_string()), add_to_canvas(&[String::from("4 4\n* 0 1 h 2")]));  
/// ```
/// ```
/// # use asciilines::*;  
/// assert_eq!(Some("......\n.#...\n.#...\n".to_string()), add_to_canvas(&[String::from("3 5\n# 1 1 v 4")]));  
/// ```
Builds canvas from tvg file rendering commands
1. Gets canvas dimensions from first line
2. Parses rendering commands into a struct for each successive line
3. Adds characters to canvas as given by each command
num_rows num_cols
char rowstart colstart direction length
Builds canvas from tvg file rendering commands 1 . Gets canvas dimensions from first line 2 . Parses rendering commands into a struct for each successive line 3 . Adds characters to canvas as given by each command num_rows num_cols char rowstart colstart direction length
pub fn add_to_canvas(args: &[String]) -> Option<String> {
    ////println!("\n\tfunction::add_to_canvas called... ");
    //println!("Printing passed in args: \n {:?} \n", args);
    //get dims
    let mut args = args.to_owned();
    let mut dims = String::new();
    let mut xydims: Vec<i32> = Vec::new();
    let mut canvas = String::new();
    let mut count = 0;
    if !args.is_empty() {
        for slice in &args[..] { //println!("slice={:?}", slice);
            for arg in slice.lines(){
                let line = arg.to_string(); //println!("line=\n{}", line);
                if count == 0 {  //--println!("if count == 0...\n");
                    // build_base_canvas
                    dims = line.to_string();
                    canvas = draw_canvas(&[dims]).unwrap(); //println!("base returned =\n{}", canvas);
                    for dim in get_dims(&[line]).unwrap().lines() {
                        xydims.push(dim.parse().unwrap());
                    }
                    count +=1;
                } else {
                    let mut new_canvas = String::new();
                    let mut position = 0;
                    let mut iter = line.split_ascii_whitespace(); // separate args by spaces
                    let curr_command = Command {
                        sym: iter.next().unwrap().to_string(),
                        rs: iter.next().unwrap().to_string().parse().unwrap(),
                        cs: iter.next().unwrap().to_string().parse().unwrap(),
                        dir: iter.next().unwrap().to_string(),
                        dis: iter.next().unwrap().to_string().parse().unwrap(),
                    };  //println!("{:?}\n", iter.next());
                    //get canvas info
                    //println!("\n\tcurr_command:\n\t{:?}", curr_command);
                    // check for valid indices
                    // rs==ys ; xs==cs
                    let min = 0;
                    let cmax = if xydims[1]-1 < 0 { min } else { xydims[1]-1 };// check #col ==> x dimension
                    let xs = if curr_command.cs > cmax { cmax } else if curr_command.cs < 0 { min } else { curr_command.cs };
                    let rmax = if xydims[0]-1 < 0 { min } else { xydims[0]-1 };// check #row ==> y dimension
                    let ys = if curr_command.rs > rmax { rmax } else if curr_command.rs < 0 { min } else { curr_command.rs };
                    let idist = curr_command.dis;
                    let isym = curr_command.sym;
                    //println!("\n\tcolmax={}, colstart={}, rowmax={}, rowstart={}, dist={}\n", cmax, xs, rmax, ys, idist);
                    if curr_command.dir == "h" { //get direction  //println!("\thorizontal movement"); // horizontal calc
                        let hdist = if cmax-xs+1 > idist { idist } else { cmax+1-xs }; //xs == cs
                        //println!("\thorizontal path length from ({}-{} , {}) = {}\n", xs, cmax, ys, hdist);
                        let pmax = if cmax+1 > hdist {hdist-1} else {cmax};
                        for row in 0..xydims[0] {  //render canvas rs==row to care about
                            let mut curr_str = String::new();
                            curr_str = "".to_string();
                            for col in 0..xydims[1] {
                                let element = canvas.as_bytes()[position] as char;
                                let element = element.to_string();  //println!("current element: {} ", element);
                                let curr_char: &String  = if row==ys && col >= xs && col <=pmax && hdist > 0 { &isym } else { &element };
                                //println!("current_char = {}\n", curr_char);
                                curr_str = curr_str + curr_char;
                                position +=1;
                            }
                            writeln!(&mut new_canvas, "{}", curr_str).unwrap();
                            position+=1;
                        }
                    } else {  //println!("\tvertical movement"); // vertical
                        let vdist = if rmax-ys+1 > idist { idist } else { rmax+1-ys };
                        //println!("vertical path length from ({} , {}-{}) = {}\n", xs, ys, rmax, vdist);
                        let pmax = if rmax+1 > vdist {vdist-1} else {rmax};
                        for row in 0..xydims[0] {  //render canvas cs==col to care about
                            let mut curr_str = String::new();
                            curr_str = "".to_string();
                            for col in 0..xydims[1] {  //let element: String = (canvas.as_bytes()[position] as char).to_string();
                                let element = canvas.as_bytes()[position] as char;
                                let element = element.to_string();  // println!("current element: {}", element);
                                let curr_char: &String  = if ((col==xs) && (row >= ys) && (row <= pmax) && (count < vdist)) { &isym } else { &element };
                                //println!("current_char = {}", curr_char);
                                curr_str = curr_str + curr_char;
                                position +=1;
                            }
                            position+=1;
                            writeln!(&mut new_canvas, "{}", curr_str).unwrap();
                        }
                    } // end if curr_command.dir == h or v
                    canvas = new_canvas;
                }  // end if count == 0 
            }  // end for arg in slice.lines() 
        }  // end for slice in &args[..] 
    } else {
        canvas = "".to_string();
    }  // end if!args.is_empty()
    ////println!("\tRETURNING new canvas from add_to_canvas: \n{}", canvas);
    Some(canvas)
}
pub fn add_to_canvas ( args : & [ String ] ) -> Option < String > { ////println!("\n\tfunction::add_to_canvas called... "); //println!("Printing passed in args: \n {:?} \n", args); //get dims let mut args = args . to_owned ( ) ; let mut dims = String :: new ( ) ; let mut xydims : Vec < i32 > = Vec :: new ( ) ; let mut canvas = String :: new ( ) ; let mut count = 0 ; if ! args . is_empty ( ) { for slice in & args [ .. ] { //println!("slice={:?}", slice); for arg in slice . lines ( ) { let line = arg . to_string ( ) ; //println!("line=\n{}", line); if count == 0 { //--println!("if count == 0...\n"); // build_base_canvas dims = line . to_string ( ) ; canvas = draw_canvas ( & [ dims ] ) . unwrap ( ) ; //println!("base returned =\n{}", canvas); for dim in get_dims ( & [ line ] ) . unwrap ( ) . lines ( ) { xydims . push ( dim . parse ( ) . unwrap ( ) ) ; } count += 1 ; } else { let mut new_canvas = String :: new ( ) ; let mut position = 0 ; let mut iter = line . split_ascii_whitespace ( ) ; // separate args by spaces let curr_command = Command { sym : iter . next ( ) . unwrap ( ) . to_string ( ) , rs : iter . next ( ) . unwrap ( ) . to_string ( ) . parse ( ) . unwrap ( ) , cs : iter . next ( ) . unwrap ( ) . to_string ( ) . parse ( ) . unwrap ( ) , dir : iter . next ( ) . unwrap ( ) . to_string ( ) , dis : iter . next ( ) . unwrap ( ) . to_string ( ) . parse ( ) . unwrap ( ) , } ; //println!("{:?}\n", iter.next()); //get canvas info //println!("\n\tcurr_command:\n\t{:?}", curr_command); // check for valid indices // rs==ys ; xs==cs let min = 0 ; let cmax = if xydims [ 1 ] - 1 < 0 { min } else { xydims [ 1 ] - 1 } ; // check #col ==> x dimension let xs = if curr_command . cs > cmax { cmax } else if curr_command . cs < 0 { min } else { curr_command . cs } ; let rmax = if xydims [ 0 ] - 1 < 0 { min } else { xydims [ 0 ] - 1 } ; // check #row ==> y dimension let ys = if curr_command . rs > rmax { rmax } else if curr_command . rs < 0 { min } else { curr_command . rs } ; let idist = curr_command . dis ; let isym = curr_command . sym ; //println!("\n\tcolmax={}, colstart={}, rowmax={}, rowstart={}, dist={}\n", cmax, xs, rmax, ys, idist); if curr_command . dir == " " { //get direction  //println!("\thorizontal movement"); // horizontal calc let hdist = if cmax - xs + 1 > idist { idist } else { cmax + 1 - xs } ; //xs == cs //println!("\thorizontal path length from ({}-{} , {}) = {}\n", xs, cmax, ys, hdist); let pmax = if cmax + 1 > hdist { hdist - 1 } else { cmax } ; for row in 0 .. xydims [ 0 ] { //render canvas rs==row to care about let mut curr_str = String :: new ( ) ; curr_str = " " . to_string ( ) ; for col in 0 .. xydims [ 1 ] { let element = canvas . as_bytes ( ) [ position ] as char ; let element = element . to_string ( ) ; //println!("current element: {} ", element); let curr_char : & String = if row == ys && col >= xs && col <= pmax && hdist > 0 { & isym } else { & element } ; //println!("current_char = {}\n", curr_char); curr_str = curr_str + curr_char ; position += 1 ; } writeln ! ( mut new_canvas " " curr_str ) . unwrap ( ) ; position += 1 ; } } else { //println!("\tvertical movement"); // vertical let vdist = if rmax - ys + 1 > idist { idist } else { rmax + 1 - ys } ; //println!("vertical path length from ({} , {}-{}) = {}\n", xs, ys, rmax, vdist); let pmax = if rmax + 1 > vdist { vdist - 1 } else { rmax } ; for row in 0 .. xydims [ 0 ] { //render canvas cs==col to care about let mut curr_str = String :: new ( ) ; curr_str = " " . to_string ( ) ; for col in 0 .. xydims [ 1 ] { //let element: String = (canvas.as_bytes()[position] as char).to_string(); let element = canvas . as_bytes ( ) [ position ] as char ; let element = element . to_string ( ) ; // println!("current element: {}", element); let curr_char : & String = if ( ( col == xs ) && ( row >= ys ) && ( row <= pmax ) && ( count < vdist ) ) { & isym } else { & element } ; //println!("current_char = {}", curr_char); curr_str = curr_str + curr_char ; position += 1 ; } position += 1 ; writeln ! ( mut new_canvas " " curr_str ) . unwrap ( ) ; } } // end if curr_command.dir == h or v canvas = new_canvas ; } // end if count == 0  } // end for arg in slice.lines()  } // end for slice in &args[..]  } else { canvas = " " . to_string ( ) ; } // end if!args.is_empty() ////println!("\tRETURNING new canvas from add_to_canvas: \n{}", canvas); Some ( canvas ) }
Builds canvas from tvg file rendering commands
1.
Builds canvas from tvg file rendering commands 1 .
args
&[String]
args
&[String]
examples:  
None
use asciilines::*;  
None
use asciilines::*;  
None