Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: more tweaks based on PR comments
#500 (review) - add comments - remove dead code (in colors and weather) - make RGB swatch into a widget - simplify the RGB logic in the swatch / weather gauge - move layout() helper function to root module - remove unused keyboard bindings - remove unused imports in theme - remove unused lipsum crate - turn on doc scraping
- Loading branch information
Showing
12 changed files
with
75 additions
and
119 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,34 @@ | ||
use palette::{ | ||
convert::{FromColorUnclamped, IntoColorUnclamped}, | ||
Okhsv, Srgb, | ||
}; | ||
use palette::{IntoColor, Okhsv, Srgb}; | ||
use ratatui::{prelude::*, widgets::*}; | ||
|
||
#[allow(dead_code)] | ||
fn render_16_color_swatch(area: Rect, buf: &mut Buffer) { | ||
let sym = "██"; | ||
Paragraph::new(vec![ | ||
Line::from(vec![sym.black(), sym.red(), sym.green(), sym.yellow()]), | ||
Line::from(vec![sym.blue(), sym.magenta(), sym.cyan(), sym.gray()]), | ||
Line::from(vec![ | ||
sym.dark_gray(), | ||
sym.light_red(), | ||
sym.light_green(), | ||
sym.light_yellow(), | ||
]), | ||
Line::from(vec![ | ||
sym.light_blue(), | ||
sym.light_magenta(), | ||
sym.light_cyan(), | ||
sym.white(), | ||
]), | ||
]) | ||
.render(area, buf); | ||
} | ||
/// A widget that renders a color swatch of RGB colors. | ||
/// | ||
/// The widget is rendered as a rectangle with the hue changing along the x-axis from 0.0 to 360.0 | ||
/// and the value changing along the y-axis (from 1.0 to 0.0). Each pixel is rendered as a block | ||
/// character with the top half slightly lighter than the bottom half. | ||
pub struct RgbSwatch; | ||
|
||
#[allow(dead_code)] | ||
fn render_256_color_swatch(area: Rect, buf: &mut Buffer) { | ||
for (xi, x) in (16..52).zip(area.left()..area.right()) { | ||
for (yi, y) in (0..3).zip(area.top()..area.bottom()) { | ||
let fg = Color::Indexed(yi * 72 + xi); | ||
let bg = Color::Indexed(yi * 72 + xi + 36); | ||
buf.get_mut(x, y).set_char('▀').set_fg(fg).set_bg(bg); | ||
impl Widget for RgbSwatch { | ||
fn render(self, area: Rect, buf: &mut Buffer) { | ||
for (yi, y) in (area.top()..area.bottom()).enumerate() { | ||
let value = area.height as f32 - yi as f32; | ||
let value_fg = value / (area.height as f32); | ||
let value_bg = (value - 0.5) / (area.height as f32); | ||
for (xi, x) in (area.left()..area.right()).enumerate() { | ||
let hue = xi as f32 * 360.0 / area.width as f32; | ||
let fg = color_from_oklab(hue, Okhsv::max_saturation(), value_fg); | ||
let bg = color_from_oklab(hue, Okhsv::max_saturation(), value_bg); | ||
buf.get_mut(x, y).set_char('▀').set_fg(fg).set_bg(bg); | ||
} | ||
} | ||
let fg = Color::Indexed(xi.saturating_add(216)); | ||
buf.get_mut(x, area.bottom() - 1).set_char('█').set_fg(fg); | ||
} | ||
} | ||
|
||
pub fn render_rgb_swatch(area: Rect, buf: &mut Buffer) { | ||
for (xi, x) in (area.left()..area.right()).enumerate() { | ||
for (yi, y) in (area.top()..area.bottom()).enumerate() { | ||
let yi = area.height as usize - yi - 1; | ||
let hue = xi as f32 * 360.0 / area.width as f32; | ||
let value_bg = (yi as f32 - 0.0) / (area.height as f32); | ||
let value_fg = (yi as f32 + 0.5) / (area.height as f32); | ||
let fg = Okhsv::<f32>::new(hue, Okhsv::max_saturation(), value_fg); | ||
let fg: Srgb<f32> = fg.into_color_unclamped(); | ||
let fg: Srgb<u8> = fg.into_format(); | ||
let fg = Color::Rgb(fg.red, fg.green, fg.blue); | ||
let bg = Okhsv::new(hue, Okhsv::max_saturation(), value_bg); | ||
let bg = Srgb::<f32>::from_color_unclamped(bg); | ||
let bg: Srgb<u8> = bg.into_format(); | ||
let bg = Color::Rgb(bg.red, bg.green, bg.blue); | ||
buf.get_mut(x, y).set_char('▀').set_fg(fg).set_bg(bg); | ||
} | ||
} | ||
/// Convert a hue and value into an RGB color via the OkLab color space. | ||
/// | ||
/// See https://bottosson.github.io/posts/oklab/ for more details. | ||
pub fn color_from_oklab(hue: f32, saturation: f32, value: f32) -> Color { | ||
let color: Srgb = Okhsv::new(hue, saturation, value).into_color(); | ||
let color = color.into_format(); | ||
Color::Rgb(color.red, color.green, color.blue) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use anyhow::Result; | ||
pub use app::*; | ||
pub use colors::*; | ||
pub use root::*; | ||
pub use term::*; | ||
pub use theme::*; | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#![allow(unused)] | ||
use palette::{named::LIGHTGRAY, white_point::B}; | ||
use ratatui::prelude::*; | ||
|
||
pub struct Theme { | ||
|