From 66429e6714414f44da0b0586a8afbf7c9804ae6d Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Wed, 15 Nov 2023 18:34:17 -0800 Subject: [PATCH] print all strings --- src/sneakers.rs | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/sneakers.rs b/src/sneakers.rs index 3fe0ab5..09c193e 100644 --- a/src/sneakers.rs +++ b/src/sneakers.rs @@ -20,8 +20,50 @@ pub extern "C" fn rust_sneakers_effect() { println!("Rust sneakers effect"); use std::time::Duration; + let (term_width, _term_height) = crossterm::terminal::size().expect("Error reading terminal size"); + let term_width = term_width as usize; + let mut buf = String::new(); + + buf.push_str(head1Left); + let spaces = term_width - head1Left.len() - head1Right.len(); + buf.push_str(&" ".repeat(spaces)); + buf.push_str(head1Right); + buf.push('\n'); + + for text in [head2Center, head3Center].iter(){ + let spaces = ((term_width - text.len()) / 2); + buf.push_str(&" ".repeat(spaces)); + buf.push_str(text); + buf.push_str("\n\n"); + }; + + for text in [head4Center, head5Center].iter(){ + let spaces = ((term_width - text.len()) / 2); + buf.push_str(&" ".repeat(spaces)); + buf.push_str(text); + buf.push('\n'); + }; + + buf.push('\n'); + + for text in [menu1, menu2, menu3, menu4, menu5, menu6].iter() { + let spaces = ((term_width - head5Center.len()) / 2) + 3; + buf.push_str(&" ".repeat(spaces)); + buf.push_str(text); + buf.push('\n'); + } + + for text in [foot1Center, foot2Center].iter() { + let spaces = ((term_width - text.len()) / 2); + buf.push('\n'); + buf.push_str(&" ".repeat(spaces)); + buf.push_str(text); + buf.push('\n'); + }; + + println!("{}", buf); + let dur = Duration::from_millis(2000); std::thread::sleep(dur); - let mut buf = String::new(); }