A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
feat(window): add a file picker with a title, prompt and file type
RoversXc732fc341690
diff --git a/window/src/lib.rs b/window/src/lib.rsindex 04938ebb..5441b5f3 100644--- a/window/src/lib.rs+++ b/window/src/lib.rs@@ -277,6 +277,20 @@ impl Default for FolderPickerOptions {}}+/// What a file picker offers and how it is worded: one kind of file, named+/// by its extension.+#[derive(Debug, Clone)]+pub struct FilePickerOptions {+ pub title: String,+ pub prompt: String,+ /// The one extension on offer, without its dot: `svg`.+ pub extension: String,+ /// What that kind of file is called, where a platform labels its filter.+ pub kind: String,+ /// Where the picker opens; best-effort, as for folders.+ pub directory: Option<PathBuf>,+}+impl ContextMenuIcon {pub fn sf_symbol_name(self) -> &'static str {match self {@@ -799,6 +813,15 @@ pub trait WindowOps {callback(None);}+ /// Show a native picker for one file of the kind `options` names.+ fn pick_file_async_with_options(+ &self,+ _options: FilePickerOptions,+ callback: Box<dyn FnOnce(Option<PathBuf>) + 'static>,+ ) {+ callback(None);+ }+/// Invalidate the window so that the entire client area will/// be repainted shortlyfn invalidate(&self);diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rsindex 8bcb9410..b4154480 100644--- a/window/src/os/macos/window.rs+++ b/window/src/os/macos/window.rs@@ -10,11 +10,12 @@ use crate::os::macos::menu::{Menu, MenuItem, RepresentedItem};use crate::parameters::{Border, Parameters, TitleBar};use crate::{Clipboard, ClipboardContents, Connection, ContextMenuItem, DeadKeyStatus, Dimensions,- FolderPickerOptions, Handled, Image, KeyCode, KeyEvent, Modifiers, MouseButtons, MouseCursor,- MouseEvent, MouseEventKind, MousePress, NativeTextInputSnapshot, Point, PreciseScrollDelta,- RawKeyEvent, Rect, RequestedWindowGeometry, ResizeIncrement, ResolvedGeometry, ScreenPoint,- ScrollPhase, Size, TextCheckCapabilities, TextCheckIssue, TextCheckRequest, TextCheckResponse,- ULength, WindowDecorations, WindowEvent, WindowEventSender, WindowOps, WindowState,+ FilePickerOptions, FolderPickerOptions, Handled, Image, KeyCode, KeyEvent, Modifiers,+ MouseButtons, MouseCursor, MouseEvent, MouseEventKind, MousePress, NativeTextInputSnapshot,+ Point, PreciseScrollDelta, RawKeyEvent, Rect, RequestedWindowGeometry, ResizeIncrement,+ ResolvedGeometry, ScreenPoint, ScrollPhase, Size, TextCheckCapabilities, TextCheckIssue,+ TextCheckRequest, TextCheckResponse, ULength, WindowDecorations, WindowEvent,+ WindowEventSender, WindowOps, WindowState,};use anyhow::{anyhow, bail, ensure};use async_trait::async_trait;@@ -1238,6 +1239,23 @@ impl WindowOps for Window {}fn pick_app_async(&self, callback: Box<dyn FnOnce(Option<PathBuf>) + 'static>) {+ self.pick_file_async_with_options(+ FilePickerOptions {+ title: "Choose Application".to_string(),+ prompt: "Choose".to_string(),+ extension: "app".to_string(),+ kind: "Application".to_string(),+ directory: Some(PathBuf::from("/Applications")),+ },+ callback,+ );+ }++ fn pick_file_async_with_options(+ &self,+ options: FilePickerOptions,+ callback: Box<dyn FnOnce(Option<PathBuf>) + 'static>,+ ) {unsafe {let _pool = NSAutoreleasePool::new(nil);let panel: id = msg_send![class!(NSOpenPanel), openPanel];@@ -1246,15 +1264,21 @@ impl WindowOps for Window {let () = msg_send![*panel, setCanChooseDirectories: NO];let () = msg_send![*panel, setAllowsMultipleSelection: NO];let () = msg_send![*panel, setResolvesAliases: YES];- let app_type = nsstring("app");- let types: id = msg_send![class!(NSArray), arrayWithObject: *app_type];+ let file_type = nsstring(&options.extension);+ let types: id = msg_send![class!(NSArray), arrayWithObject: *file_type];let () = msg_send![*panel, setAllowedFileTypes: types];- let applications_dir = nsstring("/Applications");- let dir_url: id =- msg_send![class!(NSURL), fileURLWithPath: *applications_dir isDirectory: YES];- let () = msg_send![*panel, setDirectoryURL: dir_url];- let title = nsstring("Choose Application");- let prompt = nsstring("Choose");+ // Bound to a local so the NSString outlives the NSURL made from+ // it, as in the folder picker.+ if let Some(directory) = options.directory.as_ref().and_then(|dir| dir.to_str()) {+ let directory = nsstring(directory);+ let dir_url: id =+ msg_send![class!(NSURL), fileURLWithPath: *directory isDirectory: YES];+ if dir_url != nil {+ let () = msg_send![*panel, setDirectoryURL: dir_url];+ }+ }+ let title = nsstring(&options.title);+ let prompt = nsstring(&options.prompt);let () = msg_send![*panel, setTitle: *title];let () = msg_send![*panel, setPrompt: *prompt];diff --git a/window/src/os/windows/window.rs b/window/src/os/windows/window.rsindex d057b888..2f934a41 100644--- a/window/src/os/windows/window.rs+++ b/window/src/os/windows/window.rs@@ -2,10 +2,11 @@ use super::*;use crate::connection::ConnectionOps;use crate::parameters::{self, Parameters};use crate::{- Appearance, Clipboard, ClipboardContents, DeadKeyStatus, Dimensions, FolderPickerOptions,- Handled, KeyCode, KeyEvent, Modifiers, MouseButtons, MouseCursor, MouseEvent, MouseEventKind,- MousePress, Point, RawKeyEvent, Rect, RequestedWindowGeometry, ResolvedGeometry, ScreenPoint,- ScreenRect, ULength, WindowDecorations, WindowEvent, WindowEventSender, WindowOps, WindowState,+ Appearance, Clipboard, ClipboardContents, DeadKeyStatus, Dimensions, FilePickerOptions,+ FolderPickerOptions, Handled, KeyCode, KeyEvent, Modifiers, MouseButtons, MouseCursor,+ MouseEvent, MouseEventKind, MousePress, Point, RawKeyEvent, Rect, RequestedWindowGeometry,+ ResolvedGeometry, ScreenPoint, ScreenRect, ULength, WindowDecorations, WindowEvent,+ WindowEventSender, WindowOps, WindowState,};use anyhow::{anyhow, bail};use async_trait::async_trait;@@ -268,7 +269,10 @@ unsafe fn pick_folder_dialog(result}-unsafe fn pick_app_dialog(hwnd: HWND) -> anyhow::Result<Option<PathBuf>> {+unsafe fn pick_file_dialog(+ hwnd: HWND,+ picker_options: &FilePickerOptions,+) -> anyhow::Result<Option<PathBuf>> {let coinit = CoInitializeEx(null_mut(),COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE,@@ -291,10 +295,13 @@ unsafe fn pick_app_dialog(hwnd: HWND) -> anyhow::Result<Option<PathBuf>> {"CoCreateInstance(FileOpenDialog)",)?;- let title = wide_null("Choose Application");- let choose = wide_null("Choose");- let filter_name = wide_null("Applications (*.exe)");- let filter_spec = wide_null("*.exe");+ let title = wide_null(&picker_options.title);+ let choose = wide_null(&picker_options.prompt);+ let filter_name = wide_null(&format!(+ "{} (*.{})",+ picker_options.kind, picker_options.extension+ ));+ let filter_spec = wide_null(&format!("*.{}", picker_options.extension));let filters = [COMDLG_FILTERSPEC {pszName: filter_name.as_ptr(),pszSpec: filter_spec.as_ptr(),@@ -1327,13 +1334,30 @@ impl WindowOps for Window {}fn pick_app_async(&self, callback: Box<dyn FnOnce(Option<PathBuf>) + 'static>) {+ self.pick_file_async_with_options(+ FilePickerOptions {+ title: "Choose Application".to_string(),+ prompt: "Choose".to_string(),+ extension: "exe".to_string(),+ kind: "Applications".to_string(),+ directory: None,+ },+ callback,+ );+ }++ fn pick_file_async_with_options(+ &self,+ options: FilePickerOptions,+ callback: Box<dyn FnOnce(Option<PathBuf>) + 'static>,+ ) {let hwnd = self.0 .0;promise::spawn::spawn(async move {let path = unsafe {- match pick_app_dialog(hwnd) {+ match pick_file_dialog(hwnd, &options) {Ok(path) => path,Err(err) => {- log::warn!("failed to show app picker: {err:#}");+ log::warn!("failed to show file picker: {err:#}");None}}diff --git a/window/src/os/x_and_wayland.rs b/window/src/os/x_and_wayland.rsindex a8d3b325..3adca18c 100644--- a/window/src/os/x_and_wayland.rs+++ b/window/src/os/x_and_wayland.rs@@ -393,6 +393,14 @@ impl WindowOps for Window {crate::os::xdg_desktop_portal::pick_app_async(callback);}+ fn pick_file_async_with_options(+ &self,+ options: crate::FilePickerOptions,+ callback: Box<dyn FnOnce(Option<PathBuf>) + 'static>,+ ) {+ crate::os::xdg_desktop_portal::pick_file_async_with_options(options, callback);+ }+fn invalidate(&self) {match self {Self::X11(x) => x.invalidate(),diff --git a/window/src/os/xdg_desktop_portal.rs b/window/src/os/xdg_desktop_portal.rsindex 7ab855ef..ee454dee 100644--- a/window/src/os/xdg_desktop_portal.rs+++ b/window/src/os/xdg_desktop_portal.rs@@ -258,6 +258,11 @@ pub fn pick_folder_async_with_options(/// File picker used to choose an application (a .desktop entry or an/// executable); the caller normalizes the selection.pub async fn pick_app() -> anyhow::Result<Option<PathBuf>> {+ pick_file("Choose Application", None).await+}++/// Open-file picker. Unfiltered: the caller checks what it was given.+pub async fn pick_file(title: &str, accept_label: Option<&str>) -> anyhow::Result<Option<PathBuf>> {let connection = zbus::ConnectionBuilder::session()?.build().await?;let proxy = PortalFileChooserProxy::new(&connection).await@@ -265,19 +270,22 @@ pub async fn pick_app() -> anyhow::Result<Option<PathBuf>> {let mut options = HashMap::new();options.insert("modal", Value::from(true));+ if let Some(label) = accept_label {+ options.insert("accept_label", Value::from(label));+ }let handle = proxy- .OpenFile("", "Choose Application", options)+ .OpenFile("", title, options).or(async {async_io::Timer::after(std::time::Duration::from_secs(1)).await;Err(std::io::Error::new(std::io::ErrorKind::TimedOut,- "Timed out opening xdg-desktop-portal app picker",+ "Timed out opening xdg-desktop-portal file picker",).into())}).await- .context("Opening xdg-desktop-portal app picker")?;+ .context("Opening xdg-desktop-portal file picker")?;let request = PortalRequestProxy::builder(&connection).path(handle)?@@ -295,8 +303,8 @@ pub async fn pick_app() -> anyhow::Result<Option<PathBuf>> {None}).await- .ok_or_else(|| anyhow::anyhow!("Timed out waiting for app picker response"))?;- let args = signal.args().context("decode app picker response")?;+ .ok_or_else(|| anyhow::anyhow!("Timed out waiting for file picker response"))?;+ let args = signal.args().context("decode file picker response")?;if args.response != 0 {return Ok(None);}@@ -304,6 +312,23 @@ pub async fn pick_app() -> anyhow::Result<Option<PathBuf>> {first_file_uri_to_path(&args.results)}+pub fn pick_file_async_with_options(+ options: crate::FilePickerOptions,+ callback: Box<dyn FnOnce(Option<PathBuf>) + 'static>,+) {+ promise::spawn::spawn(async move {+ let path = match pick_file(&options.title, Some(options.prompt.as_str())).await {+ Ok(path) => path,+ Err(err) => {+ log::warn!("failed to show xdg-desktop-portal file picker: {err:#}");+ None+ }+ };+ callback(path);+ })+ .detach();+}+pub fn pick_app_async(callback: Box<dyn FnOnce(Option<PathBuf>) + 'static>) {promise::spawn::spawn(async move {let path = match pick_app().await {