RTile is a simple Rust lib module meant to help with code generation. It provides a way to work with rectangular areas of text as atomic units. Can be used with nightly build only, till the feature 'localkeycell_methods' is stabilized.
Inspired by a python module tiles, developed by Martin Sustrik.
```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}"
);
println!("{}", frame_tile(gtp!(main_result_tile).unwrap(), 5, 2));
}
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! | | |
```