fix: unify Console prompt and output and keep splitters above pane chrome
Verify Tessera GUI / verify (push) Failing after 7m13s

This commit is contained in:
2026-10-20 20:19:34 +08:00
parent 53e8d7b287
commit 098fe45129
6 changed files with 173 additions and 134 deletions
+141 -125
View File
@@ -33,7 +33,6 @@ pub enum Tab {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Region {
Transcript = 0,
Input,
Tree,
Source,
Requests,
@@ -58,7 +57,6 @@ pub enum Action {
ClearNetwork,
Follow,
ResetSession,
Submit,
Focus(Focus),
Snapshot,
Cloud,
@@ -71,7 +69,6 @@ pub enum Action {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Split {
Dock,
Editor,
Tree,
Network,
}
@@ -100,11 +97,12 @@ pub struct DeveloperToolsState {
pub accent: Color,
pub input_error: String,
panel_width: f32,
editor_height: f32,
tree_width: f32,
network_fraction: f32,
scroll: [Scroll; 6],
widths: [Option<(u64, f32)>; 6],
scroll: [Scroll; 5],
widths: [Option<(u64, f32)>; 5],
reveal_input: bool,
console_stamp: u64,
drag: Option<Drag>,
cloud: bool,
follow: bool,
@@ -135,11 +133,12 @@ impl Default for DeveloperToolsState {
accent: PALETTE[0],
input_error: String::new(),
panel_width: 660.0,
editor_height: 180.0,
tree_width: 190.0,
network_fraction: 0.42,
scroll: [Scroll::default(); 6],
widths: [None; 6],
scroll: [Scroll::default(); 5],
widths: [None; 5],
reveal_input: true,
console_stamp: 0,
drag: None,
cloud: false,
follow: true,
@@ -159,6 +158,12 @@ pub struct DeveloperToolsLayout {
splits: Vec<(Rect, Split)>,
regions: Vec<(Rect, Region, f32, f32)>,
thumbs: Vec<(Rect, Region, bool, f32)>,
input: Option<ConsoleInputLayout>,
}
#[derive(Clone, Copy, Debug)]
struct ConsoleInputLayout {
viewport: Rect,
origin: Point,
}
impl DeveloperToolsState {
pub fn toggle(&mut self, doc: &RenderDocument) {
@@ -212,7 +217,9 @@ impl DeveloperToolsState {
if let Some(target) = target {
match target.role {
Role::Splitter(_) => {
if let Some((_, split)) = layout.splits.iter().find(|(r, _)| r.contains(p)) {
if let Some((_, split)) = layout.splits.iter().find(|(r, _)| {
Rect::new(r.x - 3.0, r.y - 3.0, r.width + 6.0, r.height + 6.0).contains(p)
}) {
self.drag = Some(Drag::Split(*split));
}
}
@@ -247,13 +254,10 @@ impl DeveloperToolsState {
self.focus = Some(f);
self.selection = false;
if f == Focus::Input
&& let Some((area, _, _, _)) = layout
.regions
.iter()
.find(|(_, r, _, _)| *r == Region::Input)
&& let Some(input) = layout.input
{
let scroll = self.scroll[Region::Input as usize];
let row = ((p.y - area.y - 5.0 + scroll.y) / ROW).floor().max(0.0) as usize;
let row = (((p.y - input.origin.y) / ROW).floor().max(0.0) as usize)
.min(self.input.split('\n').count() - 1);
let mut start = 0;
let line = self
.input
@@ -268,7 +272,7 @@ impl DeveloperToolsState {
}
})
.unwrap_or("");
let target = (p.x - area.x - 8.0 + scroll.x).max(0.0);
let target = (p.x - input.origin.x).max(0.0);
let mut offset = line.len();
for (i, part) in line.grapheme_indices(true) {
let advance =
@@ -279,10 +283,13 @@ impl DeveloperToolsState {
}
}
self.cursor = (start + offset).min(self.input.len());
self.reveal_cursor();
}
}
Some(Action::ClearConsole) => {
self.console_after = activity.lock().unwrap().records.back().map_or(0, |r| r.id);
self.scroll[Region::Transcript as usize] = Scroll::default();
self.reveal_cursor();
}
Some(Action::ClearNetwork) => {
self.network_after = activity.lock().unwrap().records.back().map_or(0, |r| r.id);
@@ -290,9 +297,9 @@ impl DeveloperToolsState {
}
Some(Action::Follow) => {
self.follow = !self.follow;
self.console_stamp = 0;
}
Some(Action::ResetSession) => self.submit_console(true),
Some(Action::Submit) => self.submit(),
Some(Action::Snapshot) => self.cloud = false,
Some(Action::Cloud) => self.cloud = true,
Some(Action::CloudRefresh) => self.cloud_sources.refresh(),
@@ -363,6 +370,7 @@ impl DeveloperToolsState {
});
if self.focus == Some(Focus::Input) {
self.cursor = self.input.len();
self.reveal_cursor();
}
}
return true;
@@ -402,10 +410,6 @@ impl DeveloperToolsState {
self.panel_width =
(window_width - p.x).clamp(360.0, (window_width - 100.0).max(360.0))
}
Some(Drag::Split(Split::Editor)) => {
self.editor_height = (layout.panel.height - p.y - 22.0)
.clamp(100.0, (layout.panel.height - 170.0).max(100.0))
}
Some(Drag::Split(Split::Tree)) => {
self.tree_width =
(p.x - layout.panel.x).clamp(120.0, (layout.panel.width - 180.0).max(120.0))
@@ -484,40 +488,19 @@ impl DeveloperToolsState {
None => {}
}
}
fn reveal_cursor(&mut self) {
let before = &self.input[..self.cursor];
let line = before.matches('\n').count() as f32;
let y = line * ROW;
let s = &mut self.scroll[Region::Input as usize];
if y < s.y {
s.y = y;
}
if y > s.y + self.editor_height - 100.0 {
s.y = (y - self.editor_height + 100.0).max(0.0);
}
let column = before.rsplit('\n').next().unwrap_or("");
let x = text::measure(column, TextStyle::code()).width;
if x < s.x {
s.x = x;
}
if x > s.x + self.panel_width - 100.0 {
s.x = (x - self.panel_width + 100.0).max(0.0);
}
pub(crate) fn reveal_cursor(&mut self) {
self.reveal_input = true;
}
pub fn ime_position(&self, layout: &DeveloperToolsLayout) -> Point {
if let Some((area, _, _, _)) = layout
.regions
.iter()
.find(|(_, r, _, _)| *r == Region::Input)
{
if let Some(input) = layout.input {
let before = &self.input[..self.cursor];
let row = before.matches('\n').count() as f32;
let col = before.rsplit('\n').next().unwrap_or("");
let scroll = self.scroll[Region::Input as usize];
let area = input.viewport;
return Point::new(
(area.x + 8.0 + text::measure(col, TextStyle::code()).width - scroll.x)
(input.origin.x + text::measure(col, TextStyle::code()).width)
.clamp(area.x, area.x + area.width),
(area.y + 5.0 + row * ROW - scroll.y).clamp(area.y, area.y + area.height),
(input.origin.y + row * ROW).clamp(area.y, area.y + area.height),
);
}
Point::new(layout.panel.x + 20.0, 60.0)
@@ -728,7 +711,8 @@ impl DeveloperToolsState {
self.input.clear();
self.cursor = 0;
self.history_index = None;
self.scroll[Region::Input as usize] = Scroll::default();
self.selection = false;
self.reveal_cursor();
}
self.follow = true;
self.input_error.clear();
@@ -763,18 +747,8 @@ impl Painter {
.button(r, action, Button::new(label).enabled(enabled));
}
fn split(&mut self, r: Rect, kind: Split) {
self.ui.splitter(
r,
WidgetId::new(("split", kind)),
match kind {
Split::Dock | Split::Tree => Axis::Horizontal,
_ => Axis::Vertical,
},
);
self.layout.splits.push((
Rect::new(r.x - 3.0, r.y - 3.0, r.width + 6.0, r.height + 6.0),
kind,
));
// Paint and register splitters after all pane content, in one overlay pass.
self.layout.splits.push((r, kind));
}
fn lines(
&mut self,
@@ -896,9 +870,6 @@ impl Line {
}
}
}
fn tint(c: Color) -> Color {
Theme::new(c).soft()
}
fn multiline(out: &mut Vec<Line>, value: &str, color: Color) {
out.extend(
value
@@ -1005,7 +976,7 @@ pub fn build(
p.fill(panel, BG);
p.ui.list.push(DrawCommand::PushClip(panel));
p.fill(Rect::new(x, 0.0, w, 31.0), BAR);
p.split(Rect::new(x, 0.0, 1.0, height), Split::Dock);
p.split(Rect::new(x + 1.0, 0.0, 1.0, height), Split::Dock);
for (i, (label, tab)) in [
("Console", Tab::Console),
("Sources", Tab::Sources),
@@ -1063,10 +1034,6 @@ pub fn build(
if w > 520.0 {
p.label(x + 309.0, 39.0, "app.main · live objects", MUTED, false);
}
let editor = state
.editor_height
.clamp(100.0, (height - 170.0).max(100.0));
let split_y = bottom - editor;
let mut lines = Vec::new();
for r in records.iter().filter(|r| {
r.id > state.console_after
@@ -1085,24 +1052,35 @@ pub fn build(
} else {
"CLEAR DOCUMENT"
};
let mut title = Line::new(
format!("#{} {} {} {}", r.id, r.timestamp, r.origin, kind),
MUTED,
);
title.divider = true;
title.action = Some(Action::Request(r.id));
lines.push(title);
multiline(&mut lines, &format!("› {}", r.request), TEXT);
let local =
r.origin == "Console" && r.path.ends_with("/repl") && r.method == "POST";
if !local {
let mut title = Line::new(
format!("#{} {} {} {}", r.id, r.timestamp, r.origin, kind),
MUTED,
);
title.divider = true;
title.action = Some(Action::Request(r.id));
lines.push(title);
}
for (i, line) in r.request.split('\n').enumerate() {
lines.push(Line::new(
format!("{}{line}", if i == 0 { "> " } else { " " }),
TEXT,
));
}
let color = if r.status.is_some_and(|s| s >= 400) {
ERROR
} else {
OK
};
if let Some(status) = r.status {
lines.push(Line::new(
format!("‹ {status} · {} ms", r.elapsed_ms),
color,
));
if !local {
lines.push(Line::new(
format!("‹ {status} · {} ms", r.elapsed_ms),
color,
));
}
console_result(&mut lines, &r.response, color);
} else {
lines.push(Line::new(" Executing…", MUTED));
@@ -1112,58 +1090,84 @@ pub fn build(
if lines.is_empty() {
multiline(
&mut lines,
"Console\n\nStatements, definitions and expressions share one live session.\nCreate objects now; call page.render(...) when ready to display.\nUse title = ui.text(\"你好,Tessera\") or let title = ...\nThe last value is also available as _.\n\nReset session clears objects and bindings, preserving the page.\nRuntime errors may retain earlier successful statements.\nExternal HTTP activity appears here too. History is never replayed.",
"Endor · live session\nCreate objects here; call page.render(...) to display.\n",
MUTED,
);
}
let follow = state.follow;
p.lines(
Rect::new(x + 1.0, 63.0, w - 2.0, split_y - 63.0),
Region::Transcript,
&lines,
state,
follow,
);
p.split(Rect::new(x + 1.0, split_y, w - 2.0, 1.0), Split::Editor);
p.fill(Rect::new(x + 1.0, split_y + 1.0, w - 2.0, 32.0), BAR);
p.label(
x + 12.0,
split_y + 8.0,
"Console · live session · render to display",
TEXT,
false,
);
p.enabled_button(
Rect::new(width - 95.0, split_y + 2.0, 89.0, 30.0),
"Run ↵",
Action::Submit,
!state.input.trim().is_empty(),
);
let input_area = Rect::new(x + 3.0, split_y + 35.0, w - 6.0, (editor - 62.0).max(24.0));
p.ui.text_field(
input_area,
use std::hash::{Hash, Hasher};
let mut hash = std::collections::hash_map::DefaultHasher::new();
for line in &lines {
line.value.hash(&mut hash);
}
let stamp = hash.finish();
let output_changed = stamp != state.console_stamp;
state.console_stamp = stamp;
let first_input = lines.len();
let area = Rect::new(x + 4.0, 63.0, w - 5.0, (bottom - 88.0).max(1.0));
p.ui.inline_input(
Rect::new(
area.x,
area.y,
(area.width - 9.0).max(0.0),
(area.height - 9.0).max(0.0),
),
Action::Focus(Focus::Input),
state.focus == Some(Focus::Input),
);
if state.selection && state.focus == Some(Focus::Input) {
p.fill(input_area, tint(state.accent));
}
if state.focus == Some(Focus::Input) {
p.fill(
Rect::new(x + 2.0, split_y + 35.0, 2.0, input_area.height),
state.accent,
);
}
let mut input = state.input.clone();
if state.focus == Some(Focus::Input) {
input.insert_str(state.cursor, &format!("{}│", state.preedit));
input.insert_str(state.cursor, &state.preedit);
}
if input.is_empty() {
input = "// title = ui.text(\"你好,Tessera\")".into();
for (i, line) in input.split('\n').enumerate() {
let mut line =
Line::new(format!("{}{line}", if i == 0 { "> " } else { " " }), TEXT);
line.selected = state.selection && state.focus == Some(Focus::Input);
lines.push(line);
}
let prefix = text::measure("> ", TextStyle::code()).width;
let before = &state.input[..state.cursor];
let row = before.matches('\n').count() as f32;
let column = before.rsplit('\n').next().unwrap_or("");
let caret_x = prefix
+ text::measure(&format!("{column}{}", state.preedit), TextStyle::code()).width;
let caret_y = (first_input as f32 + row) * ROW;
let follow = state.follow && output_changed && !state.reveal_input;
if state.reveal_input {
let s = &mut state.scroll[Region::Transcript as usize];
s.y = s.y.clamp(
(caret_y + ROW + 16.0 - area.height).max(0.0).min(caret_y),
caret_y,
);
s.x = s.x.clamp((caret_x + 24.0 - area.width).max(0.0), caret_x);
state.reveal_input = false;
}
p.lines(area, Region::Transcript, &lines, state, follow);
let scroll = state.scroll[Region::Transcript as usize];
let origin = Point::new(
area.x + 8.0 + prefix - scroll.x,
area.y + 5.0 + first_input as f32 * ROW - scroll.y,
);
p.layout.input = Some(ConsoleInputLayout {
viewport: area,
origin,
});
if state.focus == Some(Focus::Input) {
p.ui.list.push(DrawCommand::PushClip(Rect::new(
area.x,
area.y,
(area.width - 9.0).max(0.0),
(area.height - 9.0).max(0.0),
)));
p.fill(
Rect::new(
area.x + 8.0 + caret_x - scroll.x,
origin.y + row * ROW + 1.0,
1.0,
ROW - 2.0,
),
TEXT,
);
p.ui.list.push(DrawCommand::PopClip);
}
let mut input_lines = Vec::new();
multiline(&mut input_lines, &input, TEXT);
p.lines(input_area, Region::Input, &input_lines, state, false);
p.label(
x + 10.0,
bottom - 23.0,
@@ -1501,6 +1505,18 @@ pub fn build(
MUTED,
false,
);
// Splitters must be above toolbars, pane backgrounds and status bars for their
// whole length. Register them last so their hit priority matches their paint order.
for (rect, kind) in p.layout.splits.clone().into_iter().rev() {
p.ui.splitter(
rect,
WidgetId::new(("split", kind)),
match kind {
Split::Dock | Split::Tree => Axis::Horizontal,
Split::Network => Axis::Vertical,
},
);
}
p.ui.list.push(DrawCommand::PopClip);
let mut scaled = DisplayList::default();
for cmd in p.ui.list.commands() {