The README opens on the animated wordmark, says how Luxe is built, and CONTRIBUTING asks contributors to disclose AI help
- The README's wordmark is an animated GIF with a transparent background, rendered from the dashboard's own art and lights, in light and dark variants for GitHub's two themes. - The README says Luxe is built with AI assistance, much of it Luxe working on itself, and CONTRIBUTING has an AI-assistance section: say what helped, understand the change, write to people in your own words. - The redaction table's Google-key example is joined at compile time, so secret scanning stops reading the invented value as a leaked key. - The MCP trust tests read Luxe's own report of what it started, so a slow runner can neither fail them nor pass them falsely.
This commit is contained in:
@@ -54,6 +54,8 @@ clipboard-images = ["clipboard"]
|
||||
# Integration tests link the library without `cfg(test)`; normal dependents keep fixtures off.
|
||||
luxe-tui = { path = ".", features = ["fixture"] }
|
||||
tempfile = "3"
|
||||
# The README's animated wordmark (examples/wordmark_gif). Already in the tree through `image`.
|
||||
gif = "0.14"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -71,6 +73,10 @@ test = true
|
||||
name = "wordmark_svg"
|
||||
test = true
|
||||
|
||||
[[example]]
|
||||
name = "wordmark_gif"
|
||||
test = true
|
||||
|
||||
[[example]]
|
||||
name = "theme_css"
|
||||
test = true
|
||||
|
||||
197
crates/luxe-tui/examples/wordmark_gif.rs
Normal file
197
crates/luxe-tui/examples/wordmark_gif.rs
Normal file
@@ -0,0 +1,197 @@
|
||||
//! wordmark_gif — the logotype as the terminal lights it, as a looping GIF for the README.
|
||||
//!
|
||||
//! Every frame comes from [`Wordmark::lines_at`], the same rows and the same two lights the
|
||||
//! dashboard draws, so the recording cannot drift from the product. GitHub shows a README image on
|
||||
//! its own page background, light or dark, so the background is transparent: the art is hard-edged
|
||||
//! cells, which GIF's one-bit transparency draws exactly.
|
||||
//!
|
||||
//! ```sh
|
||||
//! cargo run -p luxe-tui --example wordmark_gif -- dark > web/src/assets/generated/wordmark-dark.gif
|
||||
//! cargo run -p luxe-tui --example wordmark_gif -- light > web/src/assets/generated/wordmark-light.gif
|
||||
//! ```
|
||||
|
||||
use luxe_tui::main_loop::ANIMATION_TICK;
|
||||
use luxe_tui::widgets::{
|
||||
Wordmark, WordmarkInk, DRIFT_FRAME_TICKS, DRIFT_PERIOD_TICKS, SHINE_CYCLE_TICKS,
|
||||
SHINE_SWEEP_TICKS,
|
||||
};
|
||||
use ratatui::style::Color;
|
||||
use std::borrow::Cow;
|
||||
use std::io::Write;
|
||||
|
||||
/// Pixels per cell: the 10×22 grid `wordmark_svg` draws, twice over so the mark stays sharp on a
|
||||
/// high-density screen when the README shows it at half size.
|
||||
const CELL_W: usize = 20;
|
||||
const CELL_H: usize = 44;
|
||||
|
||||
fn main() {
|
||||
let dark = match std::env::args().nth(1).as_deref() {
|
||||
Some("dark") => true,
|
||||
Some("light") => false,
|
||||
other => {
|
||||
eprintln!("usage: wordmark_gif dark|light (got {other:?})");
|
||||
std::process::exit(2);
|
||||
}
|
||||
};
|
||||
let mut out = Vec::new();
|
||||
write_gif(&mut out, ink(dark)).expect("encoding into memory cannot fail");
|
||||
std::io::stdout().write_all(&out).expect("write the GIF to stdout");
|
||||
}
|
||||
|
||||
/// The luxe theme's accent and canvas. `dark` sets how hard the shine pushes toward white: a light
|
||||
/// page washes the letters out sooner, so it gets the gentler peak the terminal uses on light
|
||||
/// themes. The canvas stays the dark one either way, so the drift deepens the brass on both.
|
||||
fn ink(dark: bool) -> WordmarkInk {
|
||||
let theme = luxe_core::theme::ThemeRegistry::new().resolve("luxe").expect("a built-in theme");
|
||||
let rgb = |token: &str| match theme.get(token) {
|
||||
Some(luxe_core::theme::ColorValue::Rgb(red, green, blue)) => {
|
||||
Color::Rgb(*red, *green, *blue)
|
||||
}
|
||||
other => panic!("the luxe theme's {token} is a color, not {other:?}"),
|
||||
};
|
||||
WordmarkInk { accent: rgb("accent"), canvas: Some(rgb("background")), dark }
|
||||
}
|
||||
|
||||
/// The ticks a frame is drawn at across one loop: every tick while the shine crosses, every drift
|
||||
/// frame while it rests, as the terminal repaints.
|
||||
///
|
||||
/// One loop is one drift period, which has to close on itself for the GIF to loop without a seam.
|
||||
/// The shine crosses once at its start and rests for the remainder.
|
||||
fn frame_ticks() -> Vec<u64> {
|
||||
(0..DRIFT_PERIOD_TICKS)
|
||||
.filter(|&tick| tick < SHINE_SWEEP_TICKS || tick % DRIFT_FRAME_TICKS == 0)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Each frame's delay in hundredths of a second, rounded against the running clock so the loop
|
||||
/// totals the drift period rather than gaining a rounding error per frame.
|
||||
fn delays(ticks: &[u64]) -> Vec<u16> {
|
||||
let tick_ms = ANIMATION_TICK.as_millis() as f64;
|
||||
let at = |tick: u64| (tick as f64 * tick_ms / 10.0).round() as i64;
|
||||
let ends = ticks.iter().skip(1).copied().chain([DRIFT_PERIOD_TICKS]);
|
||||
ticks.iter().zip(ends).map(|(&start, end)| (at(end) - at(start)).max(1) as u16).collect()
|
||||
}
|
||||
|
||||
fn write_gif(out: &mut Vec<u8>, ink: WordmarkInk) -> Result<(), gif::EncodingError> {
|
||||
let size = Wordmark::Full;
|
||||
let (width, height) = (usize::from(size.width()) * CELL_W, usize::from(size.height()) * CELL_H);
|
||||
let mut encoder = gif::Encoder::new(out, width as u16, height as u16, &[])?;
|
||||
encoder.set_repeat(gif::Repeat::Infinite)?;
|
||||
let ticks = frame_ticks();
|
||||
for (&tick, delay) in ticks.iter().zip(delays(&ticks)) {
|
||||
// The shine's own cycle is shorter than the loop; past it the shine rests
|
||||
let shine = (tick < SHINE_CYCLE_TICKS).then_some(tick);
|
||||
let (pixels, palette) = render(size, ink, tick, shine, width);
|
||||
encoder.write_frame(&frame((width, height), pixels, palette, delay))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// One whole-canvas frame, index 0 transparent.
|
||||
fn frame(
|
||||
(width, height): (usize, usize),
|
||||
pixels: Vec<u8>,
|
||||
palette: Vec<u8>,
|
||||
delay: u16,
|
||||
) -> gif::Frame<'static> {
|
||||
gif::Frame {
|
||||
width: width as u16,
|
||||
height: height as u16,
|
||||
buffer: Cow::Owned(pixels),
|
||||
palette: Some(palette),
|
||||
transparent: Some(0),
|
||||
delay,
|
||||
// Cleared between frames, or a cell turned transparent would keep the last frame's ink
|
||||
dispose: gif::DisposalMethod::Background,
|
||||
..gif::Frame::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// One frame as palette indices and the palette, index 0 transparent.
|
||||
fn render(
|
||||
size: Wordmark,
|
||||
ink: WordmarkInk,
|
||||
drift: u64,
|
||||
shine: Option<u64>,
|
||||
width: usize,
|
||||
) -> (Vec<u8>, Vec<u8>) {
|
||||
let mut palette = vec![0u8, 0, 0];
|
||||
let mut pixels = vec![0u8; width * usize::from(size.height()) * CELL_H];
|
||||
for (row, line) in size.lines_at(ink, drift, shine).iter().enumerate() {
|
||||
let cells = line
|
||||
.spans
|
||||
.iter()
|
||||
.flat_map(|span| span.content.chars().map(move |glyph| (glyph, span.style.fg)));
|
||||
for (column, (glyph, fg)) in cells.enumerate() {
|
||||
let Some(Color::Rgb(red, green, blue)) = fg else { continue };
|
||||
let index = palette_index(&mut palette, [red, green, blue]);
|
||||
ink_cell(&mut pixels, width, (column, row), glyph, index);
|
||||
}
|
||||
}
|
||||
(pixels, palette)
|
||||
}
|
||||
|
||||
/// Paints the part of cell `(column, row)` that `glyph` inks: all of it, or the top or bottom half.
|
||||
fn ink_cell(
|
||||
pixels: &mut [u8],
|
||||
width: usize,
|
||||
(column, row): (usize, usize),
|
||||
glyph: char,
|
||||
index: u8,
|
||||
) {
|
||||
let (top, bottom) = match glyph {
|
||||
'█' => (0, CELL_H),
|
||||
'▀' => (0, CELL_H / 2),
|
||||
'▄' => (CELL_H / 2, CELL_H),
|
||||
_ => return,
|
||||
};
|
||||
for y in row * CELL_H + top..row * CELL_H + bottom {
|
||||
pixels[y * width + column * CELL_W..][..CELL_W].fill(index);
|
||||
}
|
||||
}
|
||||
|
||||
/// The palette slot for `color`, adding it the first time it is seen.
|
||||
fn palette_index(palette: &mut Vec<u8>, color: [u8; 3]) -> u8 {
|
||||
let existing = palette.chunks(3).position(|entry| entry == color);
|
||||
let index = existing.unwrap_or_else(|| {
|
||||
palette.extend_from_slice(&color);
|
||||
palette.len() / 3 - 1
|
||||
});
|
||||
u8::try_from(index).expect("a frame of one hue lit two ways stays far under 256 colors")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// The loop is one drift period to the hundredth of a second, so it closes without a jump.
|
||||
#[test]
|
||||
fn the_frames_add_up_to_one_drift_period() {
|
||||
let total: u32 = delays(&frame_ticks()).iter().map(|&delay| u32::from(delay)).sum();
|
||||
let period_cs =
|
||||
(DRIFT_PERIOD_TICKS as f64 * ANIMATION_TICK.as_millis() as f64 / 10.0).round();
|
||||
assert_eq!(f64::from(total), period_cs);
|
||||
}
|
||||
|
||||
/// The shine crosses frame by frame, and the rest repaints at the drift's slower cadence.
|
||||
#[test]
|
||||
fn the_shine_gets_every_tick_and_the_rest_every_drift_frame() {
|
||||
let ticks = frame_ticks();
|
||||
assert!((0..SHINE_SWEEP_TICKS).all(|tick| ticks.contains(&tick)));
|
||||
assert!(ticks
|
||||
.iter()
|
||||
.filter(|&&tick| tick >= SHINE_SWEEP_TICKS)
|
||||
.all(|tick| tick % DRIFT_FRAME_TICKS == 0));
|
||||
}
|
||||
|
||||
/// The background is transparent and the letters are ink: a frame has both.
|
||||
#[test]
|
||||
fn a_frame_is_transparent_around_inked_letters() {
|
||||
let size = Wordmark::Full;
|
||||
let width = usize::from(size.width()) * CELL_W;
|
||||
let (pixels, palette) = render(size, ink(true), 0, None, width);
|
||||
assert!(pixels.contains(&0), "transparent background");
|
||||
assert!(pixels.iter().any(|&index| index != 0), "inked letters");
|
||||
assert!(palette.len() / 3 > 1);
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,11 @@ use std::time::Duration;
|
||||
use tokio::sync::mpsc;
|
||||
use tokio::time::interval;
|
||||
|
||||
/// The animation tick, about 30 a second: what every timed effect counts in, the wordmark's lights
|
||||
/// and the spinner included. Public so a recording of one, the README's wordmark, keeps the same
|
||||
/// time.
|
||||
pub const ANIMATION_TICK: Duration = Duration::from_millis(33);
|
||||
|
||||
/// Why the TUI returned control to the CLI.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum TuiExit {
|
||||
@@ -181,7 +186,7 @@ pub async fn run(
|
||||
let mut sources = Sources {
|
||||
event_rx,
|
||||
terminal_events: Some(EventStream::new()),
|
||||
tick: interval(Duration::from_millis(33)), // ~30fps
|
||||
tick: interval(ANIMATION_TICK),
|
||||
// One listener for the run, rather than a fresh registration on every pass of a loop that
|
||||
// turns over as fast as the terminal can deliver keys.
|
||||
interrupted: Box::pin(tokio::signal::ctrl_c()),
|
||||
|
||||
@@ -34,7 +34,8 @@ pub use slab::{
|
||||
pub use tool_glyph::{tool_glyph, tool_icon, GENERIC_TOOL};
|
||||
pub use wordmark::{
|
||||
banner_frame_due, render_wordmark, smoothstep, BannerClock, Wordmark, WordmarkInk, BAND,
|
||||
DRIFT_DEPTH, LEAN, PEAK_DARK, PEAK_LIGHT, SHINE_CYCLE_TICKS, SHINE_SWEEP_TICKS, STILL_TICK,
|
||||
DRIFT_DEPTH, DRIFT_FRAME_TICKS, DRIFT_PERIOD_TICKS, LEAN, PEAK_DARK, PEAK_LIGHT,
|
||||
SHINE_CYCLE_TICKS, SHINE_SWEEP_TICKS, STILL_TICK,
|
||||
};
|
||||
pub use wrap::{wrap_cells, wrap_line, wrap_lines, wrapped_row_starts};
|
||||
|
||||
|
||||
@@ -23,8 +23,11 @@
|
||||
//! wordmark in the flat accent and skip both rather than approximate them.
|
||||
|
||||
mod art;
|
||||
mod light;
|
||||
|
||||
use art::{column_groups, FULL_ART, LINE_ART, SMALL_ART};
|
||||
pub use light::smoothstep;
|
||||
use light::{blend_toward, Pass};
|
||||
use ratatui::layout::{Alignment, Rect};
|
||||
use ratatui::style::{Color, Modifier, Style};
|
||||
use ratatui::text::{Line, Span};
|
||||
@@ -194,14 +197,23 @@ impl Wordmark {
|
||||
/// A still is a frame of the same animation rather than a separate code path, so what a reader
|
||||
/// sees with `banner_animation = false` is a moment of what everyone else sees moving.
|
||||
pub fn lines(self, ink: WordmarkInk, tick: Option<u64>) -> Vec<Line<'static>> {
|
||||
let (tick, pass) = match tick {
|
||||
Some(tick) => (tick, Pass::at(self, ink, tick)),
|
||||
None => (STILL_TICK, None),
|
||||
};
|
||||
match tick {
|
||||
Some(tick) => self.lines_at(ink, tick, Some(tick)),
|
||||
None => self.lines_at(ink, STILL_TICK, None),
|
||||
}
|
||||
}
|
||||
|
||||
/// The logotype's rows with each light set on its own: the drift at `drift`, and the shine at
|
||||
/// `shine`, or none when that is `None`.
|
||||
///
|
||||
/// The terminal runs both from one clock and keeps them out of step on purpose, so its pattern
|
||||
/// takes minutes to repeat. A recording has to loop, so it sets the two to meet.
|
||||
pub fn lines_at(self, ink: WordmarkInk, drift: u64, shine: Option<u64>) -> Vec<Line<'static>> {
|
||||
let pass = shine.and_then(|tick| Pass::at(self, ink, tick));
|
||||
self.rows()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(row, text)| self.row_line(text, row as u16, ink, tick, pass.as_ref()))
|
||||
.map(|(row, text)| self.row_line(text, row as u16, ink, drift, pass.as_ref()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -412,78 +424,13 @@ pub fn render_wordmark(
|
||||
pub const SHINE_SWEEP_TICKS: u64 = SWEEP_TICKS;
|
||||
/// One pass plus its rest, in ticks.
|
||||
pub const SHINE_CYCLE_TICKS: u64 = CYCLE_TICKS;
|
||||
/// One whole pass of the drift, in ticks.
|
||||
pub const DRIFT_PERIOD_TICKS: u64 = DRIFT_TICKS;
|
||||
/// Ticks between drift frames while no shine runs.
|
||||
pub const DRIFT_FRAME_TICKS: u64 = DRIFT_FRAME;
|
||||
|
||||
fn shine_active(tick: u64) -> bool {
|
||||
tick % CYCLE_TICKS < SWEEP_TICKS
|
||||
}
|
||||
|
||||
/// One tick of one pass: where the highlight band sits, and how hard it pushes.
|
||||
struct Pass {
|
||||
center: f32,
|
||||
half: f32,
|
||||
peak: f32,
|
||||
lean: f32,
|
||||
}
|
||||
|
||||
impl Pass {
|
||||
/// The pass in flight at `tick`, or `None` while the logotype rests.
|
||||
fn at(size: Wordmark, ink: WordmarkInk, tick: u64) -> Option<Self> {
|
||||
let phase = tick % CYCLE_TICKS;
|
||||
if phase >= SWEEP_TICKS {
|
||||
return None;
|
||||
}
|
||||
let span = size.span();
|
||||
let half = (span * BAND).max(1.0);
|
||||
let travel = span + 2.0 * half;
|
||||
let progress = phase as f32 / SWEEP_TICKS as f32;
|
||||
|
||||
Some(Self {
|
||||
// The band starts and ends clear of the letters, so a pass arrives and leaves rather
|
||||
// than appearing half-drawn across them.
|
||||
center: -half + progress * travel,
|
||||
half,
|
||||
peak: if ink.dark { PEAK_DARK } else { PEAK_LIGHT },
|
||||
lean: LEAN,
|
||||
})
|
||||
}
|
||||
|
||||
/// How far this cell is lifted toward the highlight.
|
||||
fn lift(&self, column: u16, row: u16) -> f32 {
|
||||
let axis = f32::from(column) + self.lean * f32::from(row);
|
||||
let distance = ((axis - self.center).abs() / self.half).min(1.0);
|
||||
smoothstep(1.0 - distance) * self.peak
|
||||
}
|
||||
}
|
||||
|
||||
/// Smooth 0→1 with zero slope at both ends, so a band edge has no seam.
|
||||
///
|
||||
/// The shape of the highlight, and the whole reason it reads as light rather than as a stripe: a
|
||||
/// linear falloff leaves a crease along the ridge and a hard shoulder at each edge. Public so the
|
||||
/// website samples this curve rather than approximating it.
|
||||
pub fn smoothstep(t: f32) -> f32 {
|
||||
let t = t.clamp(0.0, 1.0);
|
||||
t * t * (3.0 - 2.0 * t)
|
||||
}
|
||||
|
||||
/// Alpha-blend `base` `amount` of the way toward `target`.
|
||||
///
|
||||
/// An ANSI/indexed palette has no channels to mix, so an unblendable color comes back untouched
|
||||
/// rather than as an invented RGB approximation of the terminal's own.
|
||||
fn blend_toward(base: Color, target: Color, amount: f32) -> Color {
|
||||
let (Color::Rgb(red, green, blue), Color::Rgb(tr, tg, tb)) = (base, target) else {
|
||||
return base;
|
||||
};
|
||||
if amount <= 0.0 {
|
||||
return base;
|
||||
}
|
||||
let amount = amount.clamp(0.0, 1.0);
|
||||
let lift = |channel: u8, toward: u8| {
|
||||
(f32::from(channel) + (f32::from(toward) - f32::from(channel)) * amount)
|
||||
.round()
|
||||
.clamp(0.0, 255.0) as u8
|
||||
};
|
||||
Color::Rgb(lift(red, tr), lift(green, tg), lift(blue, tb))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
75
crates/luxe-tui/src/widgets/wordmark/light.rs
Normal file
75
crates/luxe-tui/src/widgets/wordmark/light.rs
Normal file
@@ -0,0 +1,75 @@
|
||||
//! Light — the shine's band, the curve it falls off along, and the blend both lights paint with.
|
||||
//!
|
||||
//! The math of the two lights on their own, apart from the art they land on: the parent decides
|
||||
//! which cells are ink and asks here how far each one is lifted.
|
||||
|
||||
use super::{Wordmark, WordmarkInk, BAND, CYCLE_TICKS, LEAN, PEAK_DARK, PEAK_LIGHT, SWEEP_TICKS};
|
||||
use ratatui::style::Color;
|
||||
|
||||
/// One tick of one pass: where the highlight band sits, and how hard it pushes.
|
||||
pub(super) struct Pass {
|
||||
center: f32,
|
||||
half: f32,
|
||||
peak: f32,
|
||||
lean: f32,
|
||||
}
|
||||
|
||||
impl Pass {
|
||||
/// The pass in flight at `tick`, or `None` while the logotype rests.
|
||||
pub(super) fn at(size: Wordmark, ink: WordmarkInk, tick: u64) -> Option<Self> {
|
||||
let phase = tick % CYCLE_TICKS;
|
||||
if phase >= SWEEP_TICKS {
|
||||
return None;
|
||||
}
|
||||
let span = size.span();
|
||||
let half = (span * BAND).max(1.0);
|
||||
let travel = span + 2.0 * half;
|
||||
let progress = phase as f32 / SWEEP_TICKS as f32;
|
||||
|
||||
Some(Self {
|
||||
// The band starts and ends clear of the letters, so a pass arrives and leaves rather
|
||||
// than appearing half-drawn across them.
|
||||
center: -half + progress * travel,
|
||||
half,
|
||||
peak: if ink.dark { PEAK_DARK } else { PEAK_LIGHT },
|
||||
lean: LEAN,
|
||||
})
|
||||
}
|
||||
|
||||
/// How far this cell is lifted toward the highlight.
|
||||
pub(super) fn lift(&self, column: u16, row: u16) -> f32 {
|
||||
let axis = f32::from(column) + self.lean * f32::from(row);
|
||||
let distance = ((axis - self.center).abs() / self.half).min(1.0);
|
||||
smoothstep(1.0 - distance) * self.peak
|
||||
}
|
||||
}
|
||||
|
||||
/// Smooth 0→1 with zero slope at both ends, so a band edge has no seam.
|
||||
///
|
||||
/// The shape of the highlight, and the whole reason it reads as light rather than as a stripe: a
|
||||
/// linear falloff leaves a crease along the ridge and a hard shoulder at each edge. Public so the
|
||||
/// website samples this curve rather than approximating it.
|
||||
pub fn smoothstep(t: f32) -> f32 {
|
||||
let t = t.clamp(0.0, 1.0);
|
||||
t * t * (3.0 - 2.0 * t)
|
||||
}
|
||||
|
||||
/// Alpha-blend `base` `amount` of the way toward `target`.
|
||||
///
|
||||
/// An ANSI/indexed palette has no channels to mix, so an unblendable color comes back untouched
|
||||
/// rather than as an invented RGB approximation of the terminal's own.
|
||||
pub(super) fn blend_toward(base: Color, target: Color, amount: f32) -> Color {
|
||||
let (Color::Rgb(red, green, blue), Color::Rgb(tr, tg, tb)) = (base, target) else {
|
||||
return base;
|
||||
};
|
||||
if amount <= 0.0 {
|
||||
return base;
|
||||
}
|
||||
let amount = amount.clamp(0.0, 1.0);
|
||||
let lift = |channel: u8, toward: u8| {
|
||||
(f32::from(channel) + (f32::from(toward) - f32::from(channel)) * amount)
|
||||
.round()
|
||||
.clamp(0.0, 255.0) as u8
|
||||
};
|
||||
Color::Rgb(lift(red, tr), lift(green, tg), lift(blue, tb))
|
||||
}
|
||||
Reference in New Issue
Block a user