luxe 0.1.4: remembered models, wheel-driven lists, and a steadier phone app

- luxe starts on the model you last chose in this project, then the last one anywhere. Signing in
  opens the model picker instead of choosing for you.
- Every list in a modal takes the mouse wheel and a draggable scrollbar.
- The phone app shows reasoning in full, stays put while you read back through a long session, and
  shows a question's answer on its card.
- On Windows, luxe update replaces the running luxe, and a signed-in install no longer sees setup
  again.
- The file tree no longer shows "engine busy" in a large project, loop output is easier to follow,
  and the name is written lowercase.

The CHANGELOG has the full list.
This commit is contained in:
Evan Whittaker
2026-10-20 13:51:34 -05:00
parent 6184aa21fb
commit a0666d6c81
591 changed files with 4926 additions and 2942 deletions

View File

@@ -0,0 +1,193 @@
//! Paint — how a loop line looks: the guides that lead it, and its colors when there are any.
//!
//! The guides work like an editor's indent guides. A phase draws a heavy rail down the left, in
//! a color of its own; an iteration draws a light one inside it, opened with `┌` and closed with
//! `└`. Scrolled back through a long run, or seen in a minimap, each phase is a band of one color
//! and each iteration a bracket within it. Colors come from the terminal's own sixteen, so its
//! theme picks the shades, and the guides are plain characters, so a log without color keeps them.
use crossterm::style::{Color, Stylize};
/// Phase rail colors, cycled by phase number so two neighboring phases never share one.
const PHASE_COLORS: [Color; 4] = [Color::Cyan, Color::Magenta, Color::Blue, Color::Yellow];
/// Where a line sits in the run, which decides the guides leading it.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub(super) enum Depth {
/// Before the run has a phase
Run,
/// Inside a phase, between iterations
Phase(u32),
/// Inside an iteration of a phase.
///
/// Args: the phase, and which edge of the iteration the line is.
Iteration(u32, Edge),
}
/// Which part of an iteration a line is: its opening, its body, or its closing line.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub(super) enum Edge {
/// `┌`, the iteration's first line
Open,
/// `│`, every line between
Within,
/// `└`, the turn's summary
Close,
}
/// How a tool call has gone so far.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub(super) enum CallState {
/// Started, no result yet
Running,
/// Ended without an error
Succeeded,
/// Ended in an error
Failed,
}
/// Draws loop lines, in color or not.
#[derive(Clone, Copy, Debug)]
pub(super) struct Paint {
color: bool,
}
impl Paint {
/// Color when stdout is a terminal that wants it: not `NO_COLOR`, not `TERM=dumb`.
pub(super) fn detect() -> Self {
use std::io::IsTerminal;
let no_color = std::env::var_os("NO_COLOR").is_some_and(|value| !value.is_empty());
let dumb = std::env::var("TERM").is_ok_and(|term| term == "dumb");
Self { color: std::io::stdout().is_terminal() && !no_color && !dumb }
}
/// No color at all, as a pipe or a log gets.
#[cfg(test)]
pub(super) fn plain() -> Self {
Self { color: false }
}
/// Whether this paints in color.
pub(super) fn in_color(self) -> bool {
self.color
}
/// The guides for a line at `depth`, each followed by a space.
pub(super) fn guides(self, depth: Depth) -> String {
match depth {
Depth::Run => String::new(),
Depth::Phase(phase) => format!("{} ", self.rail(phase)),
Depth::Iteration(phase, edge) => {
format!("{} {} ", self.rail(phase), self.dim(edge_glyph(edge)))
}
}
}
/// The line that opens a phase: its number in the phase's color.
pub(super) fn phase_heading(self, phase: u32) -> String {
let text = format!("phase {phase}");
match self.color {
true => text.with(phase_color(phase)).bold().to_string(),
false => text,
}
}
/// A tool call: a mark and the tool's name colored by how it went, then what it was asked.
/// A failure says so in words too, so the color never carries it alone.
pub(super) fn tool(self, name: &str, label: &str, state: CallState) -> String {
let (mark, color) = match state {
CallState::Running => ("○", None),
CallState::Succeeded => ("✓", Some(Color::Green)),
CallState::Failed => ("✗", Some(Color::Red)),
};
let head = format!("{mark} {name}");
let head = match (self.color, color) {
(true, Some(color)) => head.with(color).bold().to_string(),
(true, None) => head.bold().to_string(),
(false, _) => head,
};
let failed = match state {
CallState::Failed => format!(" · {}", self.colored("failed", Color::Red)),
_ => String::new(),
};
format!("{head} {label}").trim_end().to_string() + &failed
}
/// Secondary text: a turn's summary, the iteration rail.
pub(super) fn dim(self, text: &str) -> String {
match self.color {
true => text.dim().to_string(),
false => text.to_string(),
}
}
fn colored(self, text: &str, color: Color) -> String {
match self.color {
true => text.with(color).to_string(),
false => text.to_string(),
}
}
fn rail(self, phase: u32) -> String {
self.colored("┃", phase_color(phase))
}
}
fn phase_color(phase: u32) -> Color {
PHASE_COLORS[phase as usize % PHASE_COLORS.len()]
}
fn edge_glyph(edge: Edge) -> &'static str {
match edge {
Edge::Open => "┌",
Edge::Within => "│",
Edge::Close => "└",
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn each_depth_draws_its_own_guides() {
let paint = Paint::plain();
assert_eq!(paint.guides(Depth::Run), "");
assert_eq!(paint.guides(Depth::Phase(2)), "┃ ");
assert_eq!(paint.guides(Depth::Iteration(2, Edge::Open)), "┃ ┌ ");
assert_eq!(paint.guides(Depth::Iteration(2, Edge::Within)), "┃ │ ");
assert_eq!(paint.guides(Depth::Iteration(2, Edge::Close)), "┃ └ ");
}
/// Without color a failure still reads as one, and a success has no word to need.
#[test]
fn a_failed_call_says_so_in_words() {
let paint = Paint::plain();
assert_eq!(paint.tool("read", "a.rs", CallState::Running), "○ read a.rs");
assert_eq!(paint.tool("read", "a.rs", CallState::Succeeded), "✓ read a.rs");
assert_eq!(
paint.tool("bash", "cargo test", CallState::Failed),
"✗ bash cargo test · failed"
);
assert_eq!(paint.tool("todo", "", CallState::Succeeded), "✓ todo", "no trailing space");
}
/// The tool's name takes the result's color; a plain view has no escapes at all.
#[test]
fn the_name_is_colored_by_the_result() {
let paint = Paint { color: true };
let ok = paint.tool("read", "a.rs", CallState::Succeeded);
let failed = paint.tool("read", "a.rs", CallState::Failed);
assert!(ok.contains(&"✓ read".with(Color::Green).bold().to_string()), "{ok:?}");
assert!(failed.contains(&"✗ read".with(Color::Red).bold().to_string()), "{failed:?}");
assert!(!Paint::plain().tool("read", "a.rs", CallState::Failed).contains('\x1b'));
}
/// Neighboring phases never share a rail color, so a phase boundary shows in a minimap.
#[test]
fn neighboring_phases_differ() {
for phase in 0..8 {
assert_ne!(phase_color(phase), phase_color(phase + 1), "{phase}");
}
}
}

