You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by wy...@apache.org on 2026/09/24 14:46:19 UTC

(maka) branch feat/runtime-host-rust updated: feat(tui): anonymous connection setup as a sheet

This is an automated email from the ASF dual-hosted git repository.

M4n5ter pushed a commit to branch feat/runtime-host-rust
in repository https://gitbox.apache.org/repos/asf/maka.git


The following commit(s) were added to refs/heads/feat/runtime-host-rust by this push:
     new a0c9b9f20f feat(tui): anonymous connection setup as a sheet
a0c9b9f20f is described below

commit a0c9b9f20fa378cc85d70b496fc96f97fc03b097
Author: M4n5ter <m4...@gmail.com>
AuthorDate: Thu Sep 24 22:33:33 2026 +0800

    feat(tui): anonymous connection setup as a sheet
    
    - Adding an anonymous connection is a kernel sheet in two steps. The
      setup form picks the provider from a pop-up and fills labelled rows
      (name, configuration, connection ID), where Enter moves on and from
      the last to Verify. The models step is a [✓] checklist with Back
      (and Esc) to the form, Cancel and Save connection.
    - A request in flight no longer disables the form's controls, so the
      focus stays; using one while asking does nothing.
    - Labelled text rows are drawn by one shared helper (view::form), now
      also used by the OAuth connection details.
    - Kernel: an open chooser is modal over owner-drawn fields. Owners no
      longer take its keys or clicks (a choice over a field went to the
      field and left the chooser open), and it is painted again over what
      they draw.
    - Editors take only their own pointer events (a press or the wheel
      over them, or a drag they began), so passing over a field or
      releasing a press made elsewhere no longer moves the focus.
    - The hand-drawn form, its focus index, row cursor and input handler
      are gone; the tutorial part of the models note is dropped.
    
    Generated-by: Claude Code
---
 crates/cli/tests/integration/tui/onboarding.rs     |  29 +-
 crates/tui/locales/en.ftl                          |   2 +-
 crates/tui/locales/zh-CN.ftl                       |   2 +-
 crates/tui/locales/zh-TW.ftl                       |   2 +-
 crates/tui/src/editor.rs                           |  11 +
 crates/tui/src/overlay.rs                          |  21 +-
 crates/tui/src/pages/manage.rs                     |  23 +-
 crates/tui/src/pages/manage/enabled_models.rs      |  14 +-
 .../pages/manage/enabled_models/profile/view.rs    |  15 +-
 crates/tui/src/pages/manage/oauth/input.rs         |  14 +-
 crates/tui/src/pages/manage/oauth/view.rs          |  60 +---
 crates/tui/src/pages/onboarding.rs                 | 110 +++---
 crates/tui/src/pages/onboarding/input.rs           | 176 +++-------
 crates/tui/src/pages/onboarding/view.rs            | 384 +++++++++++----------
 crates/tui/src/pages/queue/edit.rs                 |  16 +-
 crates/tui/src/theme/editor.rs                     |  13 +-
 crates/tui/src/ui/sheet.rs                         |  19 +
 crates/tui/src/ui/surface.rs                       |  17 +
 crates/tui/src/view.rs                             |   1 +
 crates/tui/src/view/form.rs                        |  80 +++++
 20 files changed, 548 insertions(+), 461 deletions(-)

diff --git a/crates/cli/tests/integration/tui/onboarding.rs b/crates/cli/tests/integration/tui/onboarding.rs
index 1d500ee8fc..73261650b4 100644
--- a/crates/cli/tests/integration/tui/onboarding.rs
+++ b/crates/cli/tests/integration/tui/onboarding.rs
@@ -59,17 +59,26 @@ fn anonymous_setup_verifies_without_writes_and_creates_first_chat() {
     let providers = runtime
         .block_on(client.provider_directory(maka_protocol::model_provider::Scope::Profile))
         .unwrap();
-    for provider in providers
+    // The provider is chosen from its pop-up.
+    let label = &providers
         .entries
         .iter()
-        .filter(|entry| entry.descriptor.anonymous)
-    {
-        tui.wait_for(&provider.descriptor.label);
-        if provider.identity.name == "lm-studio" {
-            break;
-        }
-        tui.click_text(&provider.descriptor.label);
-    }
+        .find(|entry| entry.descriptor.anonymous && entry.identity.name == "lm-studio")
+        .unwrap()
+        .descriptor
+        .label;
+    tui.wait_for(" ▾");
+    tui.click_text(" ▾");
+    let choice = ["○", "●"].map(|marker| format!("{marker} {label}"));
+    tui.wait_until(|screen| choice.iter().any(|choice| screen.contains(choice)));
+    let shown = tui.screen.snapshot().unwrap().screen;
+    tui.click_text(
+        choice
+            .iter()
+            .find(|choice| shown.contains(*choice))
+            .unwrap(),
+    );
+    tui.wait_for(&format!("{label} ▾"));
     tui.click_text("Name (optional)");
     tui.send(b"New connection");
     tui.click_text("Configuration (JSON)");
@@ -91,7 +100,7 @@ fn anonymous_setup_verifies_without_writes_and_creates_first_chat() {
         "verification cannot leave a half-configured connection or credential"
     );
     tui.click_text("fixture-model");
-    tui.wait_for("[x] fixture-model");
+    tui.wait_for("[✓] fixture-model");
     tui.click_last_text("Save connection");
     tui.wait_until(|s| {
         !s.contains("Save connection")
diff --git a/crates/tui/locales/en.ftl b/crates/tui/locales/en.ftl
index 0d7673c39d..f13d6f464f 100644
--- a/crates/tui/locales/en.ftl
+++ b/crates/tui/locales/en.ftl
@@ -453,7 +453,7 @@ onboard-save = Save connection
 onboard-back = Back
 onboard-busy = Contacting the service…
 onboard-verify-note = Verification contacts the configured service without authentication. Nothing is saved yet.
-onboard-models-note = Space/click selects. If no Host default exists, the first selected model becomes default.
+onboard-models-note = If no Host default exists, the first selected model becomes default.
 onboard-field-invalid = Check this field's format or length.
 onboard-authentication-required = This service requires authentication. Use account setup instead.
 onboard-configuration-required = Complete the provider configuration.
diff --git a/crates/tui/locales/zh-CN.ftl b/crates/tui/locales/zh-CN.ftl
index 9087bc4483..6b54bf80f2 100644
--- a/crates/tui/locales/zh-CN.ftl
+++ b/crates/tui/locales/zh-CN.ftl
@@ -453,7 +453,7 @@ onboard-save = 保存连接
 onboard-back = 返回
 onboard-busy = 正在连接服务…
 onboard-verify-note = 验证会在不携带认证信息的情况下访问所配置的服务,尚不会保存配置。
-onboard-models-note = 空格或点击选择模型。若 Host 尚无默认模型,将使用所选的第一个模型。
+onboard-models-note = 若 Host 尚无默认模型,将使用所选的第一个模型。
 onboard-field-invalid = 请检查此项的格式或长度。
 onboard-authentication-required = 此服务需要认证,请改用账户设置。
 onboard-configuration-required = 请补全提供商配置。
diff --git a/crates/tui/locales/zh-TW.ftl b/crates/tui/locales/zh-TW.ftl
index 9f0c2ca760..6d3d8af873 100644
--- a/crates/tui/locales/zh-TW.ftl
+++ b/crates/tui/locales/zh-TW.ftl
@@ -453,7 +453,7 @@ onboard-save = 儲存連線
 onboard-back = 返回
 onboard-busy = 正在連線服務…
 onboard-verify-note = 驗證會在不攜帶認證資訊的情況下存取所設定的服務,尚不會儲存設定。
-onboard-models-note = 空白鍵或點擊選擇模型。若 Host 尚無預設模型,將使用所選的第一個模型。
+onboard-models-note = 若 Host 尚無預設模型,將使用所選的第一個模型。
 onboard-field-invalid = 請檢查此項的格式或長度。
 onboard-authentication-required = 此服務需要認證,請改用帳戶設定。
 onboard-configuration-required = 請補全供應商設定。
diff --git a/crates/tui/src/editor.rs b/crates/tui/src/editor.rs
index 1eb4285000..f55f725bab 100644
--- a/crates/tui/src/editor.rs
+++ b/crates/tui/src/editor.rs
@@ -149,6 +149,17 @@ impl Editor {
         self.dragging
     }
 
+    /// Whether a pointer event is this editor's: a press or the wheel over
+    /// it, or anything while it drags a selection it began. Passing over it
+    /// or releasing a press made elsewhere is not.
+    pub fn takes(&self, mouse: &MouseEvent) -> bool {
+        self.dragging
+            || (matches!(
+                mouse.kind,
+                MouseEventKind::Down(_) | MouseEventKind::ScrollUp | MouseEventKind::ScrollDown
+            ) && self.contains(Position::new(mouse.column, mouse.row)))
+    }
+
     fn reflow(&mut self) {
         self.layout = Layout::new(&self.text, self.layout.width);
     }
diff --git a/crates/tui/src/overlay.rs b/crates/tui/src/overlay.rs
index 893a46f267..fef7cefca2 100644
--- a/crates/tui/src/overlay.rs
+++ b/crates/tui/src/overlay.rs
@@ -115,6 +115,7 @@ impl App {
             Overlay::Branch => crate::pages::branch::sheet(self),
             Overlay::Skills => crate::pages::skills::sheet(self),
             Overlay::Theme => crate::theme::editor::sheet(self),
+            Overlay::Onboarding => crate::pages::onboarding::sheet(self),
             _ => None,
         }
     }
@@ -138,6 +139,11 @@ impl App {
                     editor.visible = shown;
                 }
             }
+            Overlay::Onboarding => {
+                if let Some(form) = &mut self.onboarding.dialog {
+                    form.visible = shown;
+                }
+            }
             _ => {}
         }
     }
@@ -183,10 +189,10 @@ impl App {
             | Overlay::Recap
             | Overlay::Branch
             | Overlay::Skills
-            | Overlay::Theme => unreachable!("presented as sheets"),
+            | Overlay::Theme
+            | Overlay::Onboarding => unreachable!("presented as sheets"),
             Overlay::Attachments => self.attachment_input(event),
             Overlay::Revision => self.revision_input(event),
-            Overlay::Onboarding => self.onboarding_input(event),
             Overlay::Interactions => self.interactions_overlay_input(event),
             Overlay::Palette => self.palette_input(event),
         }
@@ -201,12 +207,15 @@ impl App {
         let Some(dismiss) = overlay.dismiss() else {
             return (false, None);
         };
-        // The sheet's owner takes its fields' keys, pastes and pointer first.
+        // The sheet's owner takes its fields' keys, pastes and pointer first,
+        // unless a chooser is open over them.
         let owned = match overlay {
+            _ if self.layer.captures() => None,
             Overlay::Reference | Overlay::Management => self.management_sheet_input(&event),
             Overlay::QueueEdit => self.queue_edit_sheet_input(&event),
             Overlay::Skills => self.skills_sheet_input(&event),
             Overlay::Theme => self.theme_sheet_input(&event),
+            Overlay::Onboarding => self.onboarding_sheet_input(&event),
             _ => None,
         };
         if let Some(outcome) = owned {
@@ -290,8 +299,10 @@ pub(crate) fn draw(
             Overlay::Reference | Overlay::Management => pages::manage::draw_field(frame, app),
             Overlay::QueueEdit => pages::queue::edit::draw_field(frame, app),
             Overlay::Theme => crate::theme::editor::draw_field(frame, app),
+            Overlay::Onboarding => pages::onboarding::draw_field(frame, app),
             _ => {}
         }
+        app.layer.repaint_chooser(frame, context);
         if !shown {
             crate::view::clear_overlay(frame, area);
             frame.render_widget(
@@ -317,10 +328,10 @@ pub(crate) fn draw(
         | Overlay::Recap
         | Overlay::Branch
         | Overlay::Skills
-        | Overlay::Theme => unreachable!("presented as sheets"),
+        | Overlay::Theme
+        | Overlay::Onboarding => unreachable!("presented as sheets"),
         Overlay::Attachments => pages::attachments::draw(frame, app, area, base),
         Overlay::Revision => pages::revision::draw(frame, app, area, base),
-        Overlay::Onboarding => pages::onboarding::draw(frame, app, area, base),
         Overlay::Interactions => pages::interactions::draw(frame, app, area, base),
         Overlay::Palette => pages::commands::draw(frame, app, area, base),
     }
diff --git a/crates/tui/src/pages/manage.rs b/crates/tui/src/pages/manage.rs
index 1085edcf52..dce2a11e24 100644
--- a/crates/tui/src/pages/manage.rs
+++ b/crates/tui/src/pages/manage.rs
@@ -1335,11 +1335,10 @@ impl App {
                 {
                     Some((dialog.editor.key(*key), None))
                 }
-                Event::Mouse(mouse)
-                    if dialog.editor.contains((mouse.column, mouse.row).into())
-                        || dialog.editor.dragging() =>
-                {
-                    self.layer.focus("field");
+                Event::Mouse(mouse) if dialog.editor.takes(mouse) => {
+                    if matches!(mouse.kind, crossterm::event::MouseEventKind::Down(_)) {
+                        self.layer.focus("field");
+                    }
                     Some((dialog.editor.mouse(*mouse), None))
                 }
                 _ => None,
@@ -1383,14 +1382,12 @@ impl App {
                 }
                 Some((dialog.editor.insert(&text.replace(['\n', '\r'], " ")), None))
             }
-            Event::Mouse(mouse)
-                if dialog
-                    .editor
-                    .contains(ratatui::layout::Position::new(mouse.column, mouse.row))
-                    || dialog.editor.dragging() =>
-            {
-                self.layer.focus("field");
-                Some((dialog.editor.mouse(*mouse) || !focused, None))
+            Event::Mouse(mouse) if dialog.editor.takes(mouse) => {
+                let press = matches!(mouse.kind, crossterm::event::MouseEventKind::Down(_));
+                if press {
+                    self.layer.focus("field");
+                }
+                Some((dialog.editor.mouse(*mouse) || (press && !focused), None))
             }
             _ => None,
         }
diff --git a/crates/tui/src/pages/manage/enabled_models.rs b/crates/tui/src/pages/manage/enabled_models.rs
index e9d3e86cd9..1f11e11f61 100644
--- a/crates/tui/src/pages/manage/enabled_models.rs
+++ b/crates/tui/src/pages/manage/enabled_models.rs
@@ -334,14 +334,12 @@ impl App {
                 }
                 Some((state.search.insert(text), None))
             }
-            Event::Mouse(mouse)
-                if state
-                    .search
-                    .contains(ratatui::layout::Position::new(mouse.column, mouse.row))
-                    || state.search.dragging() =>
-            {
-                self.layer.focus("search");
-                Some((state.search.mouse(*mouse) || !focused, None))
+            Event::Mouse(mouse) if state.search.takes(mouse) => {
+                let press = matches!(mouse.kind, crossterm::event::MouseEventKind::Down(_));
+                if press {
+                    self.layer.focus("search");
+                }
+                Some((state.search.mouse(*mouse) || (press && !focused), None))
             }
             _ => None,
         }
diff --git a/crates/tui/src/pages/manage/enabled_models/profile/view.rs b/crates/tui/src/pages/manage/enabled_models/profile/view.rs
index 535221eeed..7347a73b99 100644
--- a/crates/tui/src/pages/manage/enabled_models/profile/view.rs
+++ b/crates/tui/src/pages/manage/enabled_models/profile/view.rs
@@ -370,15 +370,14 @@ pub(in crate::pages::manage::enabled_models) fn input(
         Event::Mouse(mouse) => {
             let point = Position::new(mouse.column, mouse.row);
             let fields = draft.fields.clone();
-            if let Some(text) = draft
-                .texts
-                .iter_mut()
-                .find(|text| text.editor.contains(point) || text.editor.dragging())
-            {
+            if let Some(text) = draft.texts.iter_mut().find(|text| text.editor.takes(mouse)) {
                 let index = fields.iter().position(|field| *field == text.field)?;
-                text.editor.mouse(*mouse);
-                app.layer.focus_path(&format!("{ROWS}/{index}"));
-                return Some((true, None));
+                let changed = text.editor.mouse(*mouse);
+                if matches!(mouse.kind, MouseEventKind::Down(_)) {
+                    app.layer.focus_path(&format!("{ROWS}/{index}"));
+                    return Some((true, None));
+                }
+                return Some((changed, None));
             }
             if mouse.kind != MouseEventKind::Down(MouseButton::Left) {
                 return None;
diff --git a/crates/tui/src/pages/manage/oauth/input.rs b/crates/tui/src/pages/manage/oauth/input.rs
index 24399a9f6a..1f0cc2d892 100644
--- a/crates/tui/src/pages/manage/oauth/input.rs
+++ b/crates/tui/src/pages/manage/oauth/input.rs
@@ -21,9 +21,8 @@ use super::{
     Command,
     view::{row, row_path},
 };
-use crate::{app::App, editor::Editor};
+use crate::app::App;
 use crossterm::event::{Event, KeyCode, KeyEventKind, KeyModifiers, MouseButton, MouseEventKind};
-use ratatui::layout::Position;
 
 /// Keys, pastes and pointer presses the connection details rows take before
 /// the sheet: a focused row edits its field, Enter moves on to the next row
@@ -80,12 +79,13 @@ pub(in crate::pages::manage) fn sheet_input(
             Some((true, None))
         }
         Event::Mouse(mouse) => {
-            let point = Position::new(mouse.column, mouse.row);
-            let fields = &app.management.oauth.identity.fields;
-            let index = fields
+            let index = app
+                .management
+                .oauth
+                .identity
+                .fields
                 .iter()
-                .position(Editor::dragging)
-                .or_else(|| fields.iter().position(|editor| editor.contains(point)))
+                .position(|editor| editor.takes(mouse))
                 .filter(|index| app.oauth_enabled(Command::Field(*index)))?;
             let changed = app.management.oauth.identity.fields[index].mouse(*mouse);
             if mouse.kind == MouseEventKind::Down(MouseButton::Left) {
diff --git a/crates/tui/src/pages/manage/oauth/view.rs b/crates/tui/src/pages/manage/oauth/view.rs
index eb899e5b52..a3443eccbd 100644
--- a/crates/tui/src/pages/manage/oauth/view.rs
+++ b/crates/tui/src/pages/manage/oauth/view.rs
@@ -21,10 +21,10 @@ use super::{Command, Manage, State};
 use crate::{
     app::{Action, App},
     ui::{self, Node, On, Role, Sheet, Size, Tone},
-    view::{safe, tone},
+    view::safe,
 };
 use maka_protocol::oauth::Phase;
-use ratatui::{Frame, layout::Rect, style::Style, widgets::Paragraph};
+use ratatui::Frame;
 use unicode_width::UnicodeWidthStr;
 
 /// The connection details rows, one per field index.
@@ -57,15 +57,14 @@ fn label(app: &App, state: &State, index: usize) -> String {
 /// reads as a single aligned column.
 fn label_width(app: &App) -> u16 {
     let state = &app.management.oauth;
-    let width = ui::content_width(app.frame_size.map_or(80, |(width, _)| width));
-    let widest = state
-        .fields()
-        .filter(|_| state.identity.expanded)
-        .map(|index| label(app, state, index).width())
-        .chain([app.i18n.text("onboard-provider").width()])
-        .max()
-        .unwrap_or(0) as u16;
-    (widest + 2).min(width * 2 / 5)
+    crate::view::form::label_width(
+        state
+            .fields()
+            .filter(|_| state.identity.expanded)
+            .map(|index| label(app, state, index).width())
+            .chain([app.i18n.text("onboard-provider").width()]),
+        app.frame_size.map_or(80, |(width, _)| width),
+    )
 }
 
 /// Signing in: choose a provider and method (and, optionally, how the
@@ -287,37 +286,12 @@ pub(in crate::pages::manage) fn draw(frame: &mut Frame<'_>, app: &mut App) {
             continue;
         };
         let here = enabled && focused == Some(index);
-        let label_rect = Rect::new(rect.x, rect.y, width.min(rect.width), 1);
-        frame.buffer_mut().set_style(label_rect, colors.base());
-        frame.render_widget(
-            Paragraph::new(label).style(Style::default().fg(if here {
-                tone::accent(colors)
-            } else {
-                colors.muted
-            })),
-            Rect::new(
-                label_rect.x,
-                label_rect.y,
-                label_rect.width.saturating_sub(1),
-                1,
-            ),
-        );
-        let value = Rect::new(
-            rect.x + label_rect.width,
-            rect.y,
-            rect.width.saturating_sub(label_rect.width),
-            1,
-        );
-        if index == 3 {
-            field.draw_masked(frame, value, here, colors);
-        } else {
-            field.draw(frame, value, here, colors);
-        }
-        if index < 2 && field.text().is_empty() && !here {
-            frame.render_widget(
-                Paragraph::new(default.as_str()).style(Style::default().fg(colors.subtle)),
-                value,
-            );
-        }
+        let row = crate::view::form::Row {
+            label: &label,
+            focused: here,
+            masked: index == 3,
+            placeholder: (index < 2).then_some(default.as_str()),
+        };
+        crate::view::form::draw(frame, rect, width, row, field, colors);
     }
 }
diff --git a/crates/tui/src/pages/onboarding.rs b/crates/tui/src/pages/onboarding.rs
index 88701cf8e8..407c81b360 100644
--- a/crates/tui/src/pages/onboarding.rs
+++ b/crates/tui/src/pages/onboarding.rs
@@ -19,7 +19,7 @@
 
 mod input;
 mod view;
-pub use view::draw;
+pub(crate) use view::{draw_field, sheet};
 
 use crate::{
     app::{Action, App, ConnectionState},
@@ -33,7 +33,8 @@ use std::collections::BTreeSet;
 pub enum Command {
     Open,
     Close,
-    Provider,
+    Provider(usize),
+    /// Focuses a setup field.
     Field(usize),
     Verify,
     Toggle(String),
@@ -45,7 +46,7 @@ impl Command {
         match self {
             Self::Open => "onboard-title",
             Self::Close => "session-cancel",
-            Self::Provider => "onboard-provider",
+            Self::Provider(_) => "onboard-provider",
             Self::Field(_) => "onboard-title",
             Self::Verify => "onboard-verify",
             Self::Toggle(_) => "onboard-models",
@@ -107,16 +108,11 @@ pub struct Form {
     fields: [Editor; 3],
     models: Option<Vec<ModelInfo>>,
     selected: BTreeSet<String>,
-    row: usize,
-    focus: usize,
     pub visible: bool,
     blocked: bool,
     error: Option<&'static str>,
 }
 impl Form {
-    fn count(&self) -> usize {
-        if self.models.is_some() { 4 } else { 6 }
-    }
     fn input(&self) -> OnboardingInput {
         let provider = &self.providers[self.provider];
         let name = self.fields[0].text().trim();
@@ -151,6 +147,15 @@ impl App {
                 && !self.interactions.visible
                 && self.queue.edit.is_none();
         }
+        if self.onboarding.dialog.is_some() && *c == Command::Close {
+            return !self.onboarding.pending.as_ref().is_some_and(|p| p.save);
+        }
+        self.onboarding.pending.is_none() && self.onboarding_offered(c)
+    }
+    /// Whether the form offers `c`, before a request in flight is
+    /// considered: its control (and the focus on it) stays while the service
+    /// is asked, and using it then does nothing.
+    pub(super) fn onboarding_offered(&self, c: &Command) -> bool {
         let Some(form) = &self.onboarding.dialog else {
             return false;
         };
@@ -158,12 +163,7 @@ impl App {
             return !self.onboarding.pending.as_ref().is_some_and(|p| p.save);
         }
         let identity = matches!(&self.connection,ConnectionState::Connected{root_id,epoch} if *root_id==form.ticket.root && *epoch==form.ticket.epoch);
-        if !form.visible
-            || form.blocked
-            || !identity
-            || form.providers.is_empty()
-            || self.onboarding.pending.is_some()
-        {
+        if !form.visible || form.blocked || !identity || form.providers.is_empty() {
             return false;
         }
         match c {
@@ -189,7 +189,7 @@ impl App {
                 .is_some_and(|m| m.iter().any(|m| m.id == *id)),
             Command::Back => form.models.is_some(),
             Command::Field(index) => form.models.is_none() && *index < 3,
-            Command::Provider => form.models.is_none(),
+            Command::Provider(index) => form.models.is_none() && *index < form.providers.len(),
             _ => false,
         }
     }
@@ -217,8 +217,6 @@ impl App {
                     ],
                     models: None,
                     selected: BTreeSet::new(),
-                    row: 0,
-                    focus: 0,
                     visible: false,
                     blocked: false,
                     error: None,
@@ -234,8 +232,11 @@ impl App {
                 };
                 f.error = None;
                 match c {
-                    Command::Provider => {
-                        f.provider = (f.provider + 1) % f.providers.len();
+                    Command::Provider(index) => {
+                        if index == f.provider {
+                            return None;
+                        }
+                        f.provider = index;
                         f.fields[1] = Editor::bounded(64 * 1024, "onboard-field-invalid");
                         f.fields[1].insert(
                             &f.providers[f.provider]
@@ -243,9 +244,8 @@ impl App {
                                 .configuration_defaults
                                 .to_string(),
                         );
-                        f.focus = 0;
                     }
-                    Command::Field(index) => f.focus = index + 1,
+                    Command::Field(index) => self.layer.focus_path(&view::row_path(index)),
                     Command::Toggle(id) => {
                         if !f.selected.contains(&id) && f.selected.len() >= 512 {
                             f.error = Some("onboard-model-limit");
@@ -254,21 +254,15 @@ impl App {
                         if !f.selected.remove(&id) {
                             f.selected.insert(id.clone());
                         }
-                        if let Some(models) = &f.models {
-                            f.row = models.iter().position(|m| m.id == id).unwrap_or(0);
-                        }
-                        f.focus = 0;
                     }
                     Command::Back => {
                         f.models = None;
                         f.selected.clear();
-                        f.focus = 0;
                     }
                     _ => {}
                 }
             }
         }
-        self.hits.clear();
         None
     }
     pub fn onboarding_catalog_loaded(&mut self) {
@@ -336,8 +330,6 @@ impl App {
             Ok(ResultValue::Verified(OnboardingVerifyResult::Verified { models })) => {
                 f.models = Some(models);
                 f.selected.clear();
-                f.row = 0;
-                f.focus = 0;
                 f.error = None;
             }
             Ok(ResultValue::Saved(OnboardingSaveResult::Saved { .. })) => {
@@ -548,7 +540,7 @@ mod tests {
         );
         terminal.draw(|f| crate::view::draw(f, &mut app)).unwrap();
         app.input(Event::Key(KeyEvent::new(KeyCode::End, KeyModifiers::NONE)));
-        assert_eq!(app.onboarding.dialog.as_ref().unwrap().row, 1);
+        assert_eq!(app.layer.focused_path(), Some("list/rows/1"));
         app.input(Event::Mouse(MouseEvent {
             kind: MouseEventKind::ScrollUp,
             column: 0,
@@ -556,8 +548,8 @@ mod tests {
             modifiers: KeyModifiers::NONE,
         }));
         assert_eq!(
-            app.onboarding.dialog.as_ref().unwrap().row,
-            1,
+            app.layer.focused_path(),
+            Some("list/rows/1"),
             "wheel outside the modal cannot move its model list"
         );
         app.input(Event::Key(KeyEvent::new(KeyCode::Home, KeyModifiers::NONE)));
@@ -565,12 +557,7 @@ mod tests {
             !app.onboarding_enabled(&Command::Save),
             "no silent enable-all default"
         );
-        let hit = app
-            .hits
-            .iter()
-            .find(|h| h.action == Action::Onboard(Command::Toggle("model".into())))
-            .unwrap()
-            .area;
+        let hit = app.layer.rect("list/rows/0").unwrap();
         app.input(Event::Mouse(MouseEvent {
             kind: MouseEventKind::Down(MouseButton::Left),
             column: hit.x,
@@ -579,13 +566,7 @@ mod tests {
         }));
         assert!(app.onboarding_enabled(&Command::Save));
         terminal.draw(|f| crate::view::draw(f, &mut app)).unwrap();
-        let save_y = app
-            .hits
-            .iter()
-            .find(|h| h.action == Action::Onboard(Command::Save))
-            .unwrap()
-            .area
-            .y;
+        let save_y = app.layer.rect("footer/save").unwrap().y;
         assert!(
             save_y - hit.y < 10,
             "small model inventories keep a compact dialog"
@@ -603,6 +584,7 @@ mod tests {
                 models: vec![model],
             })),
         );
+        terminal.draw(|f| crate::view::draw(f, &mut app)).unwrap();
         app.input(Event::Key(KeyEvent::new(
             KeyCode::Char(' '),
             KeyModifiers::NONE,
@@ -637,4 +619,42 @@ mod tests {
         app.abandon_onboarding();
         assert!(app.onboarding.dialog.as_ref().unwrap().blocked);
     }
+
+    #[test]
+    fn a_chooser_open_over_a_field_takes_the_click() {
+        let mut app = App::new(
+            "/unused".into(),
+            I18n::new(LocalePreference::Explicit(Locale::En), Locale::En),
+        );
+        app.connection = ConnectionState::Connected {
+            root_id: "root".into(),
+            epoch: "epoch".into(),
+        };
+        app.providers = crate::providers::fixtures::catalog();
+        app.apply(Action::Onboard(Command::Open));
+        let mut terminal = Terminal::new(TestBackend::new(80, 24)).unwrap();
+        terminal.draw(|f| crate::view::draw(f, &mut app)).unwrap();
+        app.layer.focus_path("form/provider");
+        app.input(Event::Key(KeyEvent::new(
+            KeyCode::Enter,
+            KeyModifiers::NONE,
+        )));
+        terminal.draw(|f| crate::view::draw(f, &mut app)).unwrap();
+        assert!(app.layer.captures());
+        // The chooser's first row lies over the configuration field.
+        let owner = app.layer.rect("form/provider").unwrap();
+        for kind in [
+            MouseEventKind::Down(MouseButton::Left),
+            MouseEventKind::Up(MouseButton::Left),
+        ] {
+            app.input(Event::Mouse(MouseEvent {
+                kind,
+                column: owner.right() - 3,
+                row: owner.y + 2,
+                modifiers: KeyModifiers::NONE,
+            }));
+        }
+        assert!(!app.layer.captures(), "the choice was made");
+        assert_eq!(app.layer.focused_path(), Some("form/provider"));
+    }
 }
diff --git a/crates/tui/src/pages/onboarding/input.rs b/crates/tui/src/pages/onboarding/input.rs
index a7b3bdbffa..70a07b74f0 100644
--- a/crates/tui/src/pages/onboarding/input.rs
+++ b/crates/tui/src/pages/onboarding/input.rs
@@ -17,145 +17,73 @@
  * under the License.
  */
 
-use super::{Action, App, Command};
+use super::{
+    Action, App, Command,
+    view::{row, row_path},
+};
 use crossterm::event::{Event, KeyCode, KeyEventKind, KeyModifiers, MouseButton, MouseEventKind};
 
 impl App {
-    pub fn onboarding_input(&mut self, event: Event) -> (bool, Option<Action>) {
-        let page_size = self
-            .hits
-            .iter()
-            .filter(|h| matches!(h.action, Action::Onboard(Command::Toggle(_))))
-            .count()
-            .max(1);
-        let f = self.onboarding.dialog.as_mut().expect("onboarding form");
-        let editable =
-            f.visible && !f.blocked && !f.providers.is_empty() && self.onboarding.pending.is_none();
-        let command = match event {
-            Event::Key(key) if key.kind != KeyEventKind::Release => match key.code {
-                KeyCode::Char('q') if key.modifiers.contains(KeyModifiers::CONTROL) => {
-                    return (true, Some(Action::Quit));
-                }
-                KeyCode::Esc => Some(Command::Close),
-                _ if !editable => None,
-                KeyCode::Tab => {
-                    f.focus = (f.focus + 1) % f.count();
-                    return (true, None);
-                }
-                KeyCode::BackTab => {
-                    f.focus = (f.focus + f.count() - 1) % f.count();
-                    return (true, None);
+    /// The setup form's rows take their keys, pastes and pointer before the
+    /// sheet: Enter moves on to the next row and from the last to Verify.
+    pub(crate) fn onboarding_sheet_input(
+        &mut self,
+        event: &Event,
+    ) -> Option<(bool, Option<Action>)> {
+        if !self.onboarding_enabled(&Command::Field(0)) {
+            return None;
+        }
+        let focused = self.layer.focused_path().and_then(row);
+        let f = self.onboarding.dialog.as_mut()?;
+        match event {
+            Event::Key(key) if key.kind != KeyEventKind::Release => {
+                let index = focused?;
+                if matches!(
+                    key.code,
+                    KeyCode::Esc | KeyCode::Tab | KeyCode::BackTab | KeyCode::Up | KeyCode::Down
+                ) || (key.modifiers.contains(KeyModifiers::CONTROL)
+                    && key.code == KeyCode::Char('q'))
+                {
+                    return None;
                 }
-                KeyCode::Enter => Some(if f.models.is_some() {
-                    match f.focus {
-                        1 => Command::Back,
-                        2 => Command::Close,
-                        _ => Command::Save,
+                if key.code == KeyCode::Enter {
+                    if index + 1 < f.fields.len() {
+                        self.layer.focus_path(&row_path(index + 1));
+                    } else if self.onboarding_enabled(&Command::Verify) {
+                        self.layer.focus_path("footer/verify");
                     }
-                } else {
-                    match f.focus {
-                        0 => Command::Provider,
-                        5 => Command::Close,
-                        _ => Command::Verify,
-                    }
-                }),
-                KeyCode::Up | KeyCode::Down if f.models.is_some() && f.focus == 0 => {
-                    let n = f.models.as_ref().unwrap().len();
-                    f.row = if key.code == KeyCode::Up {
-                        f.row.saturating_sub(1)
-                    } else {
-                        (f.row + 1).min(n.saturating_sub(1))
-                    };
-                    return (true, None);
+                    return Some((true, None));
                 }
-                KeyCode::Home | KeyCode::End | KeyCode::PageUp | KeyCode::PageDown
-                    if f.models.is_some() && f.focus == 0 =>
-                {
-                    let last = f.models.as_ref().unwrap().len().saturating_sub(1);
-                    f.row = match key.code {
-                        KeyCode::Home => 0,
-                        KeyCode::End => last,
-                        KeyCode::PageUp => f.row.saturating_sub(page_size),
-                        _ => f.row.saturating_add(page_size).min(last),
-                    };
-                    return (true, None);
+                if matches!(key.code, KeyCode::Char(c) if c.is_control()) {
+                    return Some((false, None));
                 }
-                KeyCode::Char(' ') if f.models.is_some() && f.focus == 0 => f
-                    .models
-                    .as_ref()
-                    .and_then(|m| m.get(f.row))
-                    .map(|m| Command::Toggle(m.id.clone())),
-                _ if f.models.is_none() && (1..=3).contains(&f.focus) => {
-                    if matches!(key.code,KeyCode::Char(c) if c.is_control()) {
-                        return (false, None);
-                    }
-                    let changed = f.fields[f.focus - 1].key(key);
-                    if changed {
-                        f.error = None;
-                    }
-                    return (changed, None);
+                let changed = f.fields[index].key(*key);
+                if changed {
+                    f.error = None;
                 }
-                _ => None,
-            },
-            Event::Paste(text) if editable && f.models.is_none() && (1..=3).contains(&f.focus) => {
-                if f.focus != 2 && text.chars().any(char::is_control) {
+                Some((changed, None))
+            }
+            Event::Paste(text) => {
+                let index = focused?;
+                // Only the configuration is JSON; the rest are one line.
+                if index != 1 && text.chars().any(char::is_control) {
                     f.error = Some("onboard-field-invalid");
-                    return (true, None);
+                    return Some((true, None));
                 }
-                let changed = f.fields[f.focus - 1].insert(&text);
+                let changed = f.fields[index].insert(text);
                 f.error = None;
-                return (changed, None);
+                Some((changed, None))
             }
-            Event::Mouse(mouse) if f.visible => {
-                if matches!(
-                    mouse.kind,
-                    MouseEventKind::ScrollUp | MouseEventKind::ScrollDown
-                ) && editable
-                    && let Some(models) = &f.models
-                    && self.hits.iter().any(|h| {
-                        h.area.contains((mouse.column, mouse.row).into())
-                            && matches!(h.action, Action::Onboard(Command::Toggle(_)))
-                    })
-                {
-                    let n = models.len();
-                    f.row = if mouse.kind == MouseEventKind::ScrollUp {
-                        f.row.saturating_sub(1)
-                    } else {
-                        (f.row + 1).min(n.saturating_sub(1))
-                    };
-                    f.focus = 0;
-                    return (true, None);
-                }
-                if editable && f.models.is_none() {
-                    for (index, editor) in f.fields.iter_mut().enumerate() {
-                        if editor.contains((mouse.column, mouse.row).into()) || editor.dragging() {
-                            f.focus = index + 1;
-                            let changed = editor.mouse(mouse);
-                            return (
-                                changed || matches!(mouse.kind, MouseEventKind::Down(_)),
-                                None,
-                            );
-                        }
-                    }
-                }
+            Event::Mouse(mouse) => {
+                let index = f.fields.iter().position(|editor| editor.takes(mouse))?;
+                let changed = f.fields[index].mouse(*mouse);
                 if mouse.kind == MouseEventKind::Down(MouseButton::Left) {
-                    self.hits
-                        .iter()
-                        .rev()
-                        .find(|h| h.area.contains((mouse.column, mouse.row).into()))
-                        .and_then(|h| match &h.action {
-                            Action::Onboard(c) => Some(c.clone()),
-                            _ => None,
-                        })
-                } else {
-                    None
+                    self.layer.focus_path(&row_path(index));
+                    return Some((true, None));
                 }
+                Some((changed, None))
             }
             _ => None,
-        };
-        (
-            command.is_some(),
-            command.and_then(|c| self.apply(Action::Onboard(c))),
-        )
+        }
     }
 }
diff --git a/crates/tui/src/pages/onboarding/view.rs b/crates/tui/src/pages/onboarding/view.rs
index 89f2bdfb9c..efcd7d1489 100644
--- a/crates/tui/src/pages/onboarding/view.rs
+++ b/crates/tui/src/pages/onboarding/view.rs
@@ -19,208 +19,232 @@
 
 use super::Command;
 use crate::{
-    app::{Action, App, Hit},
-    view::{button, safe},
-};
-use ratatui::{
-    Frame,
-    layout::{Margin, Rect},
-    style::Style,
-    widgets::{Block, Borders, Paragraph, Wrap},
+    app::{Action, App},
+    ui::{self, Node, On, Role, Sheet, Size, Tone},
+    view::{form, safe},
 };
+use ratatui::Frame;
 use unicode_width::UnicodeWidthStr;
 
-pub fn draw(frame: &mut Frame<'_>, app: &mut App, area: Rect, base: Style) {
-    app.hits.clear();
-    let availability = if app.providers.loading() {
-        "providers-loading"
-    } else if app.providers.failed() {
-        "providers-failed"
+/// The setup form's rows, one per field index.
+const FORM: &str = "form";
+const MODELS: &str = "list/rows";
+const LABELS: [&str; 3] = ["onboard-name", "oauth-configuration", "oauth-slug"];
+
+pub(super) fn row_path(index: usize) -> String {
+    format!("{FORM}/{index}")
+}
+
+/// The setup row a focus path points into.
+pub(super) fn row(path: &str) -> Option<usize> {
+    path.strip_prefix(FORM)?.strip_prefix('/')?.parse().ok()
+}
+
+fn action(command: Command) -> Action {
+    Action::Onboard(command)
+}
+
+fn label_width(app: &App) -> u16 {
+    form::label_width(
+        LABELS
+            .iter()
+            .chain(["onboard-provider"].iter())
+            .map(|key| app.i18n.text(key).width()),
+        app.frame_size.map_or(80, |(width, _)| width),
+    )
+}
+
+/// Adding an anonymous connection: choose the provider and fill in the form,
+/// Verify contacts the service, then choose its models and Save. Back (or
+/// Esc) returns to the form from the models.
+pub(crate) fn sheet(app: &App) -> Option<Sheet<Action>> {
+    let f = app.onboarding.dialog.as_ref()?;
+    let step = if f.models.is_some() {
+        "models"
+    } else if f.providers.is_empty() {
+        "loading"
     } else {
-        "onboard-no-providers"
+        "setup"
     };
-    let f = app.onboarding.dialog.as_mut().expect("onboarding form");
-    let busy = app.onboarding.pending.is_some() || f.providers.is_empty();
-    if area.width < 44 || area.height < 22 {
-        f.visible = false;
-        for field in &mut f.fields {
-            field.invalidate_geometry();
-        }
-        crate::view::clear_overlay(frame, area);
-        frame.render_widget(
-            Paragraph::new(app.i18n.text("terminal-small")).wrap(Wrap { trim: false }),
-            area.inner(Margin::new(1, 1)),
-        );
-        return;
-    }
-    f.visible = true;
-    let width = area.width.saturating_sub(2).min(76);
-    let height = area.height.saturating_sub(2).min(
-        f.models
-            .as_ref()
-            .map_or(20, |models| (models.len().min(16) as u16 + 10).max(12)),
-    );
-    let popup = Rect::new(
-        area.x + (area.width - width) / 2,
-        area.y + (area.height - height) / 2,
-        width,
-        height,
+    let mut sheet = Sheet::new(
+        format!("onboard:{}:{step}", f.ticket.generation),
+        app.i18n.text("onboard-title"),
     );
-    let block = Block::bordered()
-        .title(app.i18n.text("onboard-title"))
-        .style(base)
-        .border_type(if app.chrome.ascii {
-            ratatui::widgets::BorderType::Plain
-        } else {
-            ratatui::widgets::BorderType::Rounded
-        })
-        .border_style(Style::default().fg(app.theme.colors().subtle));
-    let inner = block.inner(popup).inner(Margin::new(1, 0));
-    app.modal_area = Some(popup);
-    crate::view::clear_overlay(frame, popup);
-    frame.render_widget(block, popup);
-    let focus = f.focus;
-    let models = f.models.is_some();
     let error = f.error.or_else(|| f.fields.iter().find_map(|e| e.error));
-    if let Some(list) = &f.models {
-        frame.render_widget(
-            Paragraph::new(app.i18n.text("onboard-models")),
-            Rect::new(inner.x, inner.y, inner.width, 1),
-        );
-        let visible = inner.height.saturating_sub(7) as usize;
-        let start = (f.row + 1).saturating_sub(visible);
-        for (index, model) in list.iter().enumerate().skip(start).take(visible) {
-            let selected = f.selected.contains(&model.id);
-            let name = model.display_name.as_deref().unwrap_or(&model.id);
-            let marker = if selected { "[x]" } else { "[ ]" };
-            let label = if name == model.id {
-                safe(name)
-            } else {
-                format!("{} · {}", safe(name), safe(&model.id))
-            };
-            let text = format!("{marker} {label}");
-            let rect = Rect::new(
-                inner.x,
-                inner.y + 2 + (index - start) as u16,
-                inner.width,
-                1,
-            );
-            frame.render_widget(
-                Paragraph::new(text).style(
-                    if !busy && !f.blocked && focus == 0 && index == f.row {
-                        app.theme.colors().selected()
-                    } else {
-                        Style::default()
-                    },
-                ),
-                rect,
+    if let Some(models) = &f.models {
+        let rows = models
+            .iter()
+            .enumerate()
+            .map(|(index, model)| {
+                let mark = if f.selected.contains(&model.id) {
+                    app.chrome.symbol("✓", "x")
+                } else {
+                    " "
+                };
+                let name = model.display_name.as_deref().unwrap_or(&model.id);
+                let label = if name == model.id {
+                    safe(name)
+                } else {
+                    format!("{} · {}", safe(name), safe(&model.id))
+                };
+                let toggle = Command::Toggle(model.id.clone());
+                Node::text(
+                    index.to_string(),
+                    vec![(format!("[{mark}] {label}"), Tone::Normal)],
+                )
+                .clip()
+                .enabled(app.onboarding_offered(&toggle))
+                .on(On::Activate(action(toggle)))
+            })
+            .collect();
+        let height = app.frame_size.map_or(24, |(_, height)| height);
+        sheet = sheet
+            .text("heading", &app.i18n.text("onboard-models"), Tone::Normal)
+            .body(
+                Node::scroll("list", Node::column("rows", rows))
+                    .size(Size::Upto(height.saturating_sub(14).max(3))),
             );
-            if !busy && !f.blocked {
-                app.hits.push(Hit {
-                    area: rect,
-                    action: Action::Onboard(Command::Toggle(model.id.clone())),
-                });
-            }
-        }
     } else {
-        frame.render_widget(
-            Paragraph::new(app.i18n.text("onboard-provider"))
-                .style(Style::default().fg(app.theme.colors().subtle)),
-            Rect::new(inner.x, inner.y, inner.width, 1),
-        );
-        for (index, key) in ["onboard-name", "oauth-configuration", "oauth-slug"]
-            .into_iter()
+        let provider = f.providers.get(f.provider);
+        let choices = f
+            .providers
+            .iter()
             .enumerate()
-        {
-            let y = inner.y + 3 + index as u16 * 3;
-            frame.render_widget(
-                Paragraph::new(app.i18n.text(key))
-                    .style(Style::default().fg(app.theme.colors().subtle)),
-                Rect::new(inner.x, y, inner.width, 1),
-            );
-            let rect = Rect::new(inner.x, y + 1, inner.width, 1);
-            frame.render_widget(
-                Block::default()
-                    .borders(Borders::BOTTOM)
-                    .border_style(Style::default().fg(
-                        if focus == index + 1 && !busy && !f.blocked {
-                            app.theme.colors().accent
-                        } else {
-                            app.theme.colors().subtle
-                        },
-                    )),
-                Rect::new(rect.x, rect.y, rect.width, 2),
-            );
-            let field = &mut f.fields[index];
-            field.draw(
-                frame,
-                rect,
-                focus == index + 1 && !busy && !f.blocked,
-                app.theme.colors(),
-            );
-            if !busy && !f.blocked {
-                app.hits.push(Hit {
-                    area: Rect::new(rect.x, rect.y - 1, rect.width, 2),
-                    action: Action::Onboard(Command::Field(index)),
-                });
-            }
-        }
+            .map(|(index, provider)| ui::Choice {
+                label: provider.descriptor.label.clone(),
+                action: action(Command::Provider(index)),
+            })
+            .collect();
+        let enabled = app.onboarding_offered(&Command::Provider(f.provider));
+        let mut rows = vec![
+            Node::row(
+                "provider",
+                vec![
+                    Node::text(
+                        "label",
+                        vec![(app.i18n.text("onboard-provider"), Tone::Muted)],
+                    )
+                    .clip()
+                    .size(Size::Fixed(label_width(app))),
+                    Node::text(
+                        "value",
+                        vec![(
+                            provider.map_or_else(
+                                || app.i18n.text(availability(app)),
+                                |provider| {
+                                    format!(
+                                        "{} {}",
+                                        safe(&provider.descriptor.label),
+                                        app.chrome.symbol("▾", "v")
+                                    )
+                                },
+                            ),
+                            if enabled { Tone::Accent } else { Tone::Subtle },
+                        )],
+                    )
+                    .clip()
+                    .size(Size::Fill),
+                ],
+            )
+            .on(On::Choose {
+                choices,
+                current: Some(f.provider),
+            })
+            .enabled(enabled),
+        ];
+        rows.extend((0..LABELS.len()).map(|index| {
+            Node::slot(index.to_string(), 1)
+                .on(On::Activate(action(Command::Field(index))))
+                .enabled(app.onboarding_offered(&Command::Field(index)))
+        }));
+        sheet = sheet.body(Node::column(FORM, rows));
     }
     let key = if f.providers.is_empty() {
-        availability
-    } else if busy {
+        availability(app)
+    } else if app.onboarding.pending.is_some() {
         "onboard-busy"
     } else {
-        error.unwrap_or(if models {
+        error.unwrap_or(if f.models.is_some() {
             "onboard-models-note"
         } else {
             "onboard-verify-note"
         })
     };
-    frame.render_widget(
-        Paragraph::new(crate::pages::manage::view::note_lines(
-            &app.i18n.text(key),
-            inner.width,
-        ))
-        .style(Style::default().fg(if error.is_some() {
-            app.theme.colors().warning
+    sheet = sheet.text(
+        "note",
+        &app.i18n.text(key),
+        if error.is_some() {
+            Tone::Warning
         } else {
-            app.theme.colors().subtle
-        })),
-        Rect::new(inner.x, inner.bottom() - 5, inner.width, 3),
-    );
-    let provider = f.providers.get(f.provider).map_or_else(
-        || app.i18n.text(availability),
-        |provider| safe(&provider.descriptor.label),
+            Tone::Subtle
+        },
     );
-    if !models {
-        crate::view::list_item(
-            frame,
-            app,
-            Rect::new(inner.x, inner.y + 1, inner.width, 1),
-            &format!("{provider} {}", app.chrome.symbol("›", ">")),
-            Action::Onboard(Command::Provider),
-            focus == 0,
-        );
-    }
-    let controls = if models {
-        vec![(Command::Save, 3), (Command::Close, 2), (Command::Back, 1)]
+    let button = |sheet: Sheet<Action>, key, command: Command, role| {
+        let enabled = app.onboarding_offered(&command);
+        sheet.button(
+            key,
+            app.i18n.text(command.label()),
+            role,
+            action(command),
+            enabled,
+        )
+    };
+    let sheet = if f.models.is_some() {
+        let sheet = sheet
+            .aside(
+                "back",
+                app.i18n.text(Command::Back.label()),
+                action(Command::Back),
+                app.onboarding_offered(&Command::Back),
+            )
+            .back(action(Command::Back));
+        let sheet = button(sheet, "cancel", Command::Close, Role::Normal);
+        button(sheet, "save", Command::Save, Role::Primary).focus_node(format!("{MODELS}/0"))
     } else {
-        vec![(Command::Verify, 4), (Command::Close, 5)]
+        let sheet = button(sheet, "cancel", Command::Close, Role::Normal);
+        button(sheet, "verify", Command::Verify, Role::Primary).focus_node(row_path(0))
     };
-    let mut right = inner.right();
-    for (command, index) in controls {
-        let label = app.i18n.text(command.label());
-        let width = (label.width() as u16 + 2).min(inner.width / 3);
-        let rect = Rect::new(right.saturating_sub(width), inner.bottom() - 1, width, 1);
-        right = rect.x.saturating_sub(1);
-        button(
-            frame,
-            app,
-            rect,
-            &label,
-            Action::Onboard(command),
-            focus == index,
-        );
+    Some(sheet)
+}
+
+fn availability(app: &App) -> &'static str {
+    if app.providers.loading() {
+        "providers-loading"
+    } else if app.providers.failed() {
+        "providers-failed"
+    } else {
+        "onboard-no-providers"
+    }
+}
+
+/// Paints the setup form's text rows over the drawn sheet.
+pub(crate) fn draw_field(frame: &mut Frame<'_>, app: &mut App) {
+    let width = label_width(app);
+    let focused = app.layer.focused_path().and_then(row);
+    let colors = app.theme.colors();
+    let editable = app.onboarding_enabled(&Command::Field(0));
+    let rows: Vec<_> = (0..LABELS.len())
+        .map(|index| {
+            app.layer
+                .rect(&row_path(index))
+                .filter(|rect| !rect.is_empty())
+        })
+        .collect();
+    let labels: Vec<_> = LABELS.iter().map(|key| app.i18n.text(key)).collect();
+    let Some(f) = app.onboarding.dialog.as_mut() else {
+        return;
+    };
+    for (index, field) in f.fields.iter_mut().enumerate() {
+        let Some(rect) = rows[index].filter(|_| f.models.is_none()) else {
+            field.invalidate_geometry();
+            continue;
+        };
+        let row = form::Row {
+            label: &labels[index],
+            focused: editable && focused == Some(index),
+            masked: false,
+            placeholder: None,
+        };
+        form::draw(frame, rect, width, row, field, colors);
     }
 }
diff --git a/crates/tui/src/pages/queue/edit.rs b/crates/tui/src/pages/queue/edit.rs
index 7d44c04cbd..57b74b3efb 100644
--- a/crates/tui/src/pages/queue/edit.rs
+++ b/crates/tui/src/pages/queue/edit.rs
@@ -22,8 +22,8 @@ use crate::{
     app::{Action, App},
     ui::{Role, Sheet, Tone},
 };
-use crossterm::event::{Event, KeyCode, KeyEventKind, KeyModifiers};
-use ratatui::{Frame, layout::Position};
+use crossterm::event::{Event, KeyCode, KeyEventKind, KeyModifiers, MouseEventKind};
+use ratatui::Frame;
 
 const FIELD: &str = "message";
 
@@ -103,13 +103,13 @@ impl App {
                 Some((edit.editor.key(*key), None))
             }
             Event::Paste(text) if focused => Some((edit.editor.insert(text), None)),
-            Event::Mouse(mouse)
-                if edit.editor.contains(Position::new(mouse.column, mouse.row))
-                    || edit.editor.dragging() =>
-            {
+            Event::Mouse(mouse) if edit.editor.takes(mouse) => {
+                let press = matches!(mouse.kind, MouseEventKind::Down(_));
                 let changed = edit.editor.mouse(*mouse);
-                self.layer.focus(FIELD);
-                Some((changed || !focused, None))
+                if press {
+                    self.layer.focus(FIELD);
+                }
+                Some((changed || (press && !focused), None))
             }
             _ => None,
         }
diff --git a/crates/tui/src/theme/editor.rs b/crates/tui/src/theme/editor.rs
index d7464bc74b..71b9644fae 100644
--- a/crates/tui/src/theme/editor.rs
+++ b/crates/tui/src/theme/editor.rs
@@ -209,16 +209,15 @@ impl App {
                 Some((changed, None))
             }
             Event::Mouse(mouse) => {
-                let point = (mouse.column, mouse.row).into();
                 let (field, key) = [(&mut editor.name, view::NAME), (&mut editor.hex, view::HEX)]
                     .into_iter()
-                    .find(|(field, _)| field.contains(point) || field.dragging())?;
+                    .find(|(field, _)| field.takes(mouse))?;
                 let changed = field.mouse(*mouse);
-                self.layer.focus(key);
-                Some((
-                    changed || matches!(mouse.kind, crossterm::event::MouseEventKind::Down(_)),
-                    None,
-                ))
+                if matches!(mouse.kind, crossterm::event::MouseEventKind::Down(_)) {
+                    self.layer.focus(key);
+                    return Some((true, None));
+                }
+                Some((changed, None))
             }
             _ => None,
         }
diff --git a/crates/tui/src/ui/sheet.rs b/crates/tui/src/ui/sheet.rs
index 2ed45aa317..df355a497e 100644
--- a/crates/tui/src/ui/sheet.rs
+++ b/crates/tui/src/ui/sheet.rs
@@ -368,6 +368,25 @@ impl<M: Clone> Layer<M> {
         self.surface.move_focus(format!("{ROOT}/{path}"));
     }
 
+    /// A chooser is open over the sheet: it takes every key and pointer
+    /// event, so owners leave them alone.
+    pub fn captures(&self) -> bool {
+        self.surface.captures()
+    }
+
+    /// Paints an open chooser over what the owner drew after the sheet.
+    pub fn repaint_chooser(&mut self, frame: &mut Frame<'_>, context: Context) {
+        if self.area.is_some() {
+            self.surface.repaint_popover(
+                frame,
+                &Context {
+                    focused: true,
+                    ..context
+                },
+            );
+        }
+    }
+
     /// Geometry changed: nothing is clickable until the next draw.
     pub fn invalidate(&mut self) {
         self.area = None;
diff --git a/crates/tui/src/ui/surface.rs b/crates/tui/src/ui/surface.rs
index 41daeb5563..cf3b8b79c9 100644
--- a/crates/tui/src/ui/surface.rs
+++ b/crates/tui/src/ui/surface.rs
@@ -34,6 +34,7 @@ use ratatui::{
 use std::collections::HashMap;
 use unicode_width::UnicodeWidthStr;
 
+#[derive(Clone, Copy)]
 pub struct Context {
     pub colors: Palette,
     pub ascii: bool,
@@ -200,6 +201,22 @@ impl<M: Clone> Surface<M> {
         });
     }
 
+    /// Paints an open chooser again, over what an owner drew on top of
+    /// this frame: the chooser is modal, so nothing covers it.
+    pub fn repaint_popover(&mut self, frame: &mut Frame<'_>, context: &Context) {
+        if self.popover.is_none() {
+            return;
+        }
+        let Some(committed) = self.committed.take() else {
+            return;
+        };
+        let popover = self.draw_popover(frame, committed.area, &committed.items, context);
+        self.committed = Some(Committed {
+            popover,
+            ..committed
+        });
+    }
+
     fn draw_popover(
         &mut self,
         frame: &mut Frame<'_>,
diff --git a/crates/tui/src/view.rs b/crates/tui/src/view.rs
index 27cfdccef9..86dd9c6110 100644
--- a/crates/tui/src/view.rs
+++ b/crates/tui/src/view.rs
@@ -31,6 +31,7 @@ use ratatui::{
 };
 
 pub(crate) mod activity;
+pub(crate) mod form;
 pub(crate) mod queue;
 mod session;
 pub(crate) mod tone;
diff --git a/crates/tui/src/view/form.rs b/crates/tui/src/view/form.rs
new file mode 100644
index 0000000000..1d701a289a
--- /dev/null
+++ b/crates/tui/src/view/form.rs
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+//! Labelled text rows of a form sheet. Each whole row is one kernel slot,
+//! so a form's rows share a focus group and the arrows walk them; the
+//! label and the editor are painted here, over the drawn sheet.
+use crate::{editor::Editor, theme::Palette, view::tone};
+use ratatui::{Frame, layout::Rect, style::Style, widgets::Paragraph};
+
+/// The label column for labels this wide, on a terminal this wide.
+pub(crate) fn label_width(labels: impl IntoIterator<Item = usize>, terminal: u16) -> u16 {
+    let width = crate::ui::content_width(terminal);
+    let widest = labels.into_iter().max().unwrap_or(0) as u16;
+    (widest + 2).min(width * 2 / 5)
+}
+
+/// One row: its label, then the editor (masked for secrets), or a
+/// placeholder while the field is empty and unfocused.
+pub(crate) struct Row<'a> {
+    pub label: &'a str,
+    pub focused: bool,
+    pub masked: bool,
+    pub placeholder: Option<&'a str>,
+}
+
+pub(crate) fn draw(
+    frame: &mut Frame<'_>,
+    rect: Rect,
+    width: u16,
+    row: Row<'_>,
+    editor: &mut Editor,
+    colors: Palette,
+) {
+    let label = Rect::new(rect.x, rect.y, width.min(rect.width), 1);
+    frame.buffer_mut().set_style(label, colors.base());
+    frame.render_widget(
+        Paragraph::new(row.label).style(Style::default().fg(if row.focused {
+            tone::accent(colors)
+        } else {
+            colors.muted
+        })),
+        Rect::new(label.x, label.y, label.width.saturating_sub(1), 1),
+    );
+    let value = Rect::new(
+        rect.x + label.width,
+        rect.y,
+        rect.width.saturating_sub(label.width),
+        1,
+    );
+    if row.masked {
+        editor.draw_masked(frame, value, row.focused, colors);
+    } else {
+        editor.draw(frame, value, row.focused, colors);
+    }
+    if let Some(placeholder) = row.placeholder
+        && editor.text().is_empty()
+        && !row.focused
+    {
+        frame.render_widget(
+            Paragraph::new(placeholder).style(Style::default().fg(colors.subtle)),
+            value,
+        );
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org