use super::*;
pub(super) fn draw_pane(ctx: &mut Ctx, pane: &mut Pane, out: &mut Vec<Quad>) -> bool {
let s = ctx.scale;
let pal = ctx.palette;
let o = pane.opacity;
let card = pane.rect;
if card.w < 1.0 || card.h < 1.0 || o < 0.004 {
return false;
}
let radius = ctx.config.radius * s;
let pad = (ctx.config.padding * s).round();
let (cw, ch) = (ctx.glyphs.cell_w, ctx.glyphs.cell_h);
let focus = pane.focus;
let see_through = ctx.alpha < 1.0;
out.push(shadow(card, radius, 14.0 * s, 3.0 * s, if see_through { 0.24 } else { 0.45 } * o, see_through));
let (ring_color, ring) =
if pane.claude { (CLAUDE, focus * ctx.multi.max(0.55)) } else { (pal.accent, focus * ctx.multi) };
let surface = mix(pal.surface, pal.foreground, pane.bell * 0.03);
if ctx.glass {
let mut rim = mix(WHITE, ring_color, ring * 0.85);
rim = mix(rim, pal.ansi[3], pane.bell * 0.8);
rim[3] = (0.6 + 0.4 * ring + 0.4 * pane.bell).min(1.0) * o;
out.push(glass(card, with_alpha(surface, ctx.alpha * o), rim, 0.55 * o, radius, s));
} else {
let mut border = mix(pal.border, with_alpha(ring_color, 0.85), ring);
border = mix(border, pal.ansi[3], pane.bell * 0.8);
out.push(Quad {
rect: [card.x, card.y, card.w, card.h],
uv: [0.0; 4],
color: with_alpha(surface, o),
clip: NO_CLIP,
params: [MODE_ROUNDED, radius, (1.0 * s).max(1.0), 0.0],
color2: with_alpha(border, o),
});
}
if let Some(chat) = pane.chat.as_mut().filter(|c| !c.hidden) {
crate::agent::chat::draw(ctx, chat, card, o, out);
draw_veil(ctx, card, focus, o, out);
return false;
}
if let Some(view) = pane.review.as_mut().filter(|v| !v.hidden) {
let again = o > 0.5 && crate::review_ui::draw(ctx, view, card, out);
draw_veil(ctx, card, focus, o, out);
return again;
}
let ox = (card.x + pad).round();
let oy = (card.y + pad).round();
let inner = card.inset((pad * 0.35).max(2.0));
let bar_h = if pane.claude { claude_bar_height(ch, s) } else { 0.0 };
let clip = [inner.x, inner.y, inner.right(), (inner.bottom() - bar_h).max(inner.y)];
let term = pane.term.lock();
let history = term.grid().history_size();
let content = term.renderable_content();
let colors = content.colors;
let mode = content.mode;
let offset = content.display_offset;
let selection = content.selection;
let cursor = content.cursor;
let rows = pane.grid.rows;
let cursor_row = cursor.point.line.0 + offset as i32;
let show_cursor = mode.contains(TermMode::SHOW_CURSOR)
&& cursor.shape != CursorShape::Hidden
&& cursor_row >= 0
&& (cursor_row as usize) < rows;
let cursor_px = (cursor.point.column.0 as f32 * cw, cursor_row as f32 * ch);
let block_cursor = show_cursor && ctx.focused && cursor.shape == CursorShape::Block;
let invert_cell = block_cursor && ctx.cursor_alpha > 0.5;
ctx.bg.clear();
ctx.fg.clear();
let fg_alpha = o;
let sel_color = with_alpha(pal.selection, o);
let line_w = (ctx.glyphs.font_px / 14.0).round().max(1.0);
let baseline = ctx.glyphs.baseline;
for indexed in content.display_iter {
let cell = indexed.cell;
let row = indexed.point.line.0 + offset as i32;
if row < 0 || row as usize >= rows {
continue;
}
let col = indexed.point.column.0;
let flags = cell.flags;
if flags.intersects(Flags::WIDE_CHAR_SPACER | Flags::LEADING_WIDE_CHAR_SPACER) {
continue;
}
let width = if flags.contains(Flags::WIDE_CHAR) { 2.0 } else { 1.0 };
let x = ox + col as f32 * cw;
let y = oy + row as f32 * ch;
let mut fg = resolve(cell.fg, colors, pal);
let bg_default = matches!(cell.bg, Color::Named(NamedColor::Background));
let mut bg = resolve(cell.bg, colors, pal);
let mut has_bg = !bg_default;
if flags.contains(Flags::INVERSE) {
std::mem::swap(&mut fg, &mut bg);
has_bg = true;
}
if pane.claude {
fg = soften_gray(fg, pal, false);
if has_bg && !bg_default {
bg = with_alpha(soften_gray(bg, pal, true), ctx.alpha);
}
}
if flags.contains(Flags::DIM) {
fg = mix(fg, bg, 0.4);
}
let selected = selection.is_some_and(|s| s.contains(indexed.point));
if selected {
bg = pal.selection;
has_bg = true;
}
if has_bg {
let c = if selected { sel_color } else { with_alpha(bg, o) };
ctx.bg.push(quad(Rect::new(x, y, cw * width, ch), c, clip, MODE_SOLID));
}
let under_cursor = invert_cell && cursor_row == row && cursor.point.column.0 == col;
if under_cursor {
fg = pal.surface;
}
let c = cell.c;
if c != ' ' && c != '\t' && !flags.contains(Flags::HIDDEN) {
let mut style = 0;
if flags.contains(Flags::BOLD) {
style |= STYLE_BOLD;
}
if flags.contains(Flags::ITALIC) {
style |= STYLE_ITALIC;
}
let zw = cell.zerowidth().and_then(|z| z.first().copied());
if let Some(g) = ctx.glyphs.get(GlyphKey { c, zw, style }) {
let (mode, color) = if g.color {
(MODE_COLOR, [1.0, 1.0, 1.0, fg_alpha])
} else {
(MODE_MASK, with_alpha(fg, fg_alpha))
};
ctx.fg.push(Quad {
rect: [x + g.left, y + g.top, g.uv[2], g.uv[3]],
uv: g.uv,
color,
clip,
params: [mode, 0.0, 0.0, 0.0],
color2: [0.0; 4],
});
}
}
if flags.intersects(Flags::ALL_UNDERLINES | Flags::STRIKEOUT) {
let uc = cell.underline_color().map(|c| resolve(c, colors, pal)).unwrap_or(fg);
let uc = with_alpha(uc, fg_alpha);
let uy = (y + baseline + line_w * 1.5).min(y + ch - line_w);
let w = cw * width;
if flags.contains(Flags::UNDERCURL) {
let h = (3.0 * s).round().max(3.0);
ctx.fg.push(Quad {
rect: [x, uy - h * 0.5, w, h],
uv: [0.0; 4],
color: uc,
clip,
params: [MODE_UNDERCURL, line_w, 0.0, 0.0],
color2: [0.0; 4],
});
} else if flags.contains(Flags::DOUBLE_UNDERLINE) {
ctx.fg.push(quad(Rect::new(x, uy - line_w, w, line_w), uc, clip, MODE_SOLID));
ctx.fg.push(quad(Rect::new(x, uy + line_w, w, line_w), uc, clip, MODE_SOLID));
} else if flags.intersects(Flags::DOTTED_UNDERLINE | Flags::DASHED_UNDERLINE) {
let seg = if flags.contains(Flags::DOTTED_UNDERLINE) { line_w * 2.0 } else { cw * 0.5 };
let mut sx = x;
while sx < x + w {
ctx.fg.push(quad(Rect::new(sx, uy, (seg * 0.6).min(x + w - sx), line_w), uc, clip, MODE_SOLID));
sx += seg;
}
} else if flags.contains(Flags::UNDERLINE) {
ctx.fg.push(quad(Rect::new(x, uy, w, line_w), uc, clip, MODE_SOLID));
}
if flags.contains(Flags::STRIKEOUT) {
let sy = (y + baseline - ctx.glyphs.font_px * 0.3).round();
ctx.fg.push(quad(Rect::new(x, sy, w, line_w), with_alpha(fg, fg_alpha), clip, MODE_SOLID));
}
}
}
if let Some(search) = &pane.search {
let others = with_alpha(pal.accent, 0.28 * o);
let current = with_alpha(pal.ansi[3], 0.55 * o);
for (i, m) in search.matches.iter().enumerate() {
let row = m.line + offset as i32;
if row < 0 || row as usize >= rows {
continue;
}
let r = Rect::new(ox + m.start as f32 * cw, oy + row as f32 * ch, (m.end - m.start) as f32 * cw, ch);
ctx.bg.push(quad(r, if i == search.current { current } else { others }, clip, MODE_SOLID));
}
}
out.append(&mut ctx.bg);
if show_cursor && ctx.focused {
let cx = ox + cursor_px.0;
let cy = oy + cursor_px.1;
let thin = (1.6 * s).round().max(1.0);
let ccol = pal.cursor;
let a = ctx.cursor_alpha * o;
match cursor.shape {
CursorShape::Block => out.push(quad(Rect::new(cx, cy, cw, ch), with_alpha(ccol, a), clip, MODE_SOLID)),
CursorShape::Beam => ctx.fg.push(quad(Rect::new(cx, cy, thin, ch), with_alpha(ccol, a), clip, MODE_SOLID)),
CursorShape::Underline => {
ctx.fg.push(quad(Rect::new(cx, cy + ch - thin, cw, thin), with_alpha(ccol, a), clip, MODE_SOLID))
}
_ => hollow(&mut ctx.fg, cx, cy, cw, ch, thin.min(1.0 * s).max(1.0), with_alpha(ccol, a), clip),
}
}
if let Some((line, c0, c1)) = pane.link {
let row = line + offset as i32;
if row >= 0 && (row as usize) < rows {
let top = oy + row as f32 * ch;
let uy = (top + baseline + line_w * 1.5).min(top + ch - line_w);
let r = Rect::new(ox + c0 as f32 * cw, uy, (c1 - c0) as f32 * cw, line_w);
ctx.fg.push(quad(r, with_alpha(pal.accent, o), clip, MODE_SOLID));
}
}
out.append(&mut ctx.fg);
if let Some(search) = &pane.search {
draw_search_bar(ctx, search, card, o, out);
}
if offset > 0 && history > 0 {
let track = Rect::new(card.right() - 6.0 * s, card.y + radius, 3.0 * s, card.h - 2.0 * radius);
let total = (history + rows) as f32;
let th = (rows as f32 / total * track.h).max(18.0 * s);
let ty = track.y + (1.0 - offset as f32 / history as f32) * (track.h - th);
out.push(Quad {
rect: [track.x, ty, track.w, th],
uv: [0.0; 4],
color: with_alpha(pal.foreground, 0.28 * o),
clip: NO_CLIP,
params: [MODE_ROUNDED, track.w * 0.5, 0.0, 0.0],
color2: [0.0; 4],
});
}
if pane.claude {
draw_claude_bar(ctx, pane, card, out);
}
draw_veil(ctx, card, focus, o, out);
false
}
pub(super) fn draw_veil(ctx: &Ctx, card: Rect, focus: f32, o: f32, out: &mut Vec<Quad>) {
let s = ctx.scale;
let veil = (1.0 - focus) * 0.38 * ctx.multi * o;
if veil > 0.002 {
let v = card.inset(1.0 * s);
out.push(Quad {
rect: [v.x, v.y, v.w, v.h],
uv: [0.0; 4],
color: with_alpha(ctx.palette.surface, veil),
clip: NO_CLIP,
params: [MODE_ROUNDED, (ctx.config.radius * s - 1.0 * s).max(0.0), 0.0, 0.0],
color2: [0.0; 4],
});
}
}
pub(super) fn draw_drop_hint(ctx: &mut Ctx, pane: &Rect, out: &mut Vec<Quad>) {
let s = ctx.scale;
let pal = ctx.palette;
let (cw, ch) = (ctx.glyphs.cell_w, ctx.glyphs.cell_h);
let radius = ctx.config.radius * s;
let frame = pane.inset(1.0 * s);
out.push(rounded(
frame,
with_alpha(pal.accent, 0.12),
radius,
(2.0 * s).max(2.0),
with_alpha(pal.accent, 0.9),
NO_CLIP,
));
let message = "Drop to type the path";
let w = (message.chars().count() as f32 + 4.0) * cw;
let pill = Rect::new(
(pane.x + (pane.w - w) * 0.5).round(),
(pane.y + (pane.h - ch * 2.0) * 0.5).round(),
w,
(ch * 2.0).round(),
);
out.push(rounded(
pill,
with_alpha(mix(pal.surface, pal.foreground, 0.07), 0.95),
10.0 * s,
s.max(1.0),
with_alpha(pal.accent, 0.8),
NO_CLIP,
));
text(ctx, out, pill.x + 2.0 * cw, (pill.y + (pill.h - ch) * 0.5).round(), message, pal.foreground, 0, w, NO_CLIP);
}
pub(super) fn draw_search_bar(ctx: &mut Ctx, search: &Search, card: Rect, o: f32, out: &mut Vec<Quad>) {
let s = ctx.scale;
let pal = ctx.palette;
let (cw, ch) = (ctx.glyphs.cell_w, ctx.glyphs.cell_h);
let h = (ch * 1.9).round();
let w = (360.0 * s).min(card.w - 24.0 * s).max(cw * 16.0).min(card.w);
let bar = Rect::new((card.right() - w - 12.0 * s).round(), (card.y + 10.0 * s).round(), w, h);
let bg = mix(pal.surface, pal.foreground, 0.05);
out.push(shadow(bar, 10.0 * s, 14.0 * s, 5.0 * s, 0.45 * o, ctx.alpha < 1.0));
let border = with_alpha(mix(pal.border, pal.accent, 0.55), o);
out.push(rounded(bar, with_alpha(bg, (ctx.alpha + 0.2).min(1.0) * o), 10.0 * s, s.max(1.0), border, NO_CLIP));
let ty = (bar.y + (h - ch) * 0.5).round();
let tx = bar.x + cw;
text(ctx, out, tx, ty, "›", with_alpha(pal.accent, o), STYLE_BOLD, cw * 2.0, NO_CLIP);
let label = search.label();
let label_w = label.chars().count() as f32 * cw;
let label_color = if search.matches.is_empty() && !search.query.is_empty() {
with_alpha(pal.ansi[1], o)
} else {
with_alpha(mix(pal.foreground, bg, 0.55), o)
};
text(ctx, out, bar.right() - cw - label_w, ty, &label, label_color, 0, label_w + 1.0, NO_CLIP);
let qx = tx + cw * 2.0;
let room = (bar.right() - cw * 2.0 - label_w - qx).max(0.0);
let max_chars = (room / cw).floor() as usize;
let fg = with_alpha(pal.foreground, o);
let caret_x = if search.query.is_empty() {
let hint = with_alpha(mix(pal.foreground, bg, 0.7), o);
text(ctx, out, qx, ty, "find in scrollback", hint, 0, room, NO_CLIP);
qx - 3.0 * s
} else {
let chars: Vec<char> = search.query.chars().collect();
let shown: String = chars[chars.len().saturating_sub(max_chars)..].iter().collect();
qx + text(ctx, out, qx, ty, &shown, fg, 0, room + cw, NO_CLIP) + 1.0
};
let caret = Rect::new(caret_x, ty + ch * 0.12, (1.5 * s).round().max(1.0), ch * 0.76);
out.push(quad(caret, with_alpha(pal.accent, o * ctx.cursor_alpha.max(0.25)), NO_CLIP, MODE_SOLID));
}
pub fn claude_bar_height(cell_h: f32, scale: f32) -> f32 {
(cell_h * 1.6 + 6.0 * scale).round()
}
pub(super) enum Part {
Text(String, Rgba, u8),
Meter(f32),
Gap,
}
pub(super) fn draw_claude_bar(ctx: &mut Ctx, pane: &Pane, card: Rect, out: &mut Vec<Quad>) {
let s = ctx.scale;
let pal = ctx.palette;
let o = pane.opacity;
let (cw, ch) = (ctx.glyphs.cell_w, ctx.glyphs.cell_h);
let pad = (ctx.config.padding * s).round();
let bar_h = claude_bar_height(ch, s);
let top = card.bottom() - bar_h;
let muted = with_alpha(mix(pal.foreground, pal.surface, 0.5), o);
let fg = with_alpha(mix(pal.foreground, pal.surface, 0.1), o);
let level = |pct: f32| {
let c = if pct < 60.0 {
pal.ansi[2]
} else if pct < 85.0 {
pal.ansi[3]
} else {
pal.ansi[1]
};
with_alpha(c, o)
};
let line = Rect::new(card.x + pad * 0.6, top, card.w - pad * 1.2, s.max(1.0));
out.push(quad(line, with_alpha(mix(pal.border, pal.foreground, 0.04), o), NO_CLIP, MODE_SOLID));
let status = pane.claude_status.clone().unwrap_or_default();
let usage = ctx.usage.fresh();
let five = status.five_hour.or(usage.five_hour);
let week = status.seven_day.or(usage.seven_day);
let model = if status.model.is_empty() { "claude".to_string() } else { status.model.to_lowercase() };
let window = |label: &str, w: Option<claude::Window>| -> Vec<Part> {
let mut parts = vec![Part::Text(format!("{label} "), muted, 0)];
match w {
Some(w) => {
parts.push(Part::Meter(w.used_pct));
parts.push(Part::Text(format!(" {:.0}%", w.used_pct), level(w.used_pct), 0));
parts.push(Part::Text(format!(" resets {}", claude::until(w.resets_at)), muted, 0));
}
None => parts.push(Part::Text("—".into(), muted, 0)),
}
parts
};
let context = match status.context_pct {
Some(p) => {
vec![Part::Text("context ".into(), muted, 0), Part::Meter(p), Part::Text(format!(" {p:.0}%"), level(p), 0)]
}
None => vec![Part::Text("context —".into(), muted, 0)],
};
let mut segments: Vec<Vec<Part>> =
vec![vec![Part::Text("✻ ".into(), with_alpha(CLAUDE, o), STYLE_BOLD), Part::Text(model, fg, 0)]];
if five.is_none() && week.is_none() {
segments.push(vec![Part::Text("plan usage appears after Claude's first reply".into(), muted, 0)]);
} else {
segments.push(window("5h", five));
segments.push(window("week", week));
}
segments.push(context);
if status.lines_added + status.lines_removed > 0 {
segments.push(vec![
Part::Text(format!("+{}", status.lines_added), with_alpha(pal.ansi[2], o), 0),
Part::Text(format!(" −{}", status.lines_removed), with_alpha(pal.ansi[1], o), 0),
]);
}
let meter_w = (cw * 5.0).round();
let part_w = |p: &Part| match p {
Part::Text(t, _, _) => t.chars().count() as f32 * cw,
Part::Meter(_) => meter_w,
Part::Gap => cw * 2.5,
};
let avail = card.w - 2.0 * pad;
let mut used = 0.0;
let mut parts: Vec<Part> = Vec::new();
for seg in segments {
let w: f32 = seg.iter().map(part_w).sum::<f32>() + if parts.is_empty() { 0.0 } else { cw * 2.5 };
if used + w > avail {
break;
}
used += w;
if !parts.is_empty() {
parts.push(Part::Gap);
}
parts.extend(seg);
}
let ty = (top + (bar_h - ch) * 0.5).round();
let mut x = card.x + pad;
for p in &parts {
match p {
Part::Text(t, c, style) => {
text(ctx, out, x, ty, t, *c, *style, part_w(p) + 1.0, NO_CLIP);
}
Part::Meter(pct) => {
let h = (4.0 * s).round().max(3.0);
let my = (ty + (ch - h) * 0.5).round();
let track = Rect::new(x, my, meter_w, h);
out.push(rounded(
track,
with_alpha(mix(pal.surface, pal.foreground, 0.12), o),
h * 0.5,
0.0,
[0.0; 4],
NO_CLIP,
));
let fw = (meter_w * (pct / 100.0).clamp(0.0, 1.0)).max(h);
out.push(rounded(Rect::new(x, my, fw, h), level(*pct), h * 0.5, 0.0, [0.0; 4], NO_CLIP));
}
Part::Gap => {}
}
x += part_w(p);
}
}