View File

@@ -0,0 +1,177 @@
//! Screen — where loop lines go, and taking one back to redraw it.
//!
//! A tool call is printed when it starts, because "is it still going?" is the first question about
//! an unattended run, and its result only exists once it ends. On a terminal the start line is
//! redrawn in place with the result. That's only safe when every line is exactly one row, so on a
//! terminal each line is cut to the width rather than left to wrap, and a resize since the line
//! was printed means it's left alone. A pipe or a file never gets a redraw.
use crate::output::{out, outln};
use unicode_width::UnicodeWidthChar;
/// A line already printed, and what's needed to find it again.
#[derive(Clone, Copy, Debug)]
pub(super) struct Printed {
/// How many lines came before it
index: u64,
/// The terminal's width when it was printed
width: Option<u16>,
}
/// The terminal or pipe the view prints to.
pub(super) struct Screen {
/// Whether lines may be cut to the width and redrawn
terminal: bool,
/// Lines printed so far
printed: u64,
/// Where a test's lines go instead of stdout
recorded: Option<Vec<String>>,
}
impl Screen {
/// A terminal when stdout is one.
pub(super) fn detect() -> Self {
use std::io::IsTerminal;
Self { terminal: std::io::stdout().is_terminal(), printed: 0, recorded: None }
}
/// A pipe that keeps its lines for a test to read.
#[cfg(test)]
pub(super) fn recording() -> Self {
Self { terminal: false, printed: 0, recorded: Some(Vec::new()) }
}
/// What a [`Screen::recording`] was given.
#[cfg(test)]
pub(super) fn lines(&self) -> &[String] {
self.recorded.as_deref().unwrap_or_default()
}
/// Prints `line` as one row, and says where it went.
pub(super) fn print(&mut self, line: &str) -> Printed {
let width = self.width();
let printed = Printed { index: self.printed, width };
self.printed += 1;
if let Some(recorded) = &mut self.recorded {
recorded.push(line.to_string());
return printed;
}
match width {
Some(cells) => outln!("{}", fit(line, usize::from(cells))),
None => outln!("{line}"),
}
printed
}
/// Redraws an earlier line in place. False, and nothing written, when it can't be trusted to
/// land on the same row: not a terminal, a resize since, or scrolled past the top.
pub(super) fn rewrite(&mut self, at: Printed, line: &str) -> bool {
let Some(cells) = self.width().filter(|now| Some(*now) == at.width) else { return false };
let up = self.printed - at.index;
let rows = crossterm::terminal::size().map_or(0, |(_, rows)| u64::from(rows));
if up == 0 || up >= rows {
return false;
}
// Up to the line, clear it, draw, then back down to where the next line goes
out!("\x1b[{up}A\r\x1b[2K{}\x1b[{up}B\r", fit(line, usize::from(cells)));
true
}
fn width(&self) -> Option<u16> {
match self.terminal {
true => crossterm::terminal::size().ok().map(|(cols, _)| cols),
false => None,
}
}
}
/// `line` cut to fit in `width` cells, so it never wraps. Escape sequences pass through uncounted,
/// and a cut line ends in `…` and, if it had color, a reset.
pub(super) fn fit(line: &str, width: usize) -> String {
if visible_width(line) <= width {
return line.to_string();
}
let (cut, _) = scan(line, width.saturating_sub(1));
let reset = if line.contains('\x1b') { "\x1b[0m" } else { "" };
format!("{cut}…{reset}")
}
/// Where the scanner is: in text, just past an escape, or inside a `CSI` sequence.
#[derive(Clone, Copy)]
enum Scan {
Text,
Escape,
Csi,
}
/// `line` up to `budget` visible cells, with every escape sequence kept, and the cells it used.
fn scan(line: &str, budget: usize) -> (String, usize) {
let mut kept = String::with_capacity(line.len());
let mut used = 0;
let mut state = Scan::Text;
for ch in line.chars() {
state = match (state, ch) {
(Scan::Text, '\x1b') => Scan::Escape,
(Scan::Escape, '[') => Scan::Csi,
(Scan::Escape, _) => Scan::Text,
(Scan::Csi, '@'..='~') => Scan::Text,
(Scan::Csi, _) => Scan::Csi,
(Scan::Text, text) => {
let cells = text.width().unwrap_or(0);
if used + cells > budget {
break;
}
used += cells;
Scan::Text
}
};
kept.push(ch);
}
(kept, used)
}
fn visible_width(line: &str) -> usize {
scan(line, usize::MAX).1
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_line_that_fits_is_left_alone() {
assert_eq!(fit("○ read a.rs", 40), "○ read a.rs");
assert_eq!(fit("exactly", 7), "exactly");
}
/// One cell short of the width plus the ellipsis is the width, so the row never wraps.
#[test]
fn a_long_line_is_cut_to_the_width() {
assert_eq!(fit("abcdefghij", 6), "abcde…");
assert_eq!(visible_width(&fit("abcdefghij", 6)), 6);
}
/// Escapes take no cells: a colored line that fits isn't cut, and a cut one is reset.
#[test]
fn escapes_are_not_counted() {
let green = "\x1b[32m✓ read\x1b[39m a.rs";
assert_eq!(visible_width(green), "✓ read a.rs".chars().count());
assert_eq!(fit(green, 11), green);
assert_eq!(fit(green, 5), "\x1b[32m✓ re…\x1b[0m");
}
/// A wide character counts as the two cells it takes.
#[test]
fn wide_characters_count_double() {
assert_eq!(visible_width("日本"), 4);
assert_eq!(fit("日本語", 5), "日本…");
}
/// A pipe never redraws: there's no row to go back to.
#[test]
fn a_pipe_never_redraws() {
let mut screen = Screen::recording();
let line = screen.print("○ read a.rs");
assert!(!screen.rewrite(line, "✓ read a.rs"));
}
}