From 098fe451291326b901a337c08bb3528dc24268c1 Mon Sep 17 00:00:00 2001 From: Codex Bot Date: Tue, 20 Oct 2026 20:19:34 +0800 Subject: [PATCH] fix: unify Console prompt and output and keep splitters above pane chrome --- README.md | 17 ++- src/README.md | 2 +- src/app.rs | 1 + src/developer_tools.rs | 266 +++++++++++++++++++++------------------ src/system_ui/README.md | 10 +- src/system_ui/widgets.rs | 11 ++ 6 files changed, 173 insertions(+), 134 deletions(-) diff --git a/README.md b/README.md index 9e4a098..0bc0ca6 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ source budgets and VM instruction limits are not a complete untrusted-code sandb Toggle developer tools with Command-Option-I or F12 on macOS, Control-Shift-I or F12 on Windows/Linux. The compact Console, Sources, Network and Settings tabs -share a draggable dock edge. Console's editor boundary, the Sources tree/source +share a draggable dock edge. The Sources tree/source boundary and Network's request/details boundary can also be dragged. Each content area has independent vertical and horizontal scrolling, draggable scrollbar thumbs, and trackpad support. Shift-wheel scrolls horizontally. Layout uses logical pixels @@ -180,7 +180,12 @@ and the actual display scale; resize clamps pane sizes to keep controls reachabl Console is one live execution context: statements, function definitions and expressions use the same VM and globals dictionary across submissions. There is no -Expression/Script selector. Enter runs the input; Shift-Enter inserts a newline. +Expression/Script selector. The current prompt, submitted commands and results +share one scrollable surface, with no separate input box, editor splitter or Run +toolbar. Typing appears at the prompt immediately; Enter executes it and the result +appears directly below. Shift-Enter inserts a newline. Input focus uses a text caret, +without a blue field border or hover fill. The prompt, history and caret share the +same scroll offset; typing and cursor navigation reveal the current insertion point. Create objects with bare assignment or `let`, then render them when ready: ```endor @@ -226,7 +231,7 @@ failed statements; it is not guaranteed to replay as a standalone program. External HTTP activity appears in the same transcript. Unsupported language operations (currently numeric arithmetic bytecode) show actual diagnostics. Transport -failures appear beside the editor and restore an otherwise empty draft. +failures appear in the Console footer and restore an otherwise empty draft. Sources shows the full source snapshot or Console transcript with line numbers, Aster's AST and selected source ranges. Selecting an AST node scrolls to its location while @@ -255,8 +260,10 @@ widget library, independent of Endor-controlled page widgets. Buttons, tabs, toggles, rows, input fields, color swatches and drag handles share hover, pressed, selected, focus and disabled presentation. Buttons activate on release inside; dragging outside cancels. Tab/Shift-Tab navigate enabled controls and Enter/Space -activate focused buttons. Plain Tab still indents in the Console editor. Empty -Run/Clear actions are disabled. macOS clipboard reads and writes explicitly use +activate focused buttons. Plain Tab still indents at the Console prompt. Empty +Clear actions are disabled. Splitters are painted and registered above all pane +backgrounds, toolbars and status bars, so their entire length stays visible and +draggable. macOS clipboard reads and writes explicitly use UTF-8 even when launched from Finder, and decoding errors are surfaced. ## Validation diff --git a/src/README.md b/src/README.md index d7460b2..d2daa0c 100644 --- a/src/README.md +++ b/src/README.md @@ -14,7 +14,7 @@ | clipboard.rs | UTF-8 macOS clipboard adapter independent of Finder locale, with strict decoding and surfaced errors | | system_ui/ | Host-only management widget library: stable IDs, interaction, theme and reusable control drawing | | scene.rs | Page and developer-tools display-list composition | -| developer_tools.rs | Console input/transcript, full Sources, Network inspector, theme, pane/scroll geometry and focus | +| developer_tools.rs | Unified Console prompt/output stream, caret/IME mapping, full Sources, Network inspector, theme, scrolling, overlay splitters and focus | | sources.rs | Disconnected cloud workspace and provider boundary for listing/opening complete source files | | display_list.rs | Rendering primitives and color representation | | geometry.rs | Native points and rectangles | diff --git a/src/app.rs b/src/app.rs index 4ed3e0c..13f0073 100644 --- a/src/app.rs +++ b/src/app.rs @@ -233,6 +233,7 @@ impl ApplicationHandler for TesseraApp { if self.developer_tools.input.is_empty() { self.developer_tools.input = source; self.developer_tools.cursor = self.developer_tools.input.len(); + self.developer_tools.reveal_cursor(); } self.request_redraw(); } diff --git a/src/developer_tools.rs b/src/developer_tools.rs index 4252b82..ebae3ec 100644 --- a/src/developer_tools.rs +++ b/src/developer_tools.rs @@ -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, 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, +} +#[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, 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() { diff --git a/src/system_ui/README.md b/src/system_ui/README.md index f1ab46d..a254b00 100644 --- a/src/system_ui/README.md +++ b/src/system_ui/README.md @@ -12,7 +12,7 @@ and display-list rendering are shared with the page renderer. Enter/Space activation, disabled controls and cursor roles. - `theme.rs`: neutral/error/success colors, accent presets, readable custom accents and shared idle/hover/pressed/selected colors. -- `widgets.rs`: button, tab, toggle, text field chrome, selectable row, color swatch, +- `widgets.rs`: button, tab, toggle, text field chrome, borderless inline prompt target, selectable row, color swatch, splitter and scrollbar thumb. Text is clipped to its widget bounds. Hover, pressed, selection, keyboard focus and disabled states compose consistently. - `mod.rs`: public interface used by management surfaces. @@ -37,7 +37,9 @@ Store `ui.targets` with the newly produced layout and render `ui.list` through t native display-list backend. Reconcile retained interaction against the new targets; request one more redraw when a target moves, disappears or changes enabled state. This settles hover under a stationary pointer after a layout change without a timer -or continuous rendering loop. Preserve clipping and scale every primitive, including +or continuous rendering loop. Paint and register splitters after pane content and +toolbars so neither their appearance nor their hit regions are obscured. +Preserve clipping and scale every primitive, including focus outlines, when converting logical coordinates to physical pixels. Dispatch pointer movement, press and release to `Interaction`. Press establishes @@ -50,7 +52,9 @@ Tab / Shift-Tab traverse enabled controls; Enter / Space activate a focused butt on key release. The host's editor keeps plain Tab for indentation and Shift-Tab for leaving the editor. Rows and drag handles are excluded from Tab traversal. Text editing, clipboard and IME remain host adapters; the widget layer owns their chrome -and focus presentation. `src/clipboard.rs` guarantees UTF-8 for macOS clipboard +and focus presentation. `inline_input` registers a text-input target without a +background or focus border; a terminal-style host draws its own caret in the same +scrollable stream as output. `src/clipboard.rs` guarantees UTF-8 for macOS clipboard subprocesses, independent of Finder's locale. Tessera's developer tools are the first consumer. Domain actions, HTTP calls, diff --git a/src/system_ui/widgets.rs b/src/system_ui/widgets.rs index 8245d2a..543bab6 100644 --- a/src/system_ui/widgets.rs +++ b/src/system_ui/widgets.rs @@ -190,6 +190,17 @@ impl Ui { if focused || s.focused { 1.5 } else { 1.0 }, ); } + /// A terminal prompt shares its surface with output; its caret is the focus cue. + pub fn inline_input(&mut self, rect: Rect, action: A) { + self.register( + WidgetId::new(&action), + rect, + Role::TextField, + Some(action), + false, + true, + ); + } pub fn row(&mut self, paint: Rect, hit: Rect, action: A, selected: bool) { let s = self.register( WidgetId::new(&action),