Last active
March 24, 2016 04:31
-
-
Save dd86k/412cbe4d32cb1bb758b6 to your computer and use it in GitHub Desktop.
Simple Console Box Generator (Windows) in Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
generate_box(10, 4, 5, 4); | |
} | |
// ┌┐└┘─│ | |
fn generate_box(x: i32, y: i32, width: i32, height: i32) { | |
let mut nwidth = width - 2; // Corners included | |
let mut nheight = height - 2; | |
if nwidth < 2 { nwidth = 0; } | |
if nheight < 2 { nheight = 0; } | |
let mut line: String = String::new(); | |
for w in 0..nwidth { line.push('─'); } | |
print_at(x, y, "┌"); | |
print!("{}", line); | |
print!("┐"); | |
for h in 0..nheight + 1 { | |
print_at(x, y + h + 1, "│"); | |
} | |
let tx = x + width - 1; | |
for h in 0..nheight + 1 { | |
print_at(tx, y + h + 1, "│"); | |
} | |
print_at(x, y + nheight + 1, "└"); | |
print!("{}", line); | |
print!("┘"); | |
} | |
// Windows - ESC[y;xH (Escape character - \x1B) | |
fn print_at(x: i32, y: i32, i: &str) { | |
print!("\x1B[{};{}H{}", y, x, i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment