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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ terminal never keeps swallowing clicks.

- **Click** an entity row to select it and open the preview in one action.
In the workflow picker, clicking a row opens that workflow.
- **Double-click an entity ID** to copy its full value, even when a long
slug is visually shortened with an ellipsis. This uses OSC 52 and requires
clipboard support from the terminal (or its multiplexer).
- **Scroll wheel** scrolls the panel under the cursor: the preview body
when hovering the preview, the list selection when hovering the list.
- **Drag the divider** between the list and the preview to resize the
Expand Down
2 changes: 2 additions & 0 deletions crates/spacetop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition.workspace = true
[dependencies]
spacetop-core = { path = "../spacetop-core" }
anyhow = "1"
base64 = "0.22"
sentry = { version = "0.34", default-features = false, features = ["backtrace", "contexts", "panic", "reqwest", "rustls"] }
clap = { version = "4.5", features = ["derive"] }
crossterm = "0.28"
Expand All @@ -15,6 +16,7 @@ termimad = "0.34"
similar = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
unicode-width = "0.2"

[dev-dependencies]
sentry = { version = "0.34", default-features = false, features = ["test"] }
Expand Down
70 changes: 66 additions & 4 deletions crates/spacetop/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::cell::Cell;
use std::path::{Path, PathBuf};
use std::time::{Duration, Instant};

use crossterm::event::{KeyCode, KeyEvent, MouseEvent};

Expand Down Expand Up @@ -36,6 +37,20 @@ pub use session_activity_worker::{
pub(crate) use keys::ResolvedKeymap;
use keys::{handle_overview_key_with_keymap, OverviewKeyAction};

const COPY_FEEDBACK_DURATION: Duration = Duration::from_secs(2);

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum CopyFeedback {
Succeeded,
Failed,
}

#[derive(Debug, Clone, PartialEq, Eq)]
struct TimedCopyFeedback {
outcome: CopyFeedback,
expires_at: Instant,
}

#[derive(Debug, Clone, PartialEq)]
#[allow(clippy::large_enum_variant)]
pub enum AppMode {
Expand Down Expand Up @@ -213,6 +228,9 @@ pub struct App {
pending_overlay_open: bool,
pending_open_file: Option<PathBuf>,
pending_sync: bool,
pending_copy_id: Option<String>,
id_click_candidate: Option<mouse::IdClickCandidate>,
copy_feedback: Option<TimedCopyFeedback>,
}

impl App {
Expand Down Expand Up @@ -355,6 +373,9 @@ impl App {
pending_overlay_open: false,
pending_open_file: None,
pending_sync: false,
pending_copy_id: None,
id_click_candidate: None,
copy_feedback: None,
}
}

Expand Down Expand Up @@ -480,6 +501,30 @@ impl App {
self.pending_open_file.take()
}

/// Drain the full entity ID queued by a mouse double-click. OSC 52 output
/// remains in the terminal event loop rather than app/input state.
pub fn take_pending_copy_id(&mut self) -> Option<String> {
self.pending_copy_id.take()
}

pub(crate) fn set_copy_feedback_at(&mut self, outcome: CopyFeedback, now: Instant) {
self.copy_feedback = Some(TimedCopyFeedback {
outcome,
expires_at: now + COPY_FEEDBACK_DURATION,
});
}

pub(crate) fn copy_feedback(&self) -> Option<CopyFeedback> {
self.copy_feedback_at(Instant::now())
}

pub(crate) fn copy_feedback_at(&self, now: Instant) -> Option<CopyFeedback> {
self.copy_feedback
.as_ref()
.filter(|feedback| now < feedback.expires_at)
.map(|feedback| feedback.outcome)
}

/// Record a `Y` keypress intent. The event loop calls
/// `take_pending_sync` next tick and runs `git_sync::sync` against the
/// active workflow's repo root, synchronously.
Expand Down Expand Up @@ -948,13 +993,28 @@ impl App {
/// the full-pane Definition view handles only wheel scrolling, while
/// Search, Timeline, Metrics, Activity, and Relations remain inert.
pub fn handle_mouse(&mut self, mouse: MouseEvent) {
self.handle_mouse_at(mouse, Instant::now());
}

pub(crate) fn handle_mouse_at(&mut self, mouse: MouseEvent, now: Instant) {
if self.help_open {
return;
}
if matches!(
self.mode,
AppMode::Picker(_) | AppMode::PickerOverlay { .. }
) {
self.id_click_candidate = None;
self.handle_picker_mouse(mouse);
return;
}
let definition_max_scroll = self.definition_max_scroll.get();
let action = match &mut self.mode {
AppMode::Overview(session) => mouse::handle_overview_mouse(session, mouse),
AppMode::Overview(session) => {
mouse::handle_overview_mouse(session, mouse, now, &mut self.id_click_candidate)
}
AppMode::Definition { scroll, .. } => {
self.id_click_candidate = None;
match mouse.kind {
crossterm::event::MouseEventKind::ScrollDown => {
definition_scroll_down(
Expand All @@ -974,11 +1034,10 @@ impl App {
}
return;
}
AppMode::Picker(_) | AppMode::PickerOverlay { .. } => {
self.handle_picker_mouse(mouse);
_ => {
self.id_click_candidate = None;
return;
}
_ => return,
};
self.apply_overview_key_action(action);
}
Expand Down Expand Up @@ -1031,9 +1090,11 @@ impl App {
OverviewKeyAction::OpenHelp => self.help_open = true,
OverviewKeyAction::Quit => self.should_quit = true,
OverviewKeyAction::Switch(workflow_switch) => {
self.id_click_candidate = None;
self.pending_switch = Some(workflow_switch);
}
OverviewKeyAction::OpenPickerOverlay => {
self.id_click_candidate = None;
self.pending_overlay_open = true;
}
OverviewKeyAction::OpenSelectedFile(path) => {
Expand All @@ -1046,6 +1107,7 @@ impl App {
OverviewKeyAction::OpenMetrics => self.open_metrics(),
OverviewKeyAction::OpenActivity => self.open_activity(),
OverviewKeyAction::OpenRelations => self.open_relations(),
OverviewKeyAction::CopyId(id) => self.pending_copy_id = Some(id),
OverviewKeyAction::RequestSync => self.pending_sync = true,
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/spacetop/src/app/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ pub(crate) enum OverviewKeyAction {
OpenMetrics,
OpenActivity,
OpenRelations,
/// A mouse double-click landed on a rendered entity-ID cell. The full
/// underlying ID is carried to the terminal boundary for OSC 52 output.
CopyId(String),
/// `Y` from Overview: request a `git pull --ff-only` against the
/// active workflow's repo root. Always emitted when the binding
/// fires; the helper classifies availability and reports the result.
Expand Down
Loading
Loading