This commit is contained in:
2025-01-24 00:34:00 +01:00
parent 05c3376a52
commit 5a9597aed4
4 changed files with 116 additions and 31 deletions
+15 -1
View File
@@ -100,7 +100,7 @@ pub fn str_size(s: &str) -> (u16, u16) {
///
/// # Returns
/// A `Console` instance wrapped in a `Result`.
pub fn init(mouse: bool) -> crate::Result<crate::Console> {
pub fn init<'a>(mouse: bool) -> crate::Result<crate::Console<'a>> {
crossterm::terminal::enable_raw_mode()?;
clear()?;
hide_cursor()?;
@@ -112,6 +112,20 @@ pub fn init(mouse: bool) -> crate::Result<crate::Console> {
width,
height,
mouse,
handle: None,
mouse_position: None,
})
}
pub fn calculate_padding(string_length: usize, width: usize) -> (usize, usize) {
if width <= string_length {
// No padding needed if the string length is greater than or equal to the width
return (0, 0);
}
let total_padding = width - string_length;
let left_padding = total_padding / 2; // Floor division for left padding
let right_padding = total_padding - left_padding; // Remaining for right padding
(left_padding, right_padding)
}