rtile provides a way to work with rectangular areas of text as atomic units which can be used for code generation
works with nightly build, as it is dependent on the feature 'localkeycell_methods'
```rust use rtile::*;
fn main() { kp!(maintileone, "Welcome to RTile! "); tp!(maintiletwo, " Have a great day! ");
kp!(main_combined_tiles, "@{main_tile_one}@{main_tile_two}");
// apply top bottom spacing,
kp!(
combined_tiles_with_top_bottom_spacing,
"@{main_top_bottom_spaces}\n@{main_combined_tiles}\n@{main_top_bottom_spaces}"
);
// apply left right unit spacing, now we have the main_result_tile
kp!(
main_result_tile,
"@{main_left_right_spaces}@{combined_tiles_with_top_bottom_spacing}@{main_left_right_spaces}"
);
tp!(f1, frame_tile(gtp!(main_result_tile).unwrap(), 5, 2));
// set new values for main_tile_one and main_tile_two, to reuse the template with different values
kp!(
main_tile_one,
"Reusing the template with different values. "
);
tp!(main_tile_two, "{:?}", vec![1, 2, 3, 4]);
tp!(f2, frame_tile(gtp!(main_result_tile).unwrap(), 1, 1));
// set new values for main_tile_one and main_tile_two, to reuse the template with different values
kp!(
main_tile_one,
"{} ",
t!(",").vjoin(&vec!["1", "2", "3", "4", "5"], true, Some(t!(",")))
);
tp!(main_tile_two, vec!["one", "two", "three", "four", "five"]);
let result = t!(gtp!(main_result_tile).unwrap());
tp!(f3, frame_tile(result.clone(), 0, 0));
// set new values for main_tile_one and main_tile_two, to reuse the template with different values
let dimensions = result.dimensions();
kp!(main_tile_two, result);
kp!(
main_tile_one,
k!(vec![23, 4, 5, 7, 10]
.iter()
.map(|x| if x % 2 == 0 { format!("Some({x})") } else { "None".to_string() })
.collect::<Vec<String>>())
+ k!(vec![" ==> "; dimensions.1])
);
kp!(arrows,"\n{}\n",t!(vec!["------>"; dimensions.1]));
tp!(f4, frame_tile(gtp!(main_result_tile).unwrap(), 5, 0));
let result = t!(r#"
@{f1}
@{f2}
@{f3} @{arrows} @{f4}
"#);
println!("{}", result);
}
fn setspacing(widthspacing: usize, heightspacing: usize) { //set the spacing if required - maintain unit spacing, that is sufficient to create the frame let leftrightspaces = vec![" "; widthspacing]; kp!(mainleftrightspaces, vec![leftrightspaces.join(""); 1]); let topbottomspaces = vec![" "; 1]; kp!( maintopbottomspaces, vec![topbottomspaces.join(""); height_spacing] ); }
fn frametile(input: RTile, widthspacing: usize, heightspacing: usize) -> RTile { setspacing(widthspacing, heightspacing); if heightspacing > 0 { // apply top bottom spacing, kp!( combinedtileswithtopbottomspacing, "@{maintopbottomspaces}\n@{maincombinedtiles}\n@{maintopbottomspaces}" ); } else { // remove the top bottom spacing, tp!( combinedtileswithtopbottomspacing, "@{maintopbottomspaces}\n@{maincombinedtiles}\n@{maintopbottom_spaces}" ); }
let (width, height) = kp!(frame_tile, input).dimensions();
tp!(main_height, vec!["|"; height]);
tp!(main_width, vec!["="; width + 2].join(""));
t!(r#"
@{main_width}
@{main_height}@{frame_tile}@{main_height}
@{main_width}
"#)
} ```
| | | | | Welcome to RTile! Have a great day! | | |
================================================================ | | | Reusing the template with different values. [1, 2, 3, 4] |
========== ==================================== |1, one | ------> | None ==> 1, one | |2, two | ------> | Some(4) ==> 2, two | |3, three| ------> | None ==> 3, three | |4, four | ------> | None ==> 4, four | |5, five | ------> | Some(10) ==> 5, five | ========== ==================================== ```