1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//! Pane content: the terminal grid blit, the lone-pane header bar, and the
//! dot+path+close title drawn onto each split pane's top border.
use super::*;
/// Draw the dot + path (+ ✕ for the focused pane) as a title ON each pane's top
/// border row, after the borders are drawn, so it lands on the tab bar edge.
pub(super) fn draw_pane_titles(
f: &mut RenderTarget,
rects: &[(PaneId, Rect)],
focus: PaneId,
app: &App,
t: &Theme,
) -> Vec<(PaneId, Rect)> {
let mut title_rects = Vec::new();
for (id, rect) in rects {
if rect.width < 8 || rect.height < 2 {
continue;
}
let Some(pane) = app.panes.get(id) else {
continue;
};
let focused = *id == focus;
let st = pane_state(app, *id);
let path_fg = if focused { t.accent } else { t.subtext0 };
// The top border is a thin rule now (not a filled bar), so the title
// sits on the dark background; only the text cells are painted, leaving
// the thin `▔` line visible on either side of the label.
let bg = t.mantle;
let inner_w = rect.width - 2; // inside the two corner cells
let close_w: u16 = if focused { 3 } else { 0 };
let title_w = inner_w.saturating_sub(close_w);
let path = short_path(&pane.cwd, title_w.saturating_sub(4));
let text_w = (3 + path.chars().count() as u16).min(title_w);
let title = Line::from(vec![
Span::styled(
format!(" {} ", st.dot()),
Style::new().fg(st.color(t)).bg(bg),
),
Span::styled(path, Style::new().fg(path_fg).bg(bg)),
]);
let title_rect = Rect::new(rect.x + 1, rect.y, text_w, 1);
f.render_widget(Paragraph::new(title), title_rect);
// Clicking the title opens the running-command overlay.
title_rects.push((*id, title_rect));
if focused {
f.render_widget(
Paragraph::new(Span::styled(
" × ",
Style::new().fg(t.subtext1).bg(bg).bold(),
)),
Rect::new(rect.x + 1 + title_w, rect.y, close_w, 1),
);
}
}
title_rects
}
// ── panes ─────────────────────────────────────────────────────────────────
pub(super) fn draw_panes(
f: &mut RenderTarget,
rects: &[(PaneId, Rect)],
bordered: bool,
app: &App,
t: &Theme,
) -> Option<(u16, u16)> {
let focus = app.layout().focus;
let mut cursor = None;
for (id, rect) in rects {
if let Some(c) = draw_one_pane(f, *rect, *id, *id == focus, bordered, app, t) {
cursor = Some(c);
}
}
cursor
}
fn draw_one_pane(
f: &mut RenderTarget,
area: Rect,
id: PaneId,
focused: bool,
bordered: bool,
app: &App,
t: &Theme,
) -> Option<(u16, u16)> {
let pane = app.panes.get(&id)?;
let st = pane_state(app, id);
let content = pane_content(area, bordered)?;
// A lone pane has no border, so it shows a header bar on its top row.
// Bordered panes instead get their dot+path+close as a title ON the top
// border row (see `draw_pane_titles`), so it touches the tab bar.
if !bordered {
// Match the content's horizontal pad so the header bar aligns with the
// tab bar and the terminal text below it.
let pad = lone_pad(area.width);
let header = Rect::new(area.x + pad, area.y, area.width.saturating_sub(2 * pad), 1);
let hbg = if focused { t.surface1 } else { t.surface0 };
let path_fg = if focused { t.accent } else { t.overlay1 };
f.render_widget(Block::new().style(Style::new().bg(hbg)), header);
let title = Line::from(vec![
Span::styled("▎", Style::new().fg(t.accent).bg(hbg)),
Span::styled(
format!(" {} ", st.dot()),
Style::new().fg(st.color(t)).bg(hbg),
),
Span::styled(
short_path(&pane.cwd, header.width.saturating_sub(5)),
Style::new().fg(path_fg).bg(hbg),
),
]);
f.render_widget(Paragraph::new(title), header);
}
// Content background = the dark pane background.
f.render_widget(Block::new().style(Style::new().bg(t.mantle)), content);
let downsample = app.downsample;
// A mouse text-selection in this pane highlights its cells.
let sel = app.selection.filter(|s| s.pane == id);
let mut scrolled = 0usize;
let cursor_pos = match pane.engine.lock() {
Ok(engine) => {
{
let buf = f.buffer_mut();
engine.for_each_cell(&mut |row, col, cell| {
if row >= content.height || col >= content.width {
return;
}
let x = content.x + col;
let y = content.y + row;
let conv = |c: Color| {
if downsample {
crate::ipc::protocol::to_256(c)
} else {
c
}
};
let fg = if cell.fg == Color::Reset {
t.text
} else {
conv(cell.fg)
};
let mut style = Style::new().fg(fg);
if !cell.mods.is_empty() {
style = style.add_modifier(cell.mods);
}
if cell.bg != Color::Reset {
style = style.bg(conv(cell.bg));
}
// Highlight the cell if it's inside the mouse selection.
if sel.is_some_and(|s| s.contains(x, y)) {
style = style.bg(t.sel_bg);
}
// ratatui panics if a control char reaches the buffer; the
// VT grid can hold stray C0/C1 bytes, so render them blank.
let ch = if cell.c.is_control() { ' ' } else { cell.c };
let mut tmp = [0u8; 4];
let target = &mut buf[(x, y)];
target.set_symbol(ch.encode_utf8(&mut tmp));
target.set_style(style);
});
}
scrolled = engine.scroll_offset();
let cur = engine.cursor();
if focused && cur.visible && cur.x < content.width && cur.y < content.height {
Some((content.x + cur.x, content.y + cur.y))
} else {
None
}
}
Err(_) => None,
};
// Scrollback indicator: when the viewport is above the live bottom, show how
// far up (in lines) at the content's top-right so the state is never a
// mystery. Any keystroke — or scrolling back down — returns to live.
if scrolled > 0 && content.height > 0 {
let label = format!(" ↑{scrolled} ");
let w = crate::ui::display_width(&label) as u16;
if w < content.width {
let badge = Rect::new(content.x + content.width - w, content.y, w, 1);
f.render_widget(
Paragraph::new(Line::from(Span::styled(
label,
Style::new().fg(t.crust).bg(t.accent),
))),
badge,
);
}
}
cursor_pos
}