Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/dim-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ transcript target retains Shift+Tab navigation. See the
| Mouse drag | Select transcript text; release copies it (OSC 52, plus `pbcopy` locally on macOS; inside tmux OSC 52 goes through passthrough, which needs `set -g allow-passthrough on`) |
| Click a link | Opens it in the system browser (OSC 8 links, or a bare `http(s)://` URL); over SSH the status row shows the URL instead |
| Click a task row above the composer | Opens that command's output or member conversation directly; `Esc` returns with the composer draft preserved. Press and release must hit the same cell and task without dragging; resizing or an open overlay cancels or blocks the click. Scrollback keeps keyboard-only task entry |
| Click inside the composer | Places the insertion cursor at the clicked text cell. Press and release in the same cell without dragging. |
| Click the model label | Opens `/models` without discarding the draft; `Esc` returns to it. See [model label interaction](../../docs/design/model-configuration.md#scrollback-interaction) |
| Click a tool header or a thought's title | Immediately toggles only that batch, codemode or call (`▸` / `▾`), or opens/closes a settled thought. Parent collapse hides children without resetting their choices. Hover and press feedback affect only the title, not detail/body rows; release must hit the same valid target without dragging. Opening holds the view in place. Output and compare text remain selectable; links and the member-conversation entry are separate actions. `/tools` changes defaults for unchosen nodes, not manual choices; thinking has its own setting |
| Click an expanded thought's or tool node's body | Collapses that thought or the nearest enclosing open tool node (call, codemode or batch) after the existing 400ms multi-click window; headers and titles still respond immediately, and hover/press feedback remains on headers only. For thoughts, this covers actual body rows and internal gutter/blank cells in the main transcript, member conversation and branch side panel, not adjacent blocks, panel borders, scrollbar or page whitespace. For tools, this covers detail/body rows (including output, diffs, generic input/results, and non-foldable child rows) in the main transcript and member conversation, leaving siblings and other batches unchanged and excluding member-conversation entry rows, adjacent blocks, scrollbar and page whitespace. Drag selection, double/triple-click selection, links and member-conversation entries take priority. A new press, drag, scroll, resize, view change, mouse-off, overlay, paste or keyboard input cancels the pending click; the client revalidates the same expanded target before collapsing it, and re-anchors to its owning header when scrolled past it. Other block bodies (compaction, hook, error, member result) are not buttons. Manual choices survive redraws independently of the detail defaults; no gesture blocks input, Stop or background execution |
Expand Down
15 changes: 14 additions & 1 deletion crates/dim-cli/src/ui/composer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub mod mentions;
pub mod palette;

use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::layout::{Position, Rect};
use ratatui::style::{Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::StatefulWidgetRef;
Expand Down Expand Up @@ -1236,6 +1236,19 @@ impl Composer {
}
}

/// Place the cursor at `cell` and clear the selection. Both `cell` and the
/// rendered textarea `area` use screen columns and rows counted from the
/// top of the unclipped dock. Clicks outside `area` are ignored.
pub fn click(&mut self, cell: Position, area: Rect) {
Comment thread
zerob13 marked this conversation as resolved.
Resolved
if let Some(offset) = self
.area
.buffer_pos_at_screen(cell.x, cell.y, area, self.state)
{
self.area.clear_selection();
self.area.set_cursor(offset);
}
}

/// Rows of the input at `text_width` columns (without prompt/border),
/// bounded by `max_rows`, and the cursor (column, row) inside them.
pub fn render_rows(
Expand Down
100 changes: 49 additions & 51 deletions crates/dim-cli/src/ui/render/fullscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use std::collections::HashMap;
use std::io::Write;
use std::time::{Duration, Instant};

use ratatui::layout::{Position, Rect};

use crate::ui::render::Frame;
use crate::ui::render::panel::{clip, escape_len, strip_escapes};
use crate::ui::render::screen::scrub;
Expand Down Expand Up @@ -139,6 +141,10 @@ pub enum MouseOutcome {
Task(String),
/// A click landed on the composer's model label.
Models,
Composer {
cell: Position,
area: Rect,
},
/// A click landed on a branch panel thought header or expanded body.
Thought {
key: String,
Expand Down Expand Up @@ -351,6 +357,7 @@ pub struct FullScreen {
task_rows: HashMap<usize, String>,
thought_rows: HashMap<usize, PanelThought>,
model_label: Option<(usize, std::ops::Range<usize>)>,
composer: Option<(Rect, usize)>,
/// Where the last press landed and the row it showed: a click counts
/// only while that row still shows the same text at the release, so
/// output that moves the transcript in between cannot redirect it.
Expand Down Expand Up @@ -410,6 +417,7 @@ impl FullScreen {
task_rows: HashMap::new(),
thought_rows: HashMap::new(),
model_label: None,
composer: None,
press: None,
pointer: None,
hovered: None,
Expand Down Expand Up @@ -449,6 +457,7 @@ impl FullScreen {
self.task_rows.clear();
self.thought_rows.clear();
self.model_label = None;
self.composer = None;
self.invalidate();
true
}
Expand Down Expand Up @@ -654,12 +663,16 @@ impl FullScreen {
self.selection = None;
}

/// Cancels a deferred body click, including an unreleased body press.
/// Cancels a deferred body click or an unreleased body or composer press.
/// Call when disabling mouse input or changing the active view.
pub fn cancel_click(&mut self) {
self.pending = None;
if self.press.as_ref().is_some_and(|press| {
press.body.is_some() || matches!(press.spot, MouseOutcome::Thought { .. })
press.body.is_some()
|| matches!(
press.spot,
MouseOutcome::Thought { .. } | MouseOutcome::Composer { .. }
)
}) {
self.press = None;
}
Expand Down Expand Up @@ -924,6 +937,26 @@ impl FullScreen {
self.pin(next);
}

fn dock_action(&self, column: usize, row: usize) -> Option<MouseOutcome> {
if self
.model_label
.as_ref()
.is_some_and(|(y, columns)| *y == row && columns.contains(&column))
{
return Some(MouseOutcome::Models);
}
if column < content_width(self.size.0 as usize)
&& let Some(task) = self.task_rows.get(&row)
{
return Some(MouseOutcome::Task(task.clone()));
}
let (area, skipped_rows) = self.composer?;
let dock_row = row.checked_sub(self.view_rows)? + skipped_rows;
let cell = Position::new(column as u16, u16::try_from(dock_row).ok()?);
area.contains(cell)
.then_some(MouseOutcome::Composer { cell, area })
}

fn hover(&mut self, doc: &dyn Document) -> bool {
let next = if self.overlay_open || self.selecting() {
None
Expand Down Expand Up @@ -1032,20 +1065,7 @@ impl FullScreen {
|| hovered
|| self.press.as_ref().is_some_and(|p| p.target.is_some());
self.press = None;
let action = if self
.model_label
.as_ref()
.is_some_and(|(y, columns)| *y == row && columns.contains(&column))
{
Some(MouseOutcome::Models)
} else if column < content_width(self.size.0 as usize)
&& let Some(task) = self.task_rows.get(&row)
{
Some(MouseOutcome::Task(task.clone()))
} else {
None
};
if let Some(spot) = action {
if let Some(spot) = self.dock_action(column, row) {
self.clicks = None;
self.press = Some(Press {
spot,
Expand Down Expand Up @@ -1150,12 +1170,8 @@ impl FullScreen {
}
}
MouseKind::Drag => {
if self.press.as_ref().is_some_and(|press| {
matches!(press.spot, MouseOutcome::Task(_) | MouseOutcome::Models)
}) {
self.press = None;
}
let Some(selection) = self.selection else {
self.press = None;
return MouseOutcome::Ignored;
};
if selection.panel {
Expand Down Expand Up @@ -1205,34 +1221,12 @@ impl FullScreen {
}
MouseKind::Release => {
let press = self.press.take();
if let Some(Press {
spot: MouseOutcome::Models,
cell,
..
}) = &press
{
return if *cell == (column, row)
&& self
.model_label
.as_ref()
.is_some_and(|(y, columns)| *y == row && columns.contains(&column))
{
MouseOutcome::Models
} else {
MouseOutcome::Ignored
};
}
if let Some(Press {
spot: MouseOutcome::Task(task),
cell,
..
}) = &press
if let Some(press) = &press
&& press.cell == (column, row)
&& let Some(action) = self.dock_action(column, row)
&& action == press.spot
{
return if *cell == (column, row) && self.task_rows.get(&row) == Some(task) {
MouseOutcome::Task(task.clone())
} else {
MouseOutcome::Ignored
};
return action;
}
let changed = hovered || press.as_ref().is_some_and(|p| p.target.is_some());
let Some(selection) = self.selection else {
Expand Down Expand Up @@ -1311,6 +1305,7 @@ impl FullScreen {
.max(1);
let dock_skip = dock.len().saturating_sub(dock_rows);
self.view_rows = rows - dock_rows.min(rows);
self.composer = frame.composer.map(|area| (area, dock_skip));
let model_label = frame.model_label.as_ref().and_then(|(row, columns)| {
row.checked_sub(split + dock_skip)
.filter(|row| *row < dock_rows)
Expand Down Expand Up @@ -1410,9 +1405,12 @@ impl FullScreen {
if press.spot == MouseOutcome::Models {
return false;
}
let (_, row) = press.cell;
if let MouseOutcome::Task(task) = &press.spot {
return self.task_rows.get(&row) != Some(task);
let (column, row) = press.cell;
if matches!(
press.spot,
MouseOutcome::Task(_) | MouseOutcome::Composer { .. }
) {
return self.dock_action(column, row).as_ref() != Some(&press.spot);
}
if let MouseOutcome::Thought { key, body } = &press.spot {
return self.thought_rows.get(&row).is_none_or(|thought| {
Expand Down
2 changes: 2 additions & 0 deletions crates/dim-cli/src/ui/render/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub struct Frame {
pub thought_rows: Vec<(usize, std::ops::Range<usize>, String, bool)>,
/// Model label row and columns in `live`, for the fullscreen model picker.
pub model_label: Option<(usize, std::ops::Range<usize>)>,
/// Editable text cells relative to the start of the fullscreen dock.
pub composer: Option<Rect>,
/// Cursor position inside the live region (row, column), `None` hides it.
pub cursor: Option<(u16, u16)>,
/// Index in `live` where the dock (queue, composer, panels, status)
Expand Down
18 changes: 17 additions & 1 deletion crates/dim-cli/src/ui/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! diff (2.3). The terminal layer (2.2) guarantees the exit contract.

use dim_agent_types::ROOT_BRANCH_ID;
use ratatui::layout::Rect;
use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -603,6 +604,13 @@ fn run_terminal(
app.run_command("models", "");
dirty = true;
}
MouseOutcome::Composer { cell, area } => {
if mouse && app.prompt.is_none() && !app.composer.palette_open() {
full.clear_focus();
app.composer.click(cell, area);
dirty = true;
}
}
MouseOutcome::Thought { key, body } => {
dirty |= app.click_panel_thought(&key, body);
}
Expand Down Expand Up @@ -6577,13 +6585,21 @@ impl App {
}
(cursor.1 as usize, prompt_width + cursor.0 as usize)
};
let box_top = live.len();
if self.fullscreen && self.prompt.is_none() && !palette_overlay {
frame.composer = Some(Rect::new(
(MARGIN + 2 + prompt_width) as u16,
(box_top + 1 - frame.dock) as u16,
text_width as u16,
rows.len() as u16,
Comment thread
zerob13 marked this conversation as resolved.
Resolved
));
}
if self.fullscreen {
let minimum = FULLSCREEN_COMPOSER_ROWS.min((size.1 as usize).saturating_sub(7).max(1));
if rows.len() < minimum {
rows.resize(minimum, String::new());
}
}
let box_top = live.len();
let shell_title = shell.map(|shell| match shell {
Shell::Recorded => t("! shell mode"),
Shell::Private => t("!! shell mode · not sent to the model"),
Expand Down
2 changes: 2 additions & 0 deletions docs/architecture/tui-e2e.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ daemon. `--keep` leaves the home and raw streams in place for inspection.
| terminal-modes | `resize_rewraps_history_without_losing_rows` | Resizing to 60x18 and 140x40 keeps the message and answer, rewraps rows, and draws to the new width: the capture is taken only after the product's own `CSI 3J` reflow and completed frame, tmux reports the target pane size, and the new frame is stable at that width |
| terminal-modes | `resize_during_a_stream_rewraps_and_finishes` | A resize while the fixture streams repaints the live output at the new width, keeps the streamed text, and the run still finishes |
| terminal-modes | `resize_during_thinking_rewraps_multiline_history` | Expanded reasoning streams in a turn sent as three lines; five resizes (100x24, 60x24, 120x40, 45x18, 100x36) keep every user line and every reasoning line, the transcript settles as a thought, and the answer still arrives |
| composer | `fullscreen_composer_click_places_the_cursor` | Click-to-insert in ASCII and scrolled, wrapped wide text. Releasing in another cell, dragging back to the pressed cell, or typing before release preserves the insertion point |
| composer | `fullscreen_composer_click_with_a_clipped_task_strip` | In a short pane with three background tasks, clicking the top visible row of a wrapped draft inserts there. The textarea scrolls inside a padded composer box |
| composer | `composer_edits_multiline_and_stores_a_large_paste` | `Ctrl+J` newline editing, backspace, a five-line bracketed paste stored as an attachment, and the exact prompt text the model receives |
| composer | `file_mention_inserts_a_workspace_link` | The `@` picker lists the `--cwd` workspace, inserts the chosen file, and completes a directory prefix to the file under it; the prompt carries both as absolute links |
| no-session | `home_commands_without_a_session_answer_and_send_nothing` | `/export`, `/queue` and `/mcp list` run from the palette over a draft answer at home in both layouts, the draft returns to the composer after each, no command sends it, and the fixture model receives no request; `/agent` and a valued `/effort` stay with `tui_home_commands_without_a_session_answer_and_send_nothing` in CI |
Expand Down
Loading