-
-
Notifications
You must be signed in to change notification settings - Fork 39
feat(extras): create mousefood-extras #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
893d893
960968b
39c24a6
7dd0259
fc05527
1747b1c
1414678
4bd2567
7dd5eac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,20 @@ | ||||||
| [package] | ||||||
| name = "mousefood-extras" | ||||||
| # TODO: | ||||||
| # description = "???" | ||||||
| version = "0.1.0" | ||||||
| edition.workspace = true | ||||||
| rust-version.workspace = true | ||||||
| license.workspace = true | ||||||
| homepage.workspace = true | ||||||
| repository.workspace = true | ||||||
|
|
||||||
| # TODO: these fields?? | ||||||
| # keywords = ["embedded-graphics", "ratatui", "tui"] | ||||||
| # categories = ["embedded"] | ||||||
| # exclude = ["/.github", "/assets"] | ||||||
|
||||||
| keywords = ["mousefood", "ratatui", "tui"] | |
| categories = ["no-std", "graphics"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // TODO: should this be here? even for `std` builds? | ||
| #![no_std] | ||
sermuns marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| mod logo; | ||
| pub use logo::MouseFoodLogo; | ||
sermuns marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| use itertools::Itertools; | ||
| use ratatui_core::buffer::Buffer; | ||
| use ratatui_core::layout::Rect; | ||
| use ratatui_core::style::Color; | ||
| use ratatui_core::widgets::Widget; | ||
|
|
||
| const MOUSEFOOD_LOGO: &str = indoc::indoc! {" | ||
| abccccccc | ||
| dddd ddd d d ddddd ddeebbbbbbbacc | ||
| d d d d d d d d d babbbcaaccc | ||
| d d d d d d d ddddd eee abbbbabccc | ||
| d d d d d d d e e bbabbbbbbccc | ||
| d d d ddd ddd deeee eebbbbbbbbbcccc | ||
| bbbcabbbbcccbcc | ||
| ddddd ddd ddd eeee bbbcaabbbccccbac | ||
| d d d d e e e bbbbabbbbccccccc | ||
| ddd d d e e e ebaabbbcaacccbcccc | ||
| d d e e e e e abbbbbabcccbcc | ||
| d dde eeeb eeee aabbbbbcbccabc | ||
| abc b bbbbccacccc | ||
| "}; | ||
|
|
||
| const EMPTY: char = ' '; | ||
| const LIGHT_TEXT: char = 'd'; | ||
| const DARK_TEXT: char = 'e'; | ||
| const LIGHT_CHEESE: char = 'c'; | ||
| const MIDDLE_CHEESE: char = 'b'; | ||
| const DARK_CHEESE: char = 'a'; | ||
| const TERM: char = '░'; | ||
| const TERM_BORDER: char = '▒'; | ||
| const TERM_CURSOR: char = '▓'; | ||
|
|
||
| #[derive(Default)] | ||
| pub struct MouseFoodLogo {} | ||
sermuns marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| impl MouseFoodLogo { | ||
| pub fn new() -> Self { | ||
| Self::default() | ||
| } | ||
|
|
||
| const fn color_for(&self, c: char) -> Option<Color> { | ||
| match c { | ||
| LIGHT_TEXT => Some(Color::Rgb(139, 151, 182)), | ||
| DARK_TEXT => Some(Color::Rgb(53, 54, 88)), | ||
| LIGHT_CHEESE => Some(Color::Rgb(236, 233, 16)), | ||
| MIDDLE_CHEESE => Some(Color::Rgb(236, 171, 17)), | ||
| DARK_CHEESE => Some(Color::Rgb(239, 110, 16)), | ||
| TERM => Some(Color::Indexed(232)), | ||
| TERM_BORDER => Some(Color::Indexed(237)), | ||
| TERM_CURSOR => Some(Color::Indexed(248)), | ||
sermuns marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _ => None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Widget for MouseFoodLogo { | ||
| fn render(self, area: Rect, buf: &mut Buffer) { | ||
| let area = area.intersection(buf.area); | ||
| if area.is_empty() { | ||
| return; | ||
| } | ||
|
|
||
| for (y, (line1, line2)) in MOUSEFOOD_LOGO.lines().tuples().enumerate() { | ||
| for (x, (ch1, ch2)) in line1.chars().zip(line2.chars()).enumerate() { | ||
| let x = area.left() + x as u16; | ||
| let y = area.top() + y as u16; | ||
|
|
||
| // Check if coordinates are within the buffer area | ||
| if x >= area.right() || y >= area.bottom() { | ||
| continue; | ||
| } | ||
|
|
||
| let cell = &mut buf[(x, y)]; | ||
| // given two cells which make up the top and bottom of the character, | ||
| // Foreground color should be the non-space, non-terminal | ||
| let (fg, bg) = match (ch1, ch2) { | ||
| (EMPTY, EMPTY) => (None, None), | ||
| (c, EMPTY) | (EMPTY, c) => (self.color_for(c), None), | ||
| (TERM, TERM_BORDER) => (self.color_for(TERM_BORDER), self.color_for(TERM)), | ||
| (TERM, c) | (c, TERM) => (self.color_for(c), self.color_for(TERM)), | ||
| (c1, c2) => (self.color_for(c1), self.color_for(c2)), | ||
| }; | ||
| // symbol should make the empty space or terminal bg as the empty part of the block | ||
| let symbol = match (ch1, ch2) { | ||
| (EMPTY, EMPTY) => None, | ||
| (TERM, TERM) => Some(EMPTY), | ||
| (_, EMPTY | TERM) => Some('▀'), | ||
| (EMPTY | TERM, _) => Some('▄'), | ||
| (c, d) if c == d => Some('█'), | ||
| (_, _) => Some('▀'), | ||
| }; | ||
| if let Some(fg) = fg { | ||
| cell.fg = fg; | ||
| } | ||
| if let Some(bg) = bg { | ||
| cell.bg = bg; | ||
| } | ||
| if let Some(symb) = symbol { | ||
| cell.set_char(symb); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to
mousefood/mousefood-extras/Cargo.toml
Line 3 in 960968b