rust: merge UI feature modules; fix Ctrl+key on Linux/Windows (egui command_only shadowing); clippy clean; rustfmt config

This commit is contained in:
Andy Dixon
2026-10-11 17:40:48 +01:00
parent 327ca1caa9
commit 2bb12c3a58
49 changed files with 1140 additions and 659 deletions
+72 -43
View File
@@ -41,17 +41,43 @@ pub enum Prompt {
/// Modal dialogs owned by the main window.
pub enum Dialog {
/// A profile already has a live session.
Reuse { profile: String, existing: String },
Reuse {
profile: String,
existing: String,
},
/// Unencrypted VNC without an SSH tunnel.
DirectVnc { profile: String },
ConfirmClose { session: String },
ConfirmDisconnectMany { sessions: Vec<String> },
Rename { session: String, name: String },
Broadcast { picks: Vec<(String, String, bool)> },
DirectVnc {
profile: String,
},
ConfirmClose {
session: String,
},
ConfirmDisconnectMany {
sessions: Vec<String>,
},
Rename {
session: String,
name: String,
},
Broadcast {
picks: Vec<(String, String, bool)>,
},
/// Guided help for an auth or host-key failure.
Guided { session: String, title: String, body: String, known_hosts: bool },
Delete { profiles: Vec<String> },
Input { title: String, label: String, value: String, then: InputThen },
Guided {
session: String,
title: String,
body: String,
known_hosts: bool,
},
Delete {
profiles: Vec<String>,
},
Input {
title: String,
label: String,
value: String,
then: InputThen,
},
}
pub enum InputThen {
@@ -205,7 +231,9 @@ impl App {
/// Registers a just-opened session as a pane (and a tab unless it's a split child).
pub fn add_session(&mut self, id: &str, tab: bool) {
let Some(info) = self.s.svc.sessions.info(id) else { return };
let Some(info) = self.s.svc.sessions.info(id) else {
return;
};
let profile = self.s.svc.sessions.profile(id);
let view = self.view_for(&info, profile.as_ref());
self.s.panes.insert(id.into(), Pane { info, view, recording: false, local_exited: false, connected_since: None, highlight_until: 0.0 });
@@ -224,7 +252,8 @@ impl App {
};
if !skip_checks {
let live = self.s.panes.values().find(|pn| {
pn.info.profile_id == id && matches!(self.s.session_state(&pn.info.id), Some(SessionState::Connected | SessionState::Connecting | SessionState::Reconnecting))
pn.info.profile_id == id
&& matches!(self.s.session_state(&pn.info.id), Some(SessionState::Connected | SessionState::Connecting | SessionState::Reconnecting))
});
if let Some(pn) = live {
self.dialog = Some(Dialog::Reuse { profile: id.into(), existing: pn.info.id.clone() });
@@ -365,10 +394,10 @@ impl App {
fn mark_activity(&mut self, session: &str) {
let active = self.s.active.clone();
if let Some(t) = self.s.tabs.iter_mut().find(|t| t.id == session || t.split.as_ref().is_some_and(|sp| sp.sessions().iter().any(|x| x == session))) {
if active.as_deref() != Some(&t.id) {
t.activity = true;
}
if let Some(t) = self.s.tabs.iter_mut().find(|t| t.id == session || t.split.as_ref().is_some_and(|sp| sp.sessions().iter().any(|x| x == session)))
&& active.as_deref() != Some(&t.id)
{
t.activity = true;
}
}
@@ -467,7 +496,9 @@ impl App {
p.info.error = error.into();
}
}
let Some(p) = self.s.pane_mut(session) else { return };
let Some(p) = self.s.pane_mut(session) else {
return;
};
let local = p.info.protocol == Protocol::Local;
match state {
SessionState::Connected => {
@@ -477,7 +508,9 @@ impl App {
let _ = self.s.svc.sessions.write(session, format!("{cmd}\n").as_bytes());
self.run_local = None;
}
let Some(p) = self.s.pane_mut(session) else { return };
let Some(p) = self.s.pane_mut(session) else {
return;
};
p.local_exited = false;
p.connected_since = Some(chrono::Local::now());
// The PTY was created before the view knew its size: send it now.
@@ -520,7 +553,6 @@ impl App {
self.add_session(&sid, true);
self.s.info(format!("Connecting to {name}…"));
}
Request::ConnectLocal => self.connect_local(),
Request::ReloadProfiles => self.s.reload_profiles(),
Request::ReloadPreferences => {
self.s.prefs = self.s.svc.preferences();
@@ -528,26 +560,14 @@ impl App {
self.theme = theme_for(&self.s.prefs.theme);
theme::apply(&self.s.ctx, self.theme);
}
Request::QuickConnect => self.quick.open(),
Request::Settings(t) => self.settings.open(t),
Request::SshKeys => self.keys.open(),
Request::ExportEncrypted(ids) => self.transfer.export_encrypted(ids),
Request::ImportEncrypted => self.transfer.import_encrypted(),
Request::ExportJson => self.transfer.export_json(),
Request::ImportJson => self.transfer.import_json(),
Request::Recordings => self.recordings.open(),
Request::Snippets => self.snippets.open(),
Request::Triggers => self.triggers.open(),
Request::Sftp(id) => self.sftp.toggle(&id),
Request::PortForwards(id) => self.forwards.open(&id),
Request::SendToActive(text) => match self.s.focused_session() {
Some(id) if self.s.session_state(&id) == Some(SessionState::Connected) => self.send_input(&id, text.as_bytes()),
_ => self.s.error("No active connected session"),
},
Request::Write(id, data) => self.send_input(&id, &data),
Request::Disconnect(id) => self.close_session(&id),
Request::CommandPalette => self.palette = Some(chrome::Palette::default()),
Request::About => self.settings.open(SettingsTab::About),
}
}
}
@@ -754,7 +774,9 @@ impl App {
// --- screenshot automation ---------------------------------------------------------
fn screenshot(&mut self, ctx: &egui::Context) {
let Some((path, frames)) = &mut self.screenshot else { return };
let Some((path, frames)) = &mut self.screenshot else {
return;
};
*frames += 1;
if *frames < 40 {
std::thread::sleep(std::time::Duration::from_millis(15));
@@ -824,26 +846,33 @@ impl eframe::App for App {
if std::mem::take(&mut self.resize_sidebar) {
panel = panel.exact_size(width);
}
let side = panel
.min_size(180.0)
.max_size(500.0)
.resizable(true)
.frame(egui::Frame::NONE.fill(t.dock))
.show(ui, |ui| sidebar::ui(self, ui));
let side = panel.min_size(180.0).max_size(500.0).resizable(true).frame(egui::Frame::NONE.fill(t.dock)).show(ui, |ui| sidebar::ui(self, ui));
let w = side.response.rect.width().round() as i64;
if (w - self.s.prefs.sidebar_width).abs() > 2 && !ctx.input(|i| i.pointer.any_down()) {
self.s.prefs.sidebar_width = w;
let _ = self.s.svc.save_preferences(&self.s.prefs);
}
if self.editor.is_open() {
egui::Panel::right("editor").default_size(460.0).min_size(380.0).max_size(800.0).resizable(true).frame(egui::Frame::NONE.fill(t.dock).inner_margin(6)).show(ui, |ui| {
self.editor.ui(ui, &mut self.s);
});
egui::Panel::right("editor")
.default_size(460.0)
.min_size(380.0)
.max_size(800.0)
.resizable(true)
.frame(egui::Frame::NONE.fill(t.dock).inner_margin(6))
.show(ui, |ui| {
self.editor.ui(ui, &mut self.s);
});
} else if let Some(id) = self.sftp.open_for().map(String::from) {
if self.s.pane(&id).is_some() {
egui::Panel::right("sftp").default_size(380.0).min_size(280.0).max_size(800.0).resizable(true).frame(egui::Frame::NONE.fill(t.dock).inner_margin(6)).show(ui, |ui| {
self.sftp.ui(ui, &mut self.s);
});
egui::Panel::right("sftp")
.default_size(380.0)
.min_size(280.0)
.max_size(800.0)
.resizable(true)
.frame(egui::Frame::NONE.fill(t.dock).inner_margin(6))
.show(ui, |ui| {
self.sftp.ui(ui, &mut self.s);
});
} else {
self.sftp.close(&id);
}
+66 -16
View File
@@ -194,7 +194,13 @@ pub fn title_bar(app: &mut App, ui: &mut Ui) {
let resp = ui.interact(r, ui.id().with("palette-launch"), Sense::click());
ui.painter().rect(r, 6.0, if resp.hovered() { t.hover } else { t.field }, Stroke::new(1.0, t.field_border), egui::StrokeKind::Inside);
ui.painter().text(r.left_center() + vec2(9.0, 0.0), Align2::LEFT_CENTER, icon::MAGNIFYING_GLASS, egui::FontId::proportional(13.0), t.text_faint);
ui.painter().with_clip_rect(r.shrink(2.0)).text(r.left_center() + vec2(28.0, 0.0), Align2::LEFT_CENTER, "Search connections and commands", egui::FontId::proportional(12.0), t.text_faint);
ui.painter().with_clip_rect(r.shrink(2.0)).text(
r.left_center() + vec2(28.0, 0.0),
Align2::LEFT_CENTER,
"Search connections and commands",
egui::FontId::proportional(12.0),
t.text_faint,
);
if w > 250.0 {
ui.painter().text(r.right_center() - vec2(8.0, 0.0), Align2::RIGHT_CENTER, keys("Mod+K").replace('+', " "), theme::semibold(10.5), t.text_faint);
}
@@ -257,7 +263,9 @@ pub fn resize_edges(ctx: &egui::Context) {
(Rect::from_min_max(r.min, pos2(r.left() + e, r.bottom())), D::West, CursorIcon::ResizeHorizontal),
(Rect::from_min_max(pos2(r.right() - e, r.top()), r.max), D::East, CursorIcon::ResizeHorizontal),
];
let Some(p) = ctx.input(|i| i.pointer.hover_pos()) else { return };
let Some(p) = ctx.input(|i| i.pointer.hover_pos()) else {
return;
};
for (zone, dir, cursor) in zones {
if zone.contains(p) {
ctx.set_cursor_icon(cursor);
@@ -317,7 +325,13 @@ pub fn status_bar(app: &mut App, ui: &mut Ui) {
&& active.as_deref() == Some(sid)
&& let Ok(ms) = r
{
let c = if *ms < 100 { t.success } else if *ms < 250 { t.warning } else { t.danger };
let c = if *ms < 100 {
t.success
} else if *ms < 250 {
t.warning
} else {
t.danger
};
ui.label(RichText::new(format!("{ms} ms")).size(11.5).color(c));
}
if app.s.broadcast {
@@ -328,7 +342,15 @@ pub fn status_bar(app: &mut App, ui: &mut Ui) {
let vault = app.s.svc.secrets.vault.is_unlocked();
let keychain = app.s.svc.secrets.keychain_ok;
let label = if vault { format!("{} Vault unlocked", icon::LOCK_OPEN) } else { format!("{} Vault locked", icon::LOCK) };
if ui.add(egui::Label::new(dim(label)).sense(Sense::click())).on_hover_text(if keychain { "Saved credentials use the OS keychain; the vault is the fallback." } else { "No OS keychain available: saved credentials use the encrypted vault." }).clicked() {
if ui
.add(egui::Label::new(dim(label)).sense(Sense::click()))
.on_hover_text(if keychain {
"Saved credentials use the OS keychain; the vault is the fallback."
} else {
"No OS keychain available: saved credentials use the encrypted vault."
})
.clicked()
{
app.settings.open(SettingsTab::Security);
}
let total = app.s.panes.len();
@@ -337,7 +359,11 @@ pub fn status_bar(app: &mut App, ui: &mut Ui) {
if let Some(u) = &app.update
&& u.available
{
let txt = format!("{} Update available{}", icon::ARROW_CIRCLE_UP, if u.latest_version.is_empty() { String::new() } else { format!(" ({})", u.latest_version) });
let txt = format!(
"{} Update available{}",
icon::ARROW_CIRCLE_UP,
if u.latest_version.is_empty() { String::new() } else { format!(" ({})", u.latest_version) }
);
if ui.add(egui::Label::new(RichText::new(txt).size(11.5).color(t.accent)).sense(Sense::click())).clicked() {
app.settings.open(SettingsTab::About);
}
@@ -397,6 +423,8 @@ enum Cmd {
Settings,
Import,
Export,
ExportJson,
ImportJson,
Lock,
Unlock,
Keys,
@@ -435,7 +463,12 @@ fn commands(app: &App) -> Vec<(Cmd, String, &'static str, &'static str, String)>
let name = if p.display_name.is_empty() { &p.host } else { &p.display_name };
v.push((Cmd::Connect(p.id.clone()), format!("Connect to {name}"), "Connections", icon::PLUGS_CONNECTED, String::new()));
}
for (pr, label) in [(Protocol::Ssh, "New SSH Connection"), (Protocol::Telnet, "New Telnet Connection"), (Protocol::Raw, "New RAW Connection"), (Protocol::Serial, "New Serial Connection")] {
for (pr, label) in [
(Protocol::Ssh, "New SSH Connection"),
(Protocol::Telnet, "New Telnet Connection"),
(Protocol::Raw, "New RAW Connection"),
(Protocol::Serial, "New Serial Connection"),
] {
v.push((Cmd::NewProfile(pr), label.into(), "Actions", icon::PLUS_CIRCLE, if pr == Protocol::Ssh { keys("Mod+N") } else { String::new() }));
}
v.push((Cmd::Quick, "Quick Connect…".into(), "Actions", icon::LIGHTNING, keys("Mod+Shift+Q")));
@@ -456,6 +489,8 @@ fn commands(app: &App) -> Vec<(Cmd, String, &'static str, &'static str, String)>
v.push((Cmd::Settings, "Settings".into(), "Application", icon::GEAR, keys("Mod+,")));
v.push((Cmd::Import, "Import Profiles".into(), "Application", icon::DOWNLOAD_SIMPLE, String::new()));
v.push((Cmd::Export, "Export Profiles".into(), "Application", icon::UPLOAD_SIMPLE, String::new()));
v.push((Cmd::ImportJson, "Import Profiles (JSON)".into(), "Application", icon::FILE_ARROW_DOWN, String::new()));
v.push((Cmd::ExportJson, "Export Profiles (JSON)".into(), "Application", icon::FILE_ARROW_UP, String::new()));
for k in ThemeKind::ALL {
v.push((Cmd::Theme(k), format!("Theme: {}", k.label()), "Application", icon::PALETTE, String::new()));
}
@@ -501,6 +536,8 @@ fn run(app: &mut App, ctx: &egui::Context, c: Cmd) {
Cmd::Settings => app.settings.open(SettingsTab::General),
Cmd::Import => app.s.request(Request::ImportEncrypted),
Cmd::Export => app.s.request(Request::ExportEncrypted(vec![])),
Cmd::ExportJson => app.transfer.export_json(),
Cmd::ImportJson => app.transfer.import_json(),
Cmd::Lock => {
app.s.svc.secrets.vault.lock();
app.s.info("Secret store locked");
@@ -536,14 +573,13 @@ pub fn modal_backdrop(ctx: &egui::Context) {
}
pub fn palette(app: &mut App, ctx: &egui::Context) {
let Some(mut pal) = app.palette.take() else { return };
let Some(mut pal) = app.palette.take() else {
return;
};
let t = Tokens::get(ctx);
let mut matches: Vec<_> = commands(app)
.into_iter()
.filter_map(|c| fuzzy_score(&format!("{} {}", c.1, c.2), pal.query.trim()).map(|s| (s, c)))
.collect();
let mut matches: Vec<_> = commands(app).into_iter().filter_map(|c| fuzzy_score(&format!("{} {}", c.1, c.2), pal.query.trim()).map(|s| (s, c))).collect();
if !pal.query.trim().is_empty() {
matches.sort_by(|a, b| b.0.cmp(&a.0));
matches.sort_by_key(|m| std::cmp::Reverse(m.0));
}
let matches: Vec<_> = matches.into_iter().map(|(_, c)| c).collect();
pal.sel = pal.sel.min(matches.len().saturating_sub(1));
@@ -564,7 +600,13 @@ pub fn palette(app: &mut App, ctx: &egui::Context) {
ui.set_width(580.0);
ui.horizontal(|ui| {
ui.label(RichText::new(icon::MAGNIFYING_GLASS).size(16.0).color(t.text_faint));
let r = ui.add(egui::TextEdit::singleline(&mut pal.query).hint_text("Connect, switch tab, or run a command…").frame(egui::Frame::NONE).desired_width(f32::INFINITY).font(egui::FontId::proportional(15.0)));
let r = ui.add(
egui::TextEdit::singleline(&mut pal.query)
.hint_text("Connect, switch tab, or run a command…")
.frame(egui::Frame::NONE)
.desired_width(f32::INFINITY)
.font(egui::FontId::proportional(15.0)),
);
r.request_focus();
if r.changed() {
pal.sel = 0;
@@ -622,7 +664,9 @@ pub fn modal(ctx: &egui::Context, id: &str, width: f32, body: impl FnOnce(&mut U
}
pub fn prompts(app: &mut App, ctx: &egui::Context) {
let Some(p) = app.prompts.front_mut() else { return };
let Some(p) = app.prompts.front_mut() else {
return;
};
let t = Tokens::get(ctx);
let esc = ctx.input(|i| i.key_pressed(Key::Escape));
let enter = ctx.input(|i| i.key_pressed(Key::Enter));
@@ -680,7 +724,9 @@ pub fn prompts(app: &mut App, ctx: &egui::Context) {
// --- dialogs --------------------------------------------------------------------------------
pub fn dialogs(app: &mut App, ctx: &egui::Context) {
let Some(mut d) = app.dialog.take() else { return };
let Some(mut d) = app.dialog.take() else {
return;
};
let t = Tokens::get(ctx);
let esc = ctx.input(|i| i.key_pressed(Key::Escape));
let mut keep = !esc;
@@ -853,7 +899,11 @@ pub fn dialogs(app: &mut App, ctx: &egui::Context) {
let names: Vec<String> = profiles.iter().filter_map(|id| app.s.profile(id)).map(|p| p.display_name.clone()).collect();
modal(ctx, "delete", 380.0, |ui| {
ui.label(RichText::new("Delete connection?").font(theme::semibold(15.0)));
ui.label(if names.len() == 1 { format!("\"{}\" will be deleted, with its saved credentials.", names[0]) } else { format!("{} connections will be deleted.", names.len()) });
ui.label(if names.len() == 1 {
format!("\"{}\" will be deleted, with its saved credentials.", names[0])
} else {
format!("{} connections will be deleted.", names.len())
});
ui.add_space(8.0);
ui.horizontal(|ui| {
if ui.add(egui::Button::new(RichText::new(format!("{} Delete", icon::TRASH)).color(Color32::WHITE)).fill(t.danger)).clicked() {
+21 -5
View File
@@ -20,7 +20,14 @@ struct Form {
impl Default for Form {
fn default() -> Form {
Form { remote: false, bind_host: "127.0.0.1".into(), bind_port: String::new(), dest_host: "localhost".into(), dest_port: String::new(), label: String::new() }
Form {
remote: false,
bind_host: "127.0.0.1".into(),
bind_port: String::new(),
dest_host: "localhost".into(),
dest_port: String::new(),
label: String::new(),
}
}
}
@@ -52,7 +59,9 @@ impl Forwards {
s.info("Forward stopped");
}
}
let Some(sid) = self.session.clone() else { return };
let Some(sid) = self.session.clone() else {
return;
};
// A lock and a clone in the client; no network.
let list = match s.svc.sessions.forwards(&sid) {
Ok(l) => l,
@@ -84,7 +93,9 @@ impl Forwards {
ui.horizontal(|ui| {
let local = fwd.direction == ForwardDirection::Local;
widgets::chip(ui, if local { "L" } else { "R" }, if local { t.accent } else { t.warning });
let or = |s: &str, d: &str| if s.is_empty() { d.to_string() } else { s.to_string() };
let or = |s: &str, d: &str| {
if s.is_empty() { d.to_string() } else { s.to_string() }
};
let text = format!("{}:{} → {}:{}", or(&fwd.bind_host, "127.0.0.1"), fwd.bind_port, or(&fwd.dest_host, "localhost"), fwd.dest_port);
ui.label(RichText::new(text).font(theme::mono(12.0)));
if !fwd.label.is_empty() {
@@ -126,7 +137,9 @@ impl Forwards {
let f = &self.form;
match (port(&f.bind_port), port(&f.dest_port)) {
(Some(bind_port), Some(dest_port)) => {
let or = |s: &str, d: &str| if s.trim().is_empty() { d.to_string() } else { s.trim().to_string() };
let or = |s: &str, d: &str| {
if s.trim().is_empty() { d.to_string() } else { s.trim().to_string() }
};
let rule = PortForward {
id: new_id(),
direction: if f.remote { ForwardDirection::Remote } else { ForwardDirection::Local },
@@ -138,7 +151,10 @@ impl Forwards {
label: f.label.trim().into(),
};
let (svc, done) = (s.svc.clone(), self.done.clone());
s.spawn(move || svc.sessions.start_forward(&sid, rule).map_err(|e| format!("Failed to start forward: {e}").into()), move |_| done.lock().unwrap().push(true));
s.spawn(
move || svc.sessions.start_forward(&sid, rule).map_err(|e| format!("Failed to start forward: {e}").into()),
move |_| done.lock().unwrap().push(true),
);
}
_ => s.error("Bind port and destination port are required"),
}
+60 -44
View File
@@ -61,12 +61,16 @@ fn grouped<'a>(repos: &'a [GitHubRepo], login: &str, filter: &str) -> Vec<(Strin
/// "just now", "3 minutes ago", "1 day ago"… (the web build's relativeTime).
fn relative_time(iso: &str, now: DateTime<Utc>) -> String {
let Some(d) = parse_time(iso) else { return String::new() };
let Some(d) = parse_time(iso) else {
return String::new();
};
let secs = (now - d).num_seconds();
if secs < 60 {
return "just now".into();
}
let plural = |n: i64, unit: &str| if n == 1 { format!("1 {unit} ago") } else { format!("{n} {unit}s ago") };
let plural = |n: i64, unit: &str| {
if n == 1 { format!("1 {unit} ago") } else { format!("{n} {unit}s ago") }
};
let mins = secs / 60;
let hrs = mins / 60;
let days = hrs / 24;
@@ -120,6 +124,7 @@ fn lang_colour(lang: &str) -> Color32 {
Color32::from_rgb((hex >> 16) as u8, (hex >> 8) as u8, hex as u8)
}
#[allow(clippy::large_enum_variant)] // short-lived, one per click
enum Action {
Zip(GitHubRepo),
Visit(String),
@@ -178,7 +183,9 @@ impl GithubView {
fn download(&mut self, s: &Shared, repo: &GitHubRepo) {
let reference = repo.default_branch.clone();
let name = if reference.is_empty() { format!("{}.zip", repo.name) } else { format!("{}-{reference}.zip", repo.name) };
let Some(path) = rfd::FileDialog::new().set_file_name(name).add_filter("ZIP archive", &["zip"]).save_file() else { return };
let Some(path) = rfd::FileDialog::new().set_file_name(name).add_filter("ZIP archive", &["zip"]).save_file() else {
return;
};
self.on_status(format!("Downloading {}...", repo.full_name));
let (svc, sid, inbox, ctx, full) = (s.svc.clone(), self.session.clone(), self.inbox.clone(), s.ctx.clone(), repo.full_name.clone());
std::thread::spawn(move || {
@@ -221,7 +228,11 @@ impl GithubView {
if widgets::icon_button(ui, icon::ARROW_CLOCKWISE, "Refresh now").clicked() {
self.refresh(s);
}
ui.add(egui::TextEdit::singleline(&mut self.filter).hint_text(format!("{} Filter repositories…", icon::MAGNIFYING_GLASS)).desired_width(240.0));
ui.add(
egui::TextEdit::singleline(&mut self.filter)
.hint_text(format!("{} Filter repositories…", icon::MAGNIFYING_GLASS))
.desired_width(240.0),
);
});
});
let c = if self.status_error { t.danger } else { t.text_dim };
@@ -270,50 +281,55 @@ impl GithubView {
fn card(ui: &mut Ui, r: &GitHubRepo, now: DateTime<Utc>) -> Option<Action> {
let t = Tokens::get(ui.ctx());
let mut action = None;
let resp = egui::Frame::new().fill(t.card).stroke(egui::Stroke::new(1.0, t.card_border)).corner_radius(6).inner_margin(egui::Margin::symmetric(12, 9)).show(ui, |ui| {
ui.set_width(ui.available_width());
ui.horizontal(|ui| {
ui.label(RichText::new(&r.name).font(theme::semibold(13.5)).color(t.accent));
if r.private {
widgets::chip(ui, "Private", t.warning);
}
if r.fork {
widgets::chip(ui, "Fork", t.text_dim);
}
if r.archived {
widgets::chip(ui, "Archived", t.danger);
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui.button(format!("{} Visit", icon::ARROW_SQUARE_OUT)).on_hover_text("Open repository in browser").clicked() {
action = Some(Action::Visit(r.html_url.clone()));
let resp = egui::Frame::new()
.fill(t.card)
.stroke(egui::Stroke::new(1.0, t.card_border))
.corner_radius(6)
.inner_margin(egui::Margin::symmetric(12, 9))
.show(ui, |ui| {
ui.set_width(ui.available_width());
ui.horizontal(|ui| {
ui.label(RichText::new(&r.name).font(theme::semibold(13.5)).color(t.accent));
if r.private {
widgets::chip(ui, "Private", t.warning);
}
if ui.button(format!("{} ZIP", icon::FILE_ZIP)).on_hover_text("Download repository as zip").clicked() {
action = Some(Action::Zip(r.clone()));
if r.fork {
widgets::chip(ui, "Fork", t.text_dim);
}
if r.archived {
widgets::chip(ui, "Archived", t.danger);
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui.button(format!("{} Visit", icon::ARROW_SQUARE_OUT)).on_hover_text("Open repository in browser").clicked() {
action = Some(Action::Visit(r.html_url.clone()));
}
if ui.button(format!("{} ZIP", icon::FILE_ZIP)).on_hover_text("Download repository as zip").clicked() {
action = Some(Action::Zip(r.clone()));
}
});
});
if !r.latest_committer.is_empty() && !r.latest_commit_at.is_empty() {
ui.label(RichText::new(format!("Last commit: {} by {}", local_time(&r.latest_commit_at), r.latest_committer)).color(t.text_faint).size(11.5));
}
if !r.description.is_empty() {
ui.label(RichText::new(&r.description).color(t.text_dim));
}
ui.horizontal(|ui| {
if !r.language.is_empty() {
let (dot, _) = ui.allocate_exact_size(vec2(10.0, 10.0), Sense::hover());
ui.painter().circle_filled(dot.center(), 5.0, lang_colour(&r.language));
ui.label(RichText::new(&r.language).color(t.text_dim).size(11.5));
ui.add_space(8.0);
}
if r.stars > 0 {
ui.label(RichText::new(format!("{} {}", icon::STAR, widgets::group(r.stars as u64))).color(t.text_dim).size(11.5));
ui.add_space(8.0);
}
if !r.pushed_at.is_empty() {
ui.label(RichText::new(relative_time(&r.pushed_at, now)).color(t.text_faint).size(11.5)).on_hover_text(local_time(&r.pushed_at));
}
});
});
if !r.latest_committer.is_empty() && !r.latest_commit_at.is_empty() {
ui.label(RichText::new(format!("Last commit: {} by {}", local_time(&r.latest_commit_at), r.latest_committer)).color(t.text_faint).size(11.5));
}
if !r.description.is_empty() {
ui.label(RichText::new(&r.description).color(t.text_dim));
}
ui.horizontal(|ui| {
if !r.language.is_empty() {
let (dot, _) = ui.allocate_exact_size(vec2(10.0, 10.0), Sense::hover());
ui.painter().circle_filled(dot.center(), 5.0, lang_colour(&r.language));
ui.label(RichText::new(&r.language).color(t.text_dim).size(11.5));
ui.add_space(8.0);
}
if r.stars > 0 {
ui.label(RichText::new(format!("{} {}", icon::STAR, widgets::group(r.stars as u64))).color(t.text_dim).size(11.5));
ui.add_space(8.0);
}
if !r.pushed_at.is_empty() {
ui.label(RichText::new(relative_time(&r.pushed_at, now)).color(t.text_faint).size(11.5)).on_hover_text(local_time(&r.pushed_at));
}
});
});
let resp = resp.response.interact(Sense::click());
if resp.double_clicked() {
action = Some(Action::Visit(r.html_url.clone()));
+6 -3
View File
@@ -317,7 +317,9 @@ impl IrcView {
fn log(&mut self, ui: &mut Ui, theme: &'static TermTheme) {
let font = FontId::monospace(self.font_size);
let wrap = ui.available_width().max(100.0);
let Some(target) = self.targets.iter_mut().find(|t| t.name == self.active) else { return };
let Some(target) = self.targets.iter_mut().find(|t| t.name == self.active) else {
return;
};
// Lay out lines once per width/theme; the galley cache keeps scrolling cheap.
let mut tops = Vec::with_capacity(target.lines.len());
let mut y = 0.0;
@@ -453,7 +455,8 @@ impl IrcView {
ui.label(RichText::new(r.users.to_string()).color(t.text_faint).size(11.0));
ui.label(RichText::new(ircformat::plain_text(&r.topic)).color(t.text_faint).size(11.0));
});
ui.interact(ui.max_rect(), ui.id().with("tip"), Sense::hover()).on_hover_text(format!("{}\nClick to join", ircformat::plain_text(if r.topic.is_empty() { &r.name } else { &r.topic })));
ui.interact(ui.max_rect(), ui.id().with("tip"), Sense::hover())
.on_hover_text(format!("{}\nClick to join", ircformat::plain_text(if r.topic.is_empty() { &r.name } else { &r.topic })));
});
join_room = clicked.map(|i| listed[i].name.clone());
});
@@ -474,7 +477,7 @@ impl IrcView {
ui.interact(ui.max_rect(), ui.id().with("tip"), Sense::hover()).on_hover_text(format!("{}\nClick to mention", u[i]));
});
if let Some(i) = clicked {
self.insert_mention(&display_nick(&u[i]).to_string());
self.insert_mention(display_nick(&u[i]));
}
}
_ => widgets::hint(ui, "No users yet"),
+85 -24
View File
@@ -208,7 +208,10 @@ impl ProfileEditor {
});
ui.add_space(2.0);
let errs = if self.show_errors { self.validate() } else { vec![] };
egui::Panel::bottom("profile-editor-footer").resizable(false).frame(egui::Frame::NONE.fill(t.dock).inner_margin(egui::Margin::symmetric(0, 6))).show(ui, |ui| self.footer(ui, s, &errs));
egui::Panel::bottom("profile-editor-footer")
.resizable(false)
.frame(egui::Frame::NONE.fill(t.dock).inner_margin(egui::Margin::symmetric(0, 6)))
.show(ui, |ui| self.footer(ui, s, &errs));
egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| {
ui.add_space(4.0);
self.general(ui, &errs);
@@ -240,7 +243,12 @@ impl ProfileEditor {
if !errs.is_empty() {
let all = errs.iter().map(|e| e.message.clone()).collect::<Vec<_>>().join("\n");
let n = errs.len();
ui.label(RichText::new(format!("{} {n} problem{} — see the highlighted fields", icon::WARNING_CIRCLE, if n == 1 { "" } else { "s" })).color(t.danger).size(12.0)).on_hover_text(all);
ui.label(
RichText::new(format!("{} {n} problem{} — see the highlighted fields", icon::WARNING_CIRCLE, if n == 1 { "" } else { "s" }))
.color(t.danger)
.size(12.0),
)
.on_hover_text(all);
}
if self.confirm_delete {
ui.horizontal(|ui| {
@@ -435,11 +443,14 @@ impl ProfileEditor {
item(ui, |ui| {
ui.horizontal(|ui| {
let opts = [(ForwardDirection::Local, "Local →"), (ForwardDirection::Remote, "← Remote")];
ComboBox::from_id_salt(("pf-dir", i)).width(84.0).selected_text(if pf.direction == ForwardDirection::Local { opts[0].1 } else { opts[1].1 }).show_ui(ui, |ui| {
for (v, l) in opts {
ui.selectable_value(&mut pf.direction, v, l);
}
});
ComboBox::from_id_salt(("pf-dir", i))
.width(84.0)
.selected_text(if pf.direction == ForwardDirection::Local { opts[0].1 } else { opts[1].1 })
.show_ui(ui, |ui| {
for (v, l) in opts {
ui.selectable_value(&mut pf.direction, v, l);
}
});
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
act = row_buttons(ui, i, n).or(act.take());
ui.checkbox(&mut pf.enabled, "Active").on_hover_text("Start on connect");
@@ -460,13 +471,22 @@ impl ProfileEditor {
apply(&mut c.port_forwards, act);
list_errs(ui, errs, "ssh.portForwards");
if ui.button(format!("{} Add Port Forward", icon::PLUS)).clicked() {
c.port_forwards.push(PortForward { id: new_id(), bind_host: "127.0.0.1".into(), bind_port: 1, dest_port: 1, enabled: true, ..Default::default() });
c.port_forwards.push(PortForward {
id: new_id(),
bind_host: "127.0.0.1".into(),
bind_port: 1,
dest_port: 1,
enabled: true,
..Default::default()
});
}
});
section(ui, "Startup", |ui| {
text(ui, "Startup Command", &mut c.startup_command, "Optional command to run after connecting");
label(ui, "Environment Variables");
ui.add(TextEdit::multiline(env).hint_text("KEY=VALUE (one per line)").desired_rows(3).desired_width(f32::INFINITY).font(egui::TextStyle::Monospace));
ui.add(
TextEdit::multiline(env).hint_text("KEY=VALUE (one per line)").desired_rows(3).desired_width(f32::INFINITY).font(egui::TextStyle::Monospace),
);
});
section(ui, "Login Script", |ui| login_script(ui, "ssh-login", &mut c.login_scripts));
section(ui, "SSH Agent", |ui| {
@@ -488,7 +508,9 @@ impl ProfileEditor {
if let Some((_, until)) = totp_flash {
ui.ctx().request_repaint_after(std::time::Duration::from_secs_f64((*until - s.now).max(0.0)));
}
let test = ui.add(Button::new(RichText::new(flash.as_deref().unwrap_or("Test")).font(theme::mono(12.5)))).on_hover_text("Generate a code with the saved secret");
let test = ui
.add(Button::new(RichText::new(flash.as_deref().unwrap_or("Test")).font(theme::mono(12.5))))
.on_hover_text("Generate a code with the saved secret");
if test.clicked() {
*totp_flash = Some(match (*is_new, s.svc.totp_code(&id)) {
(false, Ok(code)) => (code, s.now + 5.0),
@@ -634,7 +656,24 @@ impl ProfileEditor {
err(ui, errs, "vnc.quality");
});
section(ui, "SSH Tunnel", |ui| {
tunnel(ui, "vnc", Tunnel { on: &mut c.ssh_tunnel, host: &mut c.ssh_host, port: &mut c.ssh_port, user: &mut c.ssh_username, auth: &mut c.ssh_auth_method, key: &mut c.ssh_private_key, agent: &mut c.ssh_agent_auth, mode: &mut c.ssh_secret_mode }, keys, key_checks, secrets, errs);
tunnel(
ui,
"vnc",
Tunnel {
on: &mut c.ssh_tunnel,
host: &mut c.ssh_host,
port: &mut c.ssh_port,
user: &mut c.ssh_username,
auth: &mut c.ssh_auth_method,
key: &mut c.ssh_private_key,
agent: &mut c.ssh_agent_auth,
mode: &mut c.ssh_secret_mode,
},
keys,
key_checks,
secrets,
errs,
);
});
}
@@ -686,7 +725,24 @@ impl ProfileEditor {
}
});
section(ui, "SSH Tunnel", |ui| {
tunnel(ui, "irc", Tunnel { on: &mut c.ssh_tunnel, host: &mut c.ssh_host, port: &mut c.ssh_port, user: &mut c.ssh_username, auth: &mut c.ssh_auth_method, key: &mut c.ssh_private_key, agent: &mut c.ssh_agent_auth, mode: &mut c.ssh_secret_mode }, keys, key_checks, secrets, errs);
tunnel(
ui,
"irc",
Tunnel {
on: &mut c.ssh_tunnel,
host: &mut c.ssh_host,
port: &mut c.ssh_port,
user: &mut c.ssh_username,
auth: &mut c.ssh_auth_method,
key: &mut c.ssh_private_key,
agent: &mut c.ssh_agent_auth,
mode: &mut c.ssh_secret_mode,
},
keys,
key_checks,
secrets,
errs,
);
});
section(ui, "Reconnection", |ui| reconnect(ui, &mut c.auto_reconnect, &mut c.max_reconnect_tries));
}
@@ -696,11 +752,13 @@ impl ProfileEditor {
section(ui, "Line Settings", |ui| {
label(ui, "Baud Rate");
ui.horizontal(|ui| {
ComboBox::from_id_salt("serial-baud").selected_text(if BAUDS.contains(&c.baud_rate) { c.baud_rate.to_string() } else { "Custom".into() }).show_ui(ui, |ui| {
for b in BAUDS {
ui.selectable_value(&mut c.baud_rate, b, b.to_string());
}
});
ComboBox::from_id_salt("serial-baud")
.selected_text(if BAUDS.contains(&c.baud_rate) { c.baud_rate.to_string() } else { "Custom".into() })
.show_ui(ui, |ui| {
for b in BAUDS {
ui.selectable_value(&mut c.baud_rate, b, b.to_string());
}
});
ui.add(DragValue::new(&mut c.baud_rate).range(1..=20_000_000)).on_hover_text("Any rate the adapter supports");
});
err(ui, errs, "serial.baudRate");
@@ -709,7 +767,12 @@ impl ProfileEditor {
combo(ui, "Parity", &mut c.parity, &[(Parity::None, "None"), (Parity::Odd, "Odd"), (Parity::Even, "Even")]);
combo(ui, "Stop Bits", &mut c.stop_bits, &[(1, "1"), (2, "2")]);
err(ui, errs, "serial.stopBits");
combo(ui, "Flow Control", &mut c.flow_control, &[(FlowControl::None, "None"), (FlowControl::Xonxoff, "XON/XOFF (software)"), (FlowControl::Rtscts, "RTS/CTS (hardware)")]);
combo(
ui,
"Flow Control",
&mut c.flow_control,
&[(FlowControl::None, "None"), (FlowControl::Xonxoff, "XON/XOFF (software)"), (FlowControl::Rtscts, "RTS/CTS (hardware)")],
);
});
section(ui, "Behaviour", |ui| {
line_ending(ui, &mut c.line_ending);
@@ -799,11 +862,7 @@ fn prep(p: &mut Profile) {
}
fn parse_env(text: &str) -> BTreeMap<String, String> {
text.lines()
.filter_map(|l| l.split_once('='))
.map(|(k, v)| (k.trim().to_string(), v.trim().to_string()))
.filter(|(k, _)| !k.is_empty())
.collect()
text.lines().filter_map(|l| l.split_once('=')).map(|(k, v)| (k.trim().to_string(), v.trim().to_string())).filter(|(k, _)| !k.is_empty()).collect()
}
/// "ssh.jumpHosts[2].host" → 2
@@ -1059,7 +1118,9 @@ fn login_script(ui: &mut Ui, id: &str, steps: &mut Vec<LoginScriptStep>) {
} else {
ui.add_space(56.0 + ui.spacing().item_spacing.x);
}
ui.add(TextEdit::singleline(&mut st.value).hint_text(if wait { "Text to match…" } else { "Text to send…" }).desired_width(ui.available_width()));
ui.add(
TextEdit::singleline(&mut st.value).hint_text(if wait { "Text to match…" } else { "Text to send…" }).desired_width(ui.available_width()),
);
});
});
}
+12 -2
View File
@@ -24,7 +24,16 @@ pub struct QuickConnect {
impl Default for QuickConnect {
fn default() -> Self {
QuickConnect { open: false, focus: false, protocol: Protocol::Ssh, host: String::new(), port: 22, username: String::new(), nick: "nexus".into(), ports: vec![] }
QuickConnect {
open: false,
focus: false,
protocol: Protocol::Ssh,
host: String::new(),
port: 22,
username: String::new(),
nick: "nexus".into(),
ports: vec![],
}
}
}
@@ -97,7 +106,8 @@ impl QuickConnect {
let r = ui
.horizontal(|ui| {
let w = if serial { ui.available_width() - 34.0 } else { ui.available_width() };
let r = ui.add(TextEdit::singleline(&mut self.host).hint_text(if serial { "/dev/ttyUSB0 or COM3" } else { "e.g. 192.168.1.1" }).desired_width(w));
let r = ui
.add(TextEdit::singleline(&mut self.host).hint_text(if serial { "/dev/ttyUSB0 or COM3" } else { "e.g. 192.168.1.1" }).desired_width(w));
if serial {
ui.menu_button(icon::CARET_DOWN, |ui| {
if self.ports.is_empty() {
+6 -2
View File
@@ -227,7 +227,9 @@ impl RawView {
s.warn("Nothing to save");
return;
}
let Some(path) = rfd::FileDialog::new().set_file_name("capture.json").add_filter("JSON", &["json"]).save_file() else { return };
let Some(path) = rfd::FileDialog::new().set_file_name("capture.json").add_filter("JSON", &["json"]).save_file() else {
return;
};
match s.svc.sessions.raw_save_capture(&self.session, &path) {
Ok(()) => s.success("Capture saved"),
Err(e) => s.error(format!("Save failed: {e}")),
@@ -450,7 +452,9 @@ fn hex_job(line: &str, font: &FontId, t: &Tokens, fg: Color32) -> LayoutJob {
/// HH:MM:SS for today, otherwise "Mon DD HH:MM:SS" (the web build's formatTimestamp).
fn format_time(ms: i64) -> String {
use chrono::{Local, TimeZone};
let Some(d) = Local.timestamp_millis_opt(ms).single() else { return String::new() };
let Some(d) = Local.timestamp_millis_opt(ms).single() else {
return String::new();
};
if d.date_naive() == Local::now().date_naive() { d.format("%H:%M:%S").to_string() } else { d.format("%b %d %H:%M:%S").to_string() }
}
+31 -10
View File
@@ -15,7 +15,7 @@ const SPEEDS: [f64; 5] = [0.5, 1.0, 2.0, 5.0, 10.0];
/// m:ss, as the JS `_formatSeconds`.
pub fn mmss(secs: f64) -> String {
if !(secs > 0.0) {
if secs.is_nan() || secs <= 0.0 {
return "0:00".into();
}
let s = secs.floor() as u64;
@@ -97,7 +97,18 @@ pub struct Recordings {
impl Default for Recordings {
fn default() -> Self {
Recordings { open: false, list: vec![], info: None, loading: false, rx: None, age: 30, size: 1 << 30, status: String::new(), confirm_delete: None, playback: None }
Recordings {
open: false,
list: vec![],
info: None,
loading: false,
rx: None,
age: 30,
size: 1 << 30,
status: String::new(),
confirm_delete: None,
playback: None,
}
}
}
@@ -150,7 +161,8 @@ impl Recordings {
}
let total = events.last().map_or(1.0, |e| e.elapsed).max(f64::EPSILON);
let title = if header.title.is_empty() { title } else { header.title };
let mut p = Playback { title, term: TermView::new(10_000, 13.0, CursorStyle::Block), events, total, pos: 0.0, next: 0, playing: false, speed: 1.0 };
let mut p =
Playback { title, term: TermView::new(10_000, 13.0, CursorStyle::Block), events, total, pos: 0.0, next: 0, playing: false, speed: 1.0 };
p.play(); // autoplay
self.playback = Some(p);
}
@@ -222,7 +234,11 @@ impl Recordings {
ui.set_width(ui.available_width() - 64.0);
ui.label(RichText::new(if r.title.is_empty() { &r.id } else { &r.title }).font(theme::semibold(13.0)));
let date = r.created_at.with_timezone(&chrono::Local).format("%Y-%m-%d %H:%M");
ui.label(RichText::new(format!("{date} · {} · {} · {}×{}", mmss(r.duration), widgets::human_size(r.size), r.width, r.height)).size(11.5).color(t.text_dim));
ui.label(
RichText::new(format!("{date} · {} · {} · {}×{}", mmss(r.duration), widgets::human_size(r.size), r.width, r.height))
.size(11.5)
.color(t.text_dim),
);
});
if widgets::icon_button(ui, icon::PLAY, "Play").clicked() {
play = Some(i);
@@ -245,7 +261,9 @@ impl Recordings {
}
fn delete_dialog(&mut self, ctx: &egui::Context, s: &mut Shared) {
let Some(r) = &self.confirm_delete else { return };
let Some(r) = &self.confirm_delete else {
return;
};
let (mut yes, mut no) = (false, ctx.input(|i| i.key_pressed(Key::Escape)));
let name = if r.title.is_empty() { r.id.clone() } else { r.title.clone() };
crate::chrome::modal(ctx, "rec-delete", 380.0, |ui| {
@@ -309,11 +327,14 @@ impl Recordings {
});
});
});
egui::Frame::NONE.fill(egui::Color32::from_rgba_unmultiplied(theme.background[0], theme.background[1], theme.background[2], 255)).corner_radius(t.radius).show(ui, |ui| {
ui.set_min_size(ui.available_size());
// Read-only: keyboard input and terminal replies are dropped.
let _ = p.term.ui(ui, theme, false);
});
egui::Frame::NONE
.fill(egui::Color32::from_rgba_unmultiplied(theme.background[0], theme.background[1], theme.background[2], 255))
.corner_radius(t.radius)
.show(ui, |ui| {
ui.set_min_size(ui.available_size());
// Read-only: keyboard input and terminal replies are dropped.
let _ = p.term.ui(ui, theme, false);
});
});
if !open {
self.playback = None;
+73 -19
View File
@@ -19,14 +19,27 @@ use std::sync::{Arc, Mutex};
/// Worker results, applied on the UI thread.
enum Done {
Listed { session: String, path: String, files: Result<Vec<FileEntry>, String> },
Picker { session: String, result: Result<(String, Vec<FileEntry>, bool), String> },
Listed {
session: String,
path: String,
files: Result<Vec<FileEntry>, String>,
},
Picker {
session: String,
result: Result<(String, Vec<FileEntry>, bool), String>,
},
Refresh(String),
TransferEnded { session: String, path: String },
TransferEnded {
session: String,
path: String,
},
/// Always shown.
Toast(String),
/// Shown only while the panel for `session` is open (otherwise per-file toasts cover it).
Summary { session: String, text: String },
Summary {
session: String,
text: String,
},
}
#[derive(Clone)]
@@ -372,10 +385,14 @@ impl Sftp {
fn download(&mut self, s: &Shared, session: &str, files: Vec<FileEntry>) {
let targets: Vec<(FileEntry, PathBuf)> = if files.len() == 1 {
let Some(p) = rfd::FileDialog::new().set_file_name(&files[0].name).save_file() else { return };
let Some(p) = rfd::FileDialog::new().set_file_name(&files[0].name).save_file() else {
return;
};
vec![(files[0].clone(), p)]
} else {
let Some(dir) = rfd::FileDialog::new().set_title("Download to folder").pick_folder() else { return };
let Some(dir) = rfd::FileDialog::new().set_title("Download to folder").pick_folder() else {
return;
};
files.into_iter().filter_map(|e| safe_sftp_upload_name(&e.name).ok().map(|n| (e, dir.join(n)))).collect()
};
for (e, _) in &targets {
@@ -422,7 +439,14 @@ impl Sftp {
}
/// Runs a single SFTP operation, then toasts `ok` and refreshes the listing.
fn op(&mut self, s: &Shared, session: &str, ok: &'static str, what: &'static str, f: impl FnOnce(&Service, &str) -> nexus_core::Result<()> + Send + 'static) {
fn op(
&mut self,
s: &Shared,
session: &str,
ok: &'static str,
what: &'static str,
f: impl FnOnce(&Service, &str) -> nexus_core::Result<()> + Send + 'static,
) {
let sid = session.to_string();
self.work(s, move |svc, out| {
match f(svc, &sid) {
@@ -460,7 +484,9 @@ impl Sftp {
/// The dock panel.
pub fn ui(&mut self, ui: &mut Ui, s: &mut Shared) {
self.drain(s);
let Some(session) = self.open_for.clone() else { return };
let Some(session) = self.open_for.clone() else {
return;
};
if !self.panels.contains_key(&session) {
self.navigate(s, &session, None);
}
@@ -535,7 +561,9 @@ impl Sftp {
});
});
let Some(p) = self.panels.get(&session) else { return };
let Some(p) = self.panels.get(&session) else {
return;
};
if let Some(go) = breadcrumb(ui, &p.cwd) {
act = Some(Act::Nav(go));
}
@@ -555,7 +583,11 @@ impl Sftp {
ui.add(egui::Label::new(base_name(&x.path)).truncate()).on_hover_text(&x.path);
ui.add(egui::ProgressBar::new(frac).desired_height(4.0).fill(t.accent));
let total = if x.total > 0 { widgets::human_size(x.total) } else { "?".into() };
ui.label(RichText::new(format!("{} / {total} ({:.0}%)", widgets::human_size(x.transferred), frac * 100.0)).size(11.0).color(t.text_faint));
ui.label(
RichText::new(format!("{} / {total} ({:.0}%)", widgets::human_size(x.transferred), frac * 100.0))
.size(11.0)
.color(t.text_faint),
);
});
});
}
@@ -595,7 +627,13 @@ impl Sftp {
if p.selected.contains(&e.path) {
ui.painter().rect_filled(r.expand2(vec2(6.0, 0.0)), 3.0, t.row_selected);
}
ui.painter().text(r.left_center() + vec2(8.0, 0.0), egui::Align2::CENTER_CENTER, file_icon(e), egui::FontId::proportional(14.0), if e.is_dir { t.accent } else { t.text_dim });
ui.painter().text(
r.left_center() + vec2(8.0, 0.0),
egui::Align2::CENTER_CENTER,
file_icon(e),
egui::FontId::proportional(14.0),
if e.is_dir { t.accent } else { t.text_dim },
);
let meta_w = if e.is_dir { 0.0 } else { 72.0 };
let nr = egui::Rect::from_min_max(egui::pos2(r.min.x + 22.0, r.min.y), egui::pos2(r.max.x - meta_w - 4.0, r.max.y));
ui.scope_builder(egui::UiBuilder::new().max_rect(nr).layout(Layout::left_to_right(Align::Center)), |ui| {
@@ -603,7 +641,13 @@ impl Sftp {
});
if !e.is_dir {
let mr = egui::Rect::from_min_max(egui::pos2(r.max.x - meta_w, r.min.y), r.max);
ui.painter().text(mr.right_center(), egui::Align2::RIGHT_CENTER, widgets::human_size(e.size), egui::FontId::proportional(11.5), t.text_faint);
ui.painter().text(
mr.right_center(),
egui::Align2::RIGHT_CENTER,
widgets::human_size(e.size),
egui::FontId::proportional(11.5),
t.text_faint,
);
if e.modified_at > 0 {
ui.interact(mr, ui.id().with(("meta", i)), Sense::hover()).on_hover_text(modified(e.modified_at));
}
@@ -718,14 +762,14 @@ impl Sftp {
}
}
// --- dialogs --------------------------------------------------------------------------
/// Modal dialogs (file drop, directory picker), drawn every frame.
pub fn dialogs(&mut self, ctx: &egui::Context, s: &mut Shared) {
self.drain(s);
let Some(mut d) = self.dialog.take() else { return };
let Some(mut d) = self.dialog.take() else {
return;
};
let t = Tokens::get(ctx);
let esc = ctx.input(|i| i.key_pressed(Key::Escape));
let enter = ctx.input(|i| i.key_pressed(Key::Enter));
@@ -802,7 +846,9 @@ impl Sftp {
modal(ctx, "sftp-drop", 420.0, |ui| {
ui.label(RichText::new(format!("{} File Drop", icon::FILE_ARROW_UP)).font(theme::semibold(15.0)));
ui.label(RichText::new(title).strong());
ui.label(RichText::new(format!("Choose what to do with the dropped {}.", if paths.len() == 1 { "file" } else { "files" })).color(t.text_dim));
ui.label(
RichText::new(format!("Choose what to do with the dropped {}.", if paths.len() == 1 { "file" } else { "files" })).color(t.text_dim),
);
ui.add_space(8.0);
ui.horizontal(|ui| {
upload = ui
@@ -894,8 +940,15 @@ impl Sftp {
// Keyboard: ↑↓ move (skipping unreadable folders), Enter uses, Backspace goes up.
if ready {
let (down, up, back) = ctx.input_mut(|i| (i.consume_key(Modifiers::NONE, Key::ArrowDown), i.consume_key(Modifiers::NONE, Key::ArrowUp), i.key_pressed(Key::Backspace)));
let delta: isize = if down { 1 } else if up { -1 } else { 0 };
let (down, up, back) = ctx
.input_mut(|i| (i.consume_key(Modifiers::NONE, Key::ArrowDown), i.consume_key(Modifiers::NONE, Key::ArrowUp), i.key_pressed(Key::Backspace)));
let delta: isize = if down {
1
} else if up {
-1
} else {
0
};
if delta != 0 && !visible.is_empty() {
let n = visible.len() as isize;
let mut idx = pk.cursor.map_or(if delta > 0 { -1 } else { n }, |c| c as isize);
@@ -1003,7 +1056,8 @@ impl Sftp {
ui.separator();
ui.horizontal(|ui| {
let suffix = if sel.is_none() && !pk.cwd_writable { " (read only)" } else { "" };
ui.add(egui::Label::new(RichText::new(format!("{target}{suffix}")).font(theme::mono(11.5)).color(t.text_dim)).truncate()).on_hover_text(&target);
ui.add(egui::Label::new(RichText::new(format!("{target}{suffix}")).font(theme::mono(11.5)).color(t.text_dim)).truncate())
.on_hover_text(&target);
let status = match (sel.is_some(), writable) {
(_, true) => "",
(true, false) => "No write permission",
+35 -7
View File
@@ -74,7 +74,7 @@ fn list(app: &mut App, ui: &mut Ui) {
fuzzy_score(&fields, &q).map(|s| (s, p.clone()))
})
.collect();
hits.sort_by(|a, b| b.0.cmp(&a.0));
hits.sort_by_key(|h| std::cmp::Reverse(h.0));
if hits.is_empty() {
widgets::empty(ui, icon::MAGNIFYING_GLASS, "No matches", "Try a host, name, tag or protocol.");
}
@@ -91,7 +91,7 @@ fn list(app: &mut App, ui: &mut Ui) {
section(app, ui, "★ Favourites", "favourites", &favs);
}
let mut recent: Vec<&Profile> = profiles.iter().filter(|p| p.last_connected.is_some()).collect();
recent.sort_by(|a, b| b.last_connected.cmp(&a.last_connected));
recent.sort_by_key(|p| std::cmp::Reverse(p.last_connected));
recent.truncate(RECENT);
if !recent.is_empty() {
section(app, ui, "Recent", "recent", &recent);
@@ -169,7 +169,13 @@ fn local_row(app: &mut App, ui: &mut Ui) {
if resp.hovered() {
ui.painter().rect_filled(r, 6.0, t.hover);
}
ui.painter().text(r.left_center() + vec2(10.0, 0.0), Align2::LEFT_CENTER, icon::TERMINAL_WINDOW, egui::FontId::proportional(15.0), crate::views::protocol_color(nexus_core::models::Protocol::Local));
ui.painter().text(
r.left_center() + vec2(10.0, 0.0),
Align2::LEFT_CENTER,
icon::TERMINAL_WINDOW,
egui::FontId::proportional(15.0),
crate::views::protocol_color(nexus_core::models::Protocol::Local),
);
ui.painter().text(r.left_center() + vec2(32.0, 0.0), Align2::LEFT_CENTER, "Local Machine", egui::FontId::proportional(13.0), t.text);
if resp.on_hover_text("Open a terminal on this computer").clicked() {
app.connect_local();
@@ -204,7 +210,14 @@ fn row(app: &mut App, ui: &mut Ui, p: &Profile, section: &str) {
if p.favourite {
ui.painter().text(r.right_center() - vec2(36.0, 0.0), Align2::RIGHT_CENTER, "★", egui::FontId::proportional(11.0), t.warning);
}
let tip = format!("{}\n{} {}:{}{}", name, protocol_badge(p.protocol), p.host, p.port, if p.description.is_empty() { String::new() } else { format!("\n{}", p.description) });
let tip = format!(
"{}\n{} {}:{}{}",
name,
protocol_badge(p.protocol),
p.host,
p.port,
if p.description.is_empty() { String::new() } else { format!("\n{}", p.description) }
);
let resp = resp.on_hover_text(tip);
let multi = ui.input(|i| i.modifiers.command);
if resp.double_clicked() {
@@ -281,16 +294,31 @@ fn bulk_bar(app: &mut App, ui: &mut Ui) {
}
ui.menu_button(format!("{} Tags", icon::TAG), |ui| {
if ui.button("Add tags…").clicked() {
app.dialog = Some(Dialog::Input { title: "Add tags".into(), label: "Comma-separated tags to add".into(), value: String::new(), then: InputThen::Tags { profiles: ids.clone(), replace: false } });
app.dialog = Some(Dialog::Input {
title: "Add tags".into(),
label: "Comma-separated tags to add".into(),
value: String::new(),
then: InputThen::Tags { profiles: ids.clone(), replace: false },
});
ui.close();
}
if ui.button("Replace tags…").clicked() {
app.dialog = Some(Dialog::Input { title: "Replace tags".into(), label: "Comma-separated tags".into(), value: String::new(), then: InputThen::Tags { profiles: ids.clone(), replace: true } });
app.dialog = Some(Dialog::Input {
title: "Replace tags".into(),
label: "Comma-separated tags".into(),
value: String::new(),
then: InputThen::Tags { profiles: ids.clone(), replace: true },
});
ui.close();
}
});
if ui.small_button(format!("{} Move group", icon::FOLDER)).clicked() {
app.dialog = Some(Dialog::Input { title: "Move to group".into(), label: "Group name (empty for Ungrouped)".into(), value: String::new(), then: InputThen::MoveGroup { profiles: ids.clone() } });
app.dialog = Some(Dialog::Input {
title: "Move to group".into(),
label: "Group name (empty for Ungrouped)".into(),
value: String::new(),
then: InputThen::MoveGroup { profiles: ids.clone() },
});
}
if ui.small_button(format!("{} Delete", icon::TRASH)).clicked() {
app.dialog = Some(Dialog::Delete { profiles: ids.clone() });
+25 -4
View File
@@ -71,7 +71,15 @@ pub struct Snippets {
impl Default for Snippets {
fn default() -> Self {
Snippets { open: false, list: vec![], search: String::new(), pane: Pane::Empty("Select a snippet or create a new one"), confirm_delete: None, vars: None, loaded: false }
Snippets {
open: false,
list: vec![],
search: String::new(),
pane: Pane::Empty("Select a snippet or create a new one"),
confirm_delete: None,
vars: None,
loaded: false,
}
}
}
@@ -263,7 +271,9 @@ impl Snippets {
/// Resolves variables then types the command (plus newline) into the focused session.
fn send(&mut self, s: &mut Shared, command: &str) {
let Some(id) = s.focused_session() else { return s.error("No active session") };
let Some(id) = s.focused_session() else {
return s.error("No active session");
};
if s.session_state(&id) != Some(SessionState::Connected) {
return s.error("Session is not connected");
}
@@ -306,7 +316,9 @@ impl Snippets {
}
fn delete_dialog(&mut self, ctx: &egui::Context, s: &mut Shared) {
let Some(id) = self.confirm_delete.clone() else { return };
let Some(id) = self.confirm_delete.clone() else {
return;
};
let name = self.list.iter().find(|x| x.id == id).map(|x| x.name.clone()).unwrap_or_default();
let (mut yes, mut no) = (false, ctx.input(|i| i.key_pressed(Key::Escape)));
crate::chrome::modal(ctx, "snippet-delete", 360.0, |ui| {
@@ -335,7 +347,16 @@ impl Snippets {
fn blank() -> Snippet {
let now = nexus_core::models::now();
Snippet { id: String::new(), name: String::new(), command: String::new(), description: String::new(), folder: String::new(), tags: vec![], created_at: now, updated_at: now }
Snippet {
id: String::new(),
name: String::new(),
command: String::new(),
description: String::new(),
folder: String::new(),
tags: vec![],
created_at: now,
updated_at: now,
}
}
fn send_text(s: &mut Shared, text: String) {
+40 -9
View File
@@ -52,7 +52,13 @@ impl Split {
fn at(&mut self, path: &[bool]) -> &mut Split {
match (self, path.split_first()) {
(Split::Node { a, b, .. }, Some((side, rest))) => if *side { b.at(rest) } else { a.at(rest) },
(Split::Node { a, b, .. }, Some((side, rest))) => {
if *side {
b.at(rest)
} else {
a.at(rest)
}
}
(s, _) => s,
}
}
@@ -124,20 +130,32 @@ fn divide(r: Rect, dir: Dir, ratio: f32) -> (Rect, Rect, Rect) {
match dir {
Dir::Right => {
let x = r.left() + (r.width() - GAP) * ratio;
(Rect::from_min_max(r.min, pos2(x, r.bottom())), Rect::from_min_max(pos2(x + GAP, r.top()), r.max), Rect::from_min_max(pos2(x, r.top()), pos2(x + GAP, r.bottom())))
(
Rect::from_min_max(r.min, pos2(x, r.bottom())),
Rect::from_min_max(pos2(x + GAP, r.top()), r.max),
Rect::from_min_max(pos2(x, r.top()), pos2(x + GAP, r.bottom())),
)
}
Dir::Down => {
let y = r.top() + (r.height() - GAP) * ratio;
(Rect::from_min_max(r.min, pos2(r.right(), y)), Rect::from_min_max(pos2(r.left(), y + GAP), r.max), Rect::from_min_max(pos2(r.left(), y), pos2(r.right(), y + GAP)))
(
Rect::from_min_max(r.min, pos2(r.right(), y)),
Rect::from_min_max(pos2(r.left(), y + GAP), r.max),
Rect::from_min_max(pos2(r.left(), y), pos2(r.right(), y + GAP)),
)
}
}
}
/// Splits the focused pane of the active tab.
pub fn split_focused(app: &mut App, dir: Dir) {
let Some(tab_id) = app.s.active.clone() else { return };
let Some(tab_id) = app.s.active.clone() else {
return;
};
let focused = app.s.focused_session().unwrap_or(tab_id.clone());
let Some(tab) = app.s.tabs.iter_mut().find(|t| t.id == tab_id) else { return };
let Some(tab) = app.s.tabs.iter_mut().find(|t| t.id == tab_id) else {
return;
};
match &mut tab.split {
None => tab.split = Some(Split::Node { dir, ratio: 0.5, a: Box::new(Split::Leaf(Some(tab_id.clone()))), b: Box::new(Split::Leaf(None)) }),
Some(sp) => {
@@ -152,7 +170,9 @@ pub fn split_focused(app: &mut App, dir: Dir) {
/// removed too: the next pane takes over the tab.
pub fn remove_session(s: &mut Shared, session: &str) {
for i in 0..s.tabs.len() {
let Some(sp) = &mut s.tabs[i].split else { continue };
let Some(sp) = &mut s.tabs[i].split else {
continue;
};
let mut path = vec![];
if !sp.find(session, &mut path) {
continue;
@@ -202,7 +222,8 @@ pub fn render(app: &mut App, ui: &mut Ui, tab_id: &str) {
};
let min = (MIN_PANE / len).min(0.45);
let ratio = ((pos - start) / len).clamp(min, 1.0 - min);
if let Some(Split::Node { ratio: r, .. }) = app.s.tabs.iter_mut().find(|tb| tb.id == tab_id).and_then(|tb| tb.split.as_mut()).map(|sp| sp.at(&path)) {
if let Some(Split::Node { ratio: r, .. }) = app.s.tabs.iter_mut().find(|tb| tb.id == tab_id).and_then(|tb| tb.split.as_mut()).map(|sp| sp.at(&path))
{
*r = ratio;
}
}
@@ -213,9 +234,19 @@ pub fn render(app: &mut App, ui: &mut Ui, tab_id: &str) {
let body = Rect::from_min_max(pos2(rect.left(), head.bottom()), rect.max);
let focused = session.is_some() && app.s.focused == session;
ui.painter().rect_filled(head, 0.0, if focused { t.card } else { t.tab_strip });
let title = session.as_deref().and_then(|s| app.s.pane(s)).map(|p| (p.info.tab_name.clone(), protocol_color(p.info.protocol))).unwrap_or(("New pane".into(), t.text_faint));
let title = session
.as_deref()
.and_then(|s| app.s.pane(s))
.map(|p| (p.info.tab_name.clone(), protocol_color(p.info.protocol)))
.unwrap_or(("New pane".into(), t.text_faint));
ui.painter().circle_filled(head.left_center() + vec2(10.0, 0.0), 3.5, title.1);
ui.painter().with_clip_rect(head.shrink2(vec2(24.0, 0.0))).text(head.left_center() + vec2(20.0, 0.0), Align2::LEFT_CENTER, title.0, egui::FontId::proportional(11.5), if focused { t.text } else { t.text_dim });
ui.painter().with_clip_rect(head.shrink2(vec2(24.0, 0.0))).text(
head.left_center() + vec2(20.0, 0.0),
Align2::LEFT_CENTER,
title.0,
egui::FontId::proportional(11.5),
if focused { t.text } else { t.text_dim },
);
let xr = Rect::from_center_size(head.right_center() - vec2(12.0, 0.0), vec2(16.0, 16.0));
if widgets::icon_button(&mut ui.new_child(egui::UiBuilder::new().max_rect(xr)), icon::X, "Close pane").clicked() {
close = Some((path.clone(), session.clone()));
+7 -3
View File
@@ -90,7 +90,8 @@ impl SshKeys {
}
});
});
ui.add(egui::Label::new(RichText::new(&k.public_key).font(theme::mono(11.0)).color(t.text_dim)).truncate()).on_hover_text(&k.public_key);
ui.add(egui::Label::new(RichText::new(&k.public_key).font(theme::mono(11.0)).color(t.text_dim)).truncate())
.on_hover_text(&k.public_key);
});
ui.add_space(2.0);
}
@@ -111,7 +112,8 @@ impl SshKeys {
s.error("Passphrases do not match");
} else {
let (svc, kind, bits, pass) = (s.svc.clone(), f.kind, f.bits, f.pass.clone());
self.job = Some(Job::spawn(ctx, move || svc.generate_ssh_key(&name, kind, bits, &pass).map(|_| name).map_err(|e| e.to_string())));
self.job =
Some(Job::spawn(ctx, move || svc.generate_ssh_key(&name, kind, bits, &pass).map(|_| name).map_err(|e| e.to_string())));
}
}
if self.job.is_none() && ui.button("Cancel").clicked() {
@@ -125,7 +127,9 @@ impl SshKeys {
}
fn delete_dialog(&mut self, ctx: &egui::Context, s: &mut Shared) {
let Some(name) = self.confirm_delete.clone() else { return };
let Some(name) = self.confirm_delete.clone() else {
return;
};
let t = Tokens::get(ctx);
let mut done = false;
let r = egui::Modal::new(egui::Id::new("delete-key")).show(ctx, |ui| {
+6 -24
View File
@@ -8,36 +8,27 @@ use std::collections::HashSet;
use std::sync::Arc;
/// Things a feature asks the main window to do (handled once per frame, in order).
#[allow(clippy::large_enum_variant)] // a per-frame queue; boxing buys nothing
pub enum Request {
/// Open the profile editor for a new profile (optionally pre-set protocol / folder).
NewProfile { protocol: Option<Protocol>, folder: String },
NewProfile {
protocol: Option<Protocol>,
folder: String,
},
EditProfile(String),
Connect(String),
ConnectQuick(Profile),
ConnectLocal,
/// Reload `Shared::profiles` from the database.
ReloadProfiles,
/// Re-read and apply preferences (theme, terminal theme, fonts…).
ReloadPreferences,
QuickConnect,
Settings(SettingsTab),
SshKeys,
ExportEncrypted(Vec<String>),
ImportEncrypted,
ExportJson,
ImportJson,
Recordings,
Snippets,
Triggers,
Sftp(String),
PortForwards(String),
/// Type text into the active session (snippets).
SendToActive(String),
/// Bytes to a specific session.
Write(String, Vec<u8>),
Disconnect(String),
CommandPalette,
About,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
@@ -174,11 +165,6 @@ impl Shared {
self.panes.get_mut(id)
}
/// The tab that shows `session` (its own, or the one it's split into).
pub fn tab_of(&self, session: &str) -> Option<&Tab> {
self.tabs.iter().find(|t| t.id == session || t.split.as_ref().is_some_and(|sp| sp.sessions().iter().any(|x| x == session)))
}
/// The session keyboard actions apply to: the focused pane, else the active tab.
pub fn focused_session(&self) -> Option<String> {
self.focused.clone().or_else(|| self.active.clone())
@@ -208,9 +194,5 @@ impl Shared {
/// Formats a command-key shortcut for menus: "⌘K" on macOS, "Ctrl+K" elsewhere.
pub fn keys(s: &str) -> String {
if cfg!(target_os = "macos") {
s.replace("Mod+Shift+", "⇧⌘").replace("Mod+", "⌘")
} else {
s.replace("Mod+", "Ctrl+")
}
if cfg!(target_os = "macos") { s.replace("Mod+Shift+", "⇧⌘").replace("Mod+", "⌘") } else { s.replace("Mod+", "Ctrl+") }
}
+15 -3
View File
@@ -141,7 +141,13 @@ fn strip(app: &mut App, ui: &mut Ui) {
if sftp {
let fr = Rect::from_center_size(pos2(body.right() - 33.0, body.center().y), vec2(16.0, 16.0));
let fresp = ui.interact(fr, ui.id().with(("sftp", id)), Sense::click());
let c = if app.sftp.open_for() == Some(id.as_str()) { t.accent } else if fresp.hovered() { t.text } else { t.text_faint };
let c = if app.sftp.open_for() == Some(id.as_str()) {
t.accent
} else if fresp.hovered() {
t.text
} else {
t.text_faint
};
ui.painter().text(fr.center(), Align2::CENTER_CENTER, icon::FOLDER_SIMPLE, egui::FontId::proportional(12.0), c);
if fresp.on_hover_text("SFTP browser").clicked() {
app.s.request(Request::Sftp(id.clone()));
@@ -211,7 +217,11 @@ fn strip(app: &mut App, ui: &mut Ui) {
if widgets::icon_button(&mut right, icon::PLUS, "New connection").clicked() {
app.s.request(Request::NewProfile { protocol: None, folder: String::new() });
}
let b = widgets::icon_button(&mut right, icon::BROADCAST, if app.s.broadcast { "Broadcast ON — click to stop, right-click for targets" } else { "Broadcast input (right-click to pick targets)" });
let b = widgets::icon_button(
&mut right,
icon::BROADCAST,
if app.s.broadcast { "Broadcast ON — click to stop, right-click for targets" } else { "Broadcast input (right-click to pick targets)" },
);
if app.s.broadcast {
right.painter().rect_stroke(b.rect, 4.0, Stroke::new(1.5, t.warning), egui::StrokeKind::Inside);
}
@@ -281,7 +291,9 @@ fn tab_action(app: &mut App, id: &str, a: &str) {
/// Draws one session into `rect`.
pub fn pane(app: &mut App, ui: &mut Ui, id: &str, rect: Rect) {
let Some(mut pane) = app.s.panes.remove(id) else { return };
let Some(mut pane) = app.s.panes.remove(id) else {
return;
};
let t = Tokens::get(ui.ctx());
let theme_id = app.s.prefs.terminal_theme.clone();
let focused_tab = app.s.focused.as_deref() == Some(id) || (app.s.focused.is_none() && app.s.active.as_deref() == Some(id));
+16 -28
View File
@@ -143,14 +143,6 @@ impl TermView {
self.focus_requested = true;
}
pub fn alt_screen(&self) -> bool {
self.term.mode().contains(TermMode::ALT_SCREEN)
}
pub fn has_selection(&self) -> bool {
self.term.selection.as_ref().is_some_and(|s| !s.is_empty())
}
pub fn selection_text(&self) -> Option<String> {
self.term.selection_to_string().filter(|s| !s.is_empty())
}
@@ -284,13 +276,13 @@ impl TermView {
let focused = ui.memory(|m| m.has_focus(id));
out.focused = focused;
if focused {
ui.memory_mut(|m| {
m.set_focus_lock_filter(id, egui::EventFilter { tab: true, horizontal_arrows: true, vertical_arrows: true, escape: true })
});
ui.memory_mut(|m| m.set_focus_lock_filter(id, egui::EventFilter { tab: true, horizontal_arrows: true, vertical_arrows: true, escape: true }));
self.keyboard(ui, &mut out);
let cur = self.term.grid().cursor.point;
let cursor_rect = Rect::from_min_size(origin + vec2(cur.column.0 as f32 * cw, cur.line.0 as f32 * ch), vec2(cw, ch));
ui.output_mut(|o| o.ime = Some(egui::output::IMEOutput { purpose: egui::IMEPurpose::Terminal, rect, cursor_rect, should_interrupt_composition: false }));
ui.output_mut(|o| {
o.ime = Some(egui::output::IMEOutput { purpose: egui::IMEPurpose::Terminal, rect, cursor_rect, should_interrupt_composition: false })
});
}
self.mouse(ui, &resp, origin, cw, ch, &mut out);
@@ -475,7 +467,9 @@ impl TermView {
continue;
}
if *pressed {
if modifiers.command && let Some(url) = self.url_at(origin, cw, ch, *pos) {
if modifiers.command
&& let Some(url) = self.url_at(origin, cw, ch, *pos)
{
ui.ctx().open_url(egui::OpenUrl::new_tab(url));
continue;
}
@@ -560,11 +554,8 @@ impl TermView {
let selection = self.term.selection.as_ref().and_then(|s| s.to_range(&self.term));
let sel_bg = rgb(theme.selection);
self.refresh_find();
let finds: Vec<(i32, usize, usize, bool)> = self
.find
.as_ref()
.map(|f| f.matches.iter().enumerate().map(|(i, &(l, a, b))| (l, a, b, i == f.current)).collect())
.unwrap_or_default();
let finds: Vec<(i32, usize, usize, bool)> =
self.find.as_ref().map(|f| f.matches.iter().enumerate().map(|(i, &(l, a, b))| (l, a, b, i == f.current)).collect()).unwrap_or_default();
let ncols = self.cols as usize;
for vr in 0..self.rows as i32 {
let line = Line(vr - offset);
@@ -818,7 +809,7 @@ pub fn key_bytes(key: Key, m: Modifiers, mode: TermMode) -> Option<Vec<u8>> {
Key::F10 => tilde(21),
Key::F11 => tilde(23),
Key::F12 => tilde(24),
_ if m.ctrl && !m.command_only() => {
_ if m.ctrl && !mac_cmd_only(m) => {
let b = match key {
Key::Space | Key::Num2 => 0,
Key::OpenBracket | Key::Num3 => 0x1b,
@@ -840,15 +831,9 @@ pub fn key_bytes(key: Key, m: Modifiers, mode: TermMode) -> Option<Vec<u8>> {
})
}
trait CommandOnly {
fn command_only(&self) -> bool;
}
impl CommandOnly for Modifiers {
/// On macOS, Cmd is the app's modifier; Ctrl still produces control codes.
fn command_only(&self) -> bool {
cfg!(target_os = "macos") && self.mac_cmd && !self.ctrl
}
/// On macOS Cmd is the app's modifier while Ctrl still produces control codes.
fn mac_cmd_only(m: Modifiers) -> bool {
cfg!(target_os = "macos") && m.mac_cmd && !m.ctrl
}
#[cfg(test)]
@@ -862,6 +847,9 @@ mod tests {
assert_eq!(key_bytes(Key::ArrowUp, none, TermMode::APP_CURSOR).unwrap(), b"\x1bOA");
assert_eq!(key_bytes(Key::ArrowLeft, Modifiers::CTRL, TermMode::empty()).unwrap(), b"\x1b[1;5D");
assert_eq!(key_bytes(Key::C, Modifiers::CTRL, TermMode::empty()).unwrap(), [3]);
// egui reports Ctrl as ctrl + command on Linux/Windows; it must still send a control code.
let ctrl_cmd = Modifiers { ctrl: true, command: true, ..Default::default() };
assert_eq!(key_bytes(Key::D, ctrl_cmd, TermMode::empty()).unwrap(), [4]);
assert_eq!(key_bytes(Key::F5, none, TermMode::empty()).unwrap(), b"\x1b[15~");
assert_eq!(key_bytes(Key::Backspace, none, TermMode::empty()).unwrap(), [0x7f]);
assert!(key_bytes(Key::A, none, TermMode::empty()).is_none());
+198 -11
View File
@@ -21,7 +21,24 @@ pub const THEMES: &[TermTheme] = &[
cursor: [78, 205, 196, 255],
cursor_accent: [28, 28, 28, 255],
selection: [78, 205, 196, 76],
ansi: [[28, 28, 28, 255], [239, 83, 80, 255], [102, 187, 106, 255], [255, 167, 38, 255], [66, 165, 245, 255], [171, 71, 188, 255], [78, 205, 196, 255], [228, 228, 228, 255], [85, 85, 85, 255], [255, 112, 67, 255], [129, 199, 132, 255], [255, 204, 2, 255], [100, 181, 246, 255], [206, 147, 216, 255], [128, 222, 234, 255], [255, 255, 255, 255]],
ansi: [
[28, 28, 28, 255],
[239, 83, 80, 255],
[102, 187, 106, 255],
[255, 167, 38, 255],
[66, 165, 245, 255],
[171, 71, 188, 255],
[78, 205, 196, 255],
[228, 228, 228, 255],
[85, 85, 85, 255],
[255, 112, 67, 255],
[129, 199, 132, 255],
[255, 204, 2, 255],
[100, 181, 246, 255],
[206, 147, 216, 255],
[128, 222, 234, 255],
[255, 255, 255, 255],
],
},
TermTheme {
id: "solarized-dark",
@@ -31,7 +48,24 @@ pub const THEMES: &[TermTheme] = &[
cursor: [147, 161, 161, 255],
cursor_accent: [0, 43, 54, 255],
selection: [147, 161, 161, 76],
ansi: [[7, 54, 66, 255], [220, 50, 47, 255], [133, 153, 0, 255], [181, 137, 0, 255], [38, 139, 210, 255], [211, 54, 130, 255], [42, 161, 152, 255], [238, 232, 213, 255], [88, 110, 117, 255], [203, 75, 22, 255], [88, 110, 117, 255], [101, 123, 131, 255], [131, 148, 150, 255], [108, 113, 196, 255], [147, 161, 161, 255], [253, 246, 227, 255]],
ansi: [
[7, 54, 66, 255],
[220, 50, 47, 255],
[133, 153, 0, 255],
[181, 137, 0, 255],
[38, 139, 210, 255],
[211, 54, 130, 255],
[42, 161, 152, 255],
[238, 232, 213, 255],
[88, 110, 117, 255],
[203, 75, 22, 255],
[88, 110, 117, 255],
[101, 123, 131, 255],
[131, 148, 150, 255],
[108, 113, 196, 255],
[147, 161, 161, 255],
[253, 246, 227, 255],
],
},
TermTheme {
id: "monokai",
@@ -41,7 +75,24 @@ pub const THEMES: &[TermTheme] = &[
cursor: [248, 248, 240, 255],
cursor_accent: [39, 40, 34, 255],
selection: [73, 72, 62, 153],
ansi: [[39, 40, 34, 255], [249, 38, 114, 255], [166, 226, 46, 255], [244, 191, 117, 255], [102, 217, 239, 255], [174, 129, 255, 255], [161, 239, 228, 255], [248, 248, 242, 255], [117, 113, 94, 255], [249, 38, 114, 255], [166, 226, 46, 255], [244, 191, 117, 255], [102, 217, 239, 255], [174, 129, 255, 255], [161, 239, 228, 255], [249, 248, 245, 255]],
ansi: [
[39, 40, 34, 255],
[249, 38, 114, 255],
[166, 226, 46, 255],
[244, 191, 117, 255],
[102, 217, 239, 255],
[174, 129, 255, 255],
[161, 239, 228, 255],
[248, 248, 242, 255],
[117, 113, 94, 255],
[249, 38, 114, 255],
[166, 226, 46, 255],
[244, 191, 117, 255],
[102, 217, 239, 255],
[174, 129, 255, 255],
[161, 239, 228, 255],
[249, 248, 245, 255],
],
},
TermTheme {
id: "nord",
@@ -51,7 +102,24 @@ pub const THEMES: &[TermTheme] = &[
cursor: [216, 222, 233, 255],
cursor_accent: [46, 52, 64, 255],
selection: [136, 192, 208, 76],
ansi: [[59, 66, 82, 255], [191, 97, 106, 255], [163, 190, 140, 255], [235, 203, 139, 255], [129, 161, 193, 255], [180, 142, 173, 255], [136, 192, 208, 255], [229, 233, 240, 255], [76, 86, 106, 255], [191, 97, 106, 255], [163, 190, 140, 255], [235, 203, 139, 255], [129, 161, 193, 255], [180, 142, 173, 255], [143, 188, 187, 255], [236, 239, 244, 255]],
ansi: [
[59, 66, 82, 255],
[191, 97, 106, 255],
[163, 190, 140, 255],
[235, 203, 139, 255],
[129, 161, 193, 255],
[180, 142, 173, 255],
[136, 192, 208, 255],
[229, 233, 240, 255],
[76, 86, 106, 255],
[191, 97, 106, 255],
[163, 190, 140, 255],
[235, 203, 139, 255],
[129, 161, 193, 255],
[180, 142, 173, 255],
[143, 188, 187, 255],
[236, 239, 244, 255],
],
},
TermTheme {
id: "dracula",
@@ -61,7 +129,24 @@ pub const THEMES: &[TermTheme] = &[
cursor: [248, 248, 242, 255],
cursor_accent: [40, 42, 54, 255],
selection: [68, 71, 90, 153],
ansi: [[33, 34, 44, 255], [255, 85, 85, 255], [80, 250, 123, 255], [241, 250, 140, 255], [189, 147, 249, 255], [255, 121, 198, 255], [139, 233, 253, 255], [248, 248, 242, 255], [98, 114, 164, 255], [255, 110, 110, 255], [105, 255, 148, 255], [255, 255, 165, 255], [214, 172, 255, 255], [255, 146, 223, 255], [164, 255, 255, 255], [255, 255, 255, 255]],
ansi: [
[33, 34, 44, 255],
[255, 85, 85, 255],
[80, 250, 123, 255],
[241, 250, 140, 255],
[189, 147, 249, 255],
[255, 121, 198, 255],
[139, 233, 253, 255],
[248, 248, 242, 255],
[98, 114, 164, 255],
[255, 110, 110, 255],
[105, 255, 148, 255],
[255, 255, 165, 255],
[214, 172, 255, 255],
[255, 146, 223, 255],
[164, 255, 255, 255],
[255, 255, 255, 255],
],
},
TermTheme {
id: "one-dark",
@@ -71,7 +156,24 @@ pub const THEMES: &[TermTheme] = &[
cursor: [82, 139, 255, 255],
cursor_accent: [40, 44, 52, 255],
selection: [82, 139, 255, 76],
ansi: [[40, 44, 52, 255], [224, 108, 117, 255], [152, 195, 121, 255], [229, 192, 123, 255], [97, 175, 239, 255], [198, 120, 221, 255], [86, 182, 194, 255], [171, 178, 191, 255], [92, 99, 112, 255], [224, 108, 117, 255], [152, 195, 121, 255], [229, 192, 123, 255], [97, 175, 239, 255], [198, 120, 221, 255], [86, 182, 194, 255], [255, 255, 255, 255]],
ansi: [
[40, 44, 52, 255],
[224, 108, 117, 255],
[152, 195, 121, 255],
[229, 192, 123, 255],
[97, 175, 239, 255],
[198, 120, 221, 255],
[86, 182, 194, 255],
[171, 178, 191, 255],
[92, 99, 112, 255],
[224, 108, 117, 255],
[152, 195, 121, 255],
[229, 192, 123, 255],
[97, 175, 239, 255],
[198, 120, 221, 255],
[86, 182, 194, 255],
[255, 255, 255, 255],
],
},
TermTheme {
id: "gruvbox-dark",
@@ -81,7 +183,24 @@ pub const THEMES: &[TermTheme] = &[
cursor: [235, 219, 178, 255],
cursor_accent: [40, 40, 40, 255],
selection: [214, 93, 14, 76],
ansi: [[40, 40, 40, 255], [204, 36, 29, 255], [152, 151, 26, 255], [215, 153, 33, 255], [69, 133, 136, 255], [177, 98, 134, 255], [104, 157, 106, 255], [168, 153, 132, 255], [146, 131, 116, 255], [251, 73, 52, 255], [184, 187, 38, 255], [250, 189, 47, 255], [131, 165, 152, 255], [211, 134, 155, 255], [142, 192, 124, 255], [235, 219, 178, 255]],
ansi: [
[40, 40, 40, 255],
[204, 36, 29, 255],
[152, 151, 26, 255],
[215, 153, 33, 255],
[69, 133, 136, 255],
[177, 98, 134, 255],
[104, 157, 106, 255],
[168, 153, 132, 255],
[146, 131, 116, 255],
[251, 73, 52, 255],
[184, 187, 38, 255],
[250, 189, 47, 255],
[131, 165, 152, 255],
[211, 134, 155, 255],
[142, 192, 124, 255],
[235, 219, 178, 255],
],
},
TermTheme {
id: "tokyo-night",
@@ -91,7 +210,24 @@ pub const THEMES: &[TermTheme] = &[
cursor: [192, 202, 245, 255],
cursor_accent: [26, 27, 38, 255],
selection: [41, 46, 66, 230],
ansi: [[21, 22, 30, 255], [247, 118, 142, 255], [158, 206, 106, 255], [224, 175, 104, 255], [122, 162, 247, 255], [187, 154, 247, 255], [125, 207, 255, 255], [169, 177, 214, 255], [65, 72, 104, 255], [247, 118, 142, 255], [158, 206, 106, 255], [224, 175, 104, 255], [122, 162, 247, 255], [187, 154, 247, 255], [125, 207, 255, 255], [192, 202, 245, 255]],
ansi: [
[21, 22, 30, 255],
[247, 118, 142, 255],
[158, 206, 106, 255],
[224, 175, 104, 255],
[122, 162, 247, 255],
[187, 154, 247, 255],
[125, 207, 255, 255],
[169, 177, 214, 255],
[65, 72, 104, 255],
[247, 118, 142, 255],
[158, 206, 106, 255],
[224, 175, 104, 255],
[122, 162, 247, 255],
[187, 154, 247, 255],
[125, 207, 255, 255],
[192, 202, 245, 255],
],
},
TermTheme {
id: "catppuccin-mocha",
@@ -101,7 +237,24 @@ pub const THEMES: &[TermTheme] = &[
cursor: [245, 224, 220, 255],
cursor_accent: [30, 30, 46, 255],
selection: [88, 91, 112, 128],
ansi: [[69, 71, 90, 255], [243, 139, 168, 255], [166, 227, 161, 255], [249, 226, 175, 255], [137, 180, 250, 255], [245, 194, 231, 255], [148, 226, 213, 255], [186, 194, 222, 255], [88, 91, 112, 255], [243, 139, 168, 255], [166, 227, 161, 255], [249, 226, 175, 255], [137, 180, 250, 255], [245, 194, 231, 255], [148, 226, 213, 255], [166, 173, 200, 255]],
ansi: [
[69, 71, 90, 255],
[243, 139, 168, 255],
[166, 227, 161, 255],
[249, 226, 175, 255],
[137, 180, 250, 255],
[245, 194, 231, 255],
[148, 226, 213, 255],
[186, 194, 222, 255],
[88, 91, 112, 255],
[243, 139, 168, 255],
[166, 227, 161, 255],
[249, 226, 175, 255],
[137, 180, 250, 255],
[245, 194, 231, 255],
[148, 226, 213, 255],
[166, 173, 200, 255],
],
},
TermTheme {
id: "rose-pine",
@@ -111,7 +264,24 @@ pub const THEMES: &[TermTheme] = &[
cursor: [82, 79, 103, 255],
cursor_accent: [224, 222, 244, 255],
selection: [110, 106, 134, 102],
ansi: [[38, 35, 58, 255], [235, 111, 146, 255], [49, 116, 143, 255], [246, 193, 119, 255], [156, 207, 216, 255], [196, 167, 231, 255], [235, 188, 186, 255], [224, 222, 244, 255], [110, 106, 134, 255], [235, 111, 146, 255], [49, 116, 143, 255], [246, 193, 119, 255], [156, 207, 216, 255], [196, 167, 231, 255], [235, 188, 186, 255], [224, 222, 244, 255]],
ansi: [
[38, 35, 58, 255],
[235, 111, 146, 255],
[49, 116, 143, 255],
[246, 193, 119, 255],
[156, 207, 216, 255],
[196, 167, 231, 255],
[235, 188, 186, 255],
[224, 222, 244, 255],
[110, 106, 134, 255],
[235, 111, 146, 255],
[49, 116, 143, 255],
[246, 193, 119, 255],
[156, 207, 216, 255],
[196, 167, 231, 255],
[235, 188, 186, 255],
[224, 222, 244, 255],
],
},
TermTheme {
id: "solarized-light",
@@ -121,7 +291,24 @@ pub const THEMES: &[TermTheme] = &[
cursor: [88, 110, 117, 255],
cursor_accent: [253, 246, 227, 255],
selection: [7, 54, 66, 51],
ansi: [[7, 54, 66, 255], [220, 50, 47, 255], [133, 153, 0, 255], [181, 137, 0, 255], [38, 139, 210, 255], [211, 54, 130, 255], [42, 161, 152, 255], [238, 232, 213, 255], [0, 43, 54, 255], [203, 75, 22, 255], [88, 110, 117, 255], [101, 123, 131, 255], [131, 148, 150, 255], [108, 113, 196, 255], [147, 161, 161, 255], [253, 246, 227, 255]],
ansi: [
[7, 54, 66, 255],
[220, 50, 47, 255],
[133, 153, 0, 255],
[181, 137, 0, 255],
[38, 139, 210, 255],
[211, 54, 130, 255],
[42, 161, 152, 255],
[238, 232, 213, 255],
[0, 43, 54, 255],
[203, 75, 22, 255],
[88, 110, 117, 255],
[101, 123, 131, 255],
[131, 148, 150, 255],
[108, 113, 196, 255],
[147, 161, 161, 255],
[253, 246, 227, 255],
],
},
];
+6 -1
View File
@@ -212,7 +212,12 @@ pub fn install_fonts(ctx: &egui::Context) {
/// The first wide-coverage (CJK) system font found on this machine.
fn system_fallback_font() -> Option<Vec<u8>> {
let candidates: &[&str] = if cfg!(target_os = "macos") {
&["/System/Library/Fonts/PingFang.ttc", "/System/Library/Fonts/Hiragino Sans GB.ttc", "/Library/Fonts/Arial Unicode.ttf", "/System/Library/Fonts/Supplemental/Arial Unicode.ttf"]
&[
"/System/Library/Fonts/PingFang.ttc",
"/System/Library/Fonts/Hiragino Sans GB.ttc",
"/Library/Fonts/Arial Unicode.ttf",
"/System/Library/Fonts/Supplemental/Arial Unicode.ttf",
]
} else if cfg!(windows) {
&["C:\\Windows\\Fonts\\msyh.ttc", "C:\\Windows\\Fonts\\YuGothM.ttc", "C:\\Windows\\Fonts\\msgothic.ttc", "C:\\Windows\\Fonts\\malgun.ttf"]
} else {
+48 -11
View File
@@ -14,10 +14,25 @@ const STRATEGIES: [(&str, &str); 3] = [("skip", "Skip existing"), ("overwrite",
enum Mode {
/// `selected` is filled from `preselect` (or every profile) on the first frame.
Export { preselect: Option<Vec<String>>, selected: HashSet<String>, pw: String, confirm: String },
Import { path: PathBuf, pw: String, strategy: &'static str, status: String },
ExportJson { include_secrets: bool },
ImportJson { path: PathBuf, strategy: &'static str },
Export {
preselect: Option<Vec<String>>,
selected: HashSet<String>,
pw: String,
confirm: String,
},
Import {
path: PathBuf,
pw: String,
strategy: &'static str,
status: String,
},
ExportJson {
include_secrets: bool,
},
ImportJson {
path: PathBuf,
strategy: &'static str,
},
}
enum Done {
@@ -38,7 +53,9 @@ impl Transfer {
}
pub fn import_encrypted(&mut self) {
if let Some(path) = rfd::FileDialog::new().set_title("Import Profiles").add_filter("Nexus Export", &[EXTENSION, "link"]).add_filter("All files", &["*"]).pick_file() {
if let Some(path) =
rfd::FileDialog::new().set_title("Import Profiles").add_filter("Nexus Export", &[EXTENSION, "link"]).add_filter("All files", &["*"]).pick_file()
{
self.mode = Some(Mode::Import { path, pw: String::new(), strategy: "skip", status: String::new() });
}
}
@@ -112,7 +129,11 @@ impl Transfer {
let name = if p.display_name.is_empty() { &p.host } else { &p.display_name };
let label = format!("{name} ({})", p.protocol.id());
if ui.checkbox(&mut on, label).changed() {
if on { selected.insert(p.id.clone()) } else { selected.remove(&p.id) };
if on {
selected.insert(p.id.clone())
} else {
selected.remove(&p.id)
};
}
}
});
@@ -131,11 +152,18 @@ impl Transfer {
s.error("Passwords do not match.");
} else if selected.is_empty() {
s.error("Please select at least one profile.");
} else if let Some(path) = rfd::FileDialog::new().set_title("Export Profiles").set_file_name(format!("nexus-profiles.{EXTENSION}")).add_filter("Nexus Export", &[EXTENSION]).save_file() {
} else if let Some(path) = rfd::FileDialog::new()
.set_title("Export Profiles")
.set_file_name(format!("nexus-profiles.{EXTENSION}"))
.add_filter("Nexus Export", &[EXTENSION])
.save_file()
{
// Keep the sidebar's order.
let ids: Vec<String> = s.profiles.iter().filter(|p| selected.contains(&p.id)).map(|p| p.id.clone()).collect();
let (svc, pw) = (s.svc.clone(), pw.clone());
start = Some(Box::new(move || svc.export_encrypted(&ids, &pw, &path).map(|p| Done::Exported(ids.len(), p)).map_err(|e| format!("Export failed: {e}"))));
start = Some(Box::new(move || {
svc.export_encrypted(&ids, &pw, &path).map(|p| Done::Exported(ids.len(), p)).map_err(|e| format!("Export failed: {e}"))
}));
}
}
}
@@ -169,10 +197,18 @@ impl Transfer {
ui.label(format!("Exports all {} profile(s) as plain JSON.", s.profiles.len()));
ui.checkbox(include_secrets, "Include secrets (proxy passwords, TOTP secrets)");
if *include_secrets {
ui.label(RichText::new(format!("{} The file will contain secrets in plain text. Prefer the encrypted export.", icon::WARNING)).color(t.warning).size(12.0));
ui.label(
RichText::new(format!("{} The file will contain secrets in plain text. Prefer the encrypted export.", icon::WARNING))
.color(t.warning)
.size(12.0),
);
}
if buttons(ui, false, icon::FILE_ARROW_UP, "Export", &mut close)
&& let Some(path) = rfd::FileDialog::new().set_title("Export Profiles (JSON)").set_file_name("nexus-profiles.json").add_filter("JSON", &["json"]).save_file()
&& let Some(path) = rfd::FileDialog::new()
.set_title("Export Profiles (JSON)")
.set_file_name("nexus-profiles.json")
.add_filter("JSON", &["json"])
.save_file()
{
match s.svc.export_json(*include_secrets).map_err(|e| e.to_string()).and_then(|j| std::fs::write(&path, j).map_err(|e| e.to_string())) {
Ok(()) => {
@@ -189,7 +225,8 @@ impl Transfer {
file_line(ui, path);
strategy_combo(ui, strategy);
if buttons(ui, false, icon::FILE_ARROW_DOWN, "Import", &mut close) {
match std::fs::read_to_string(&path).map_err(|e| e.to_string()).and_then(|j| s.svc.import_json(&j, strategy).map_err(|e| e.to_string())) {
match std::fs::read_to_string(&path).map_err(|e| e.to_string()).and_then(|j| s.svc.import_json(&j, strategy).map_err(|e| e.to_string()))
{
Ok(n) => {
s.success(format!("Imported {n} profile(s)"));
s.request(Request::ReloadProfiles);
+9 -2
View File
@@ -117,7 +117,10 @@ impl Triggers {
}
let lines = complete_lines(self.buffers.entry(session.to_owned()).or_default(), data);
let mut highlight = false;
let label = s.pane(session).map(|p| if p.info.tab_name.is_empty() { p.info.profile_name.clone() } else { p.info.tab_name.clone() }).unwrap_or_else(|| session.to_owned());
let label = s
.pane(session)
.map(|p| if p.info.tab_name.is_empty() { p.info.profile_name.clone() } else { p.info.tab_name.clone() })
.unwrap_or_else(|| session.to_owned());
let mut fired: Vec<(String, String)> = vec![];
for line in &lines {
let clean = strip_ansi(line);
@@ -191,7 +194,11 @@ impl Triggers {
ui.vertical(|ui| {
ui.label(RichText::new(if r.name.is_empty() { &r.pattern } else { &r.name }).font(theme::semibold(13.0)));
let action = ACTIONS.iter().find(|a| a.0 == r.action).map_or(r.action.as_str(), |a| a.1);
let meta = format!("{} · {action} · {}", if r.is_regex { "Regex" } else { "Text" }, if r.case_sensitive { "Case-sensitive" } else { "Case-insensitive" });
let meta = format!(
"{} · {action} · {}",
if r.is_regex { "Regex" } else { "Text" },
if r.case_sensitive { "Case-sensitive" } else { "Case-insensitive" }
);
ui.label(RichText::new(meta).size(11.5).color(t.text_dim));
});
ui.label(RichText::new(&r.pattern).font(theme::mono(12.0)).color(if r.is_regex && r.re.is_none() { t.danger } else { t.text }));
-9
View File
@@ -14,15 +14,6 @@ pub enum View {
Vnc(Box<VncView>),
}
impl View {
pub fn terminal(&mut self) -> Option<&mut TermView> {
match self {
View::Terminal(t) => Some(t),
_ => None,
}
}
}
/// Protocol badge colour (the web build's --protocol-* tokens).
pub fn protocol_color(p: nexus_core::models::Protocol) -> egui::Color32 {
use nexus_core::models::Protocol::*;
+12 -6
View File
@@ -254,7 +254,11 @@ impl VncView {
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
ui.add_enabled_ui(self.ready, |ui| {
let (g, tip) = if self.scale_to_fit { (icon::CORNERS_IN, "Scaled to fit (click for 1:1)") } else { (icon::CORNERS_OUT, "1:1 (click to scale to fit)") };
let (g, tip) = if self.scale_to_fit {
(icon::CORNERS_IN, "Scaled to fit (click for 1:1)")
} else {
(icon::CORNERS_OUT, "1:1 (click to scale to fit)")
};
if widgets::icon_button(ui, g, tip).clicked() {
self.scale_to_fit = !self.scale_to_fit;
}
@@ -264,7 +268,10 @@ impl VncView {
let _ = c.request_full_update();
}
if !self.view_only {
if widgets::button(ui, icon::CLIPBOARD_TEXT, "Paste Clipboard").on_hover_text("Send the local clipboard to the remote desktop").clicked() {
if widgets::button(ui, icon::CLIPBOARD_TEXT, "Paste Clipboard")
.on_hover_text("Send the local clipboard to the remote desktop")
.clicked()
{
match arboard::Clipboard::new().and_then(|mut c| c.get_text()) {
Ok(text) if !text.is_empty() => {
self.paste(s, &text);
@@ -293,9 +300,7 @@ impl VncView {
let focused = resp.has_focus();
if focused {
ui.painter().rect_stroke(img, 0.0, egui::Stroke::new(1.0, Tokens::get(ui.ctx()).accent.gamma_multiply(0.6)), egui::StrokeKind::Outside);
ui.memory_mut(|m| {
m.set_focus_lock_filter(id, egui::EventFilter { tab: true, horizontal_arrows: true, vertical_arrows: true, escape: true })
});
ui.memory_mut(|m| m.set_focus_lock_filter(id, egui::EventFilter { tab: true, horizontal_arrows: true, vertical_arrows: true, escape: true }));
} else if self.had_focus {
self.release_all();
}
@@ -344,7 +349,8 @@ impl VncView {
for e in events {
match e {
Event::Key { key, pressed, modifiers, .. } => {
let sym = named_keysym(key).or_else(|| (modifiers.ctrl || modifiers.alt || modifiers.mac_cmd).then(|| chord_keysym(key, modifiers.shift)).flatten());
let sym = named_keysym(key)
.or_else(|| (modifiers.ctrl || modifiers.alt || modifiers.mac_cmd).then(|| chord_keysym(key, modifiers.shift)).flatten());
if let Some(sym) = sym {
self.key(sym, pressed);
}