r3bl-org/r3bl-open-core

[tuify] Create easy API to surround text with different glyphs

Closed this issue · 0 comments

Currently, I love the feature in quiz game where the rounded rectangular border surrounds the text inside it.
image

In the quiz game example it is hardcoded as

let line = "─".to_string().as_str().repeat(line_length - 2);
let color = Color::Rgb(9, 183, 238);
AnsiStyledText {
text: format!("╭{}╮", line).as_str(),
style: &[r3bl_ansi_color::Style::Foreground(color)],
}
.println();
let vertical_line = "│".to_string();
let mut score_text = Vec::<String>::new();
score_text.push(vertical_line.clone());
score_text.push(format!(
" End of the game: Your score is {}/{}",
score.to_string(),
all_questions_and_answers.len()
));
let text_length = score_text.join("").len();
let spaces_to_add = line_length - text_length + 1;
score_text.push(" ".to_string().repeat(spaces_to_add));
score_text.push(vertical_line.clone());
AnsiStyledText {
text: score_text.join("").as_str(),
style: &[r3bl_ansi_color::Style::Foreground(color)],
}
.println();
AnsiStyledText {
text: format!("╰{}╯", line).as_str(),
style: &[r3bl_ansi_color::Style::Foreground(color)],
}
.println();

Inside of the tuify we can provide UX APIs directly to users based on which they can select their shapes from what we already serve them. They would just put in string and rest would be taken care.

We can provide

  • Cornered Rectangle
  • Sharp Rectangle
  • Squares
    ... and so on.

The higher level overview of API method should look like
shapeName("Demo Text", ColorScheme) and they can just use one line code from tuify to get their job done.