diff --git a/crates/ghostty-apprt-gtk/build.rs b/crates/ghostty-apprt-gtk/build.rs index 8692488..0dad45c 100644 --- a/crates/ghostty-apprt-gtk/build.rs +++ b/crates/ghostty-apprt-gtk/build.rs @@ -3,9 +3,11 @@ //! ZIG/src/apprt/gtk/build/{blueprint,gresource}.zig. #![allow(clippy::unwrap_used)] -use std::fmt::Write as _; -use std::path::{Path, PathBuf}; -use std::process::Command; +use std::{ + fmt::Write as _, + path::{Path, PathBuf}, + process::Command, +}; const PREFIX: &str = "/com/mitchellh/ghostty"; const APP_ID: &str = "com.mitchellh.ghostty"; diff --git a/crates/ghostty-apprt-gtk/examples/demo.rs b/crates/ghostty-apprt-gtk/examples/demo.rs index fa20a33..aae6fa9 100644 --- a/crates/ghostty-apprt-gtk/examples/demo.rs +++ b/crates/ghostty-apprt-gtk/examples/demo.rs @@ -13,24 +13,40 @@ #![allow(unsafe_code)] // GL calls through glow -use std::cell::{Cell, RefCell}; -use std::rc::Rc; -use std::sync::Arc; -use std::time::Duration; - -use ghostty_apprt::action::{self, Action, Target}; -use ghostty_apprt::runtime_api::{ - AppMessage, CellSize, ClipboardError, CoreApp, CoreError, CoreSurface, DesiredFontSize, - InputEffect, KeyEvent, RtApp, RtSurface, SurfaceId, +use std::{ + cell::{Cell, RefCell}, + rc::Rc, + sync::Arc, + time::Duration, }; -use ghostty_apprt::structs::{ - ClipboardRequest, ColorScheme, ContentScale, CursorPos, ImePos, SurfaceSize, + +use ghostty_apprt::{ + action::{self, Action, Target}, + runtime_api::{ + AppMessage, + CellSize, + ClipboardError, + CoreApp, + CoreError, + CoreSurface, + DesiredFontSize, + InputEffect, + KeyEvent, + RtApp, + RtSurface, + SurfaceId, + }, + structs::{ClipboardRequest, ColorScheme, ContentScale, CursorPos, ImePos, SurfaceSize}, }; use ghostty_apprt_gtk::app::App; use ghostty_config::config::Config; -use ghostty_input::binding::set::Value as BindingValue; -use ghostty_input::binding::{self, Action as Binding}; -use ghostty_input::{Mods, MouseButton, MouseButtonState, ScrollMods}; +use ghostty_input::{ + Mods, + MouseButton, + MouseButtonState, + ScrollMods, + binding::{self, Action as Binding, set::Value as BindingValue}, +}; use glow::HasContext; fn confirm() -> bool { diff --git a/crates/ghostty-apprt-gtk/src/app.rs b/crates/ghostty-apprt-gtk/src/app.rs index bb7d1e4..963da10 100644 --- a/crates/ghostty-apprt-gtk/src/app.rs +++ b/crates/ghostty-apprt-gtk/src/app.rs @@ -7,14 +7,15 @@ //! app.terminate(); //! ``` -use std::rc::Rc; -use std::sync::Arc; +use std::{rc::Rc, sync::Arc}; -use ghostty_apprt::action::{Action, Target}; -use ghostty_apprt::ipc; +use ghostty_apprt::{ + action::{Action, Target}, + ipc, + runtime_api::{CoreApp, SurfaceId, Waker}, +}; use crate::class::application::{Application, RunError}; -use ghostty_apprt::runtime_api::{CoreApp, SurfaceId, Waker}; /// This is detected by the Renderer, in which case it sends a /// `redraw_surface` message so that we can call `drawFrame` ourselves from diff --git a/crates/ghostty-apprt-gtk/src/cgroup.rs b/crates/ghostty-apprt-gtk/src/cgroup.rs index da1d27e..e7b4c4b 100644 --- a/crates/ghostty-apprt-gtk/src/cgroup.rs +++ b/crates/ghostty-apprt-gtk/src/cgroup.rs @@ -1,8 +1,6 @@ //! Transient systemd scope creation over D-Bus (port of `apprt/gtk/cgroup.zig`). -use gtk::gio; -use gtk::glib; -use gtk::prelude::*; +use gtk::{gio, glib, prelude::*}; /// Properties for the transient scope. #[derive(Debug, Clone, Copy, Default)] diff --git a/crates/ghostty-apprt-gtk/src/class/application.rs b/crates/ghostty-apprt-gtk/src/class/application.rs index 327bd57..bcd5550 100644 --- a/crates/ghostty-apprt-gtk/src/class/application.rs +++ b/crates/ghostty-apprt-gtk/src/class/application.rs @@ -18,32 +18,41 @@ clippy::should_implement_trait )] -use std::cell::{Cell, OnceCell, Ref, RefCell, RefMut}; -use std::rc::Rc; -use std::sync::Arc; +use std::{ + cell::{Cell, OnceCell, Ref, RefCell, RefMut}, + rc::Rc, + sync::Arc, +}; -use adw::prelude::*; -use adw::subclass::prelude::*; -use ghostty_apprt::action::{self, Action, Target}; -use ghostty_apprt::structs::ColorScheme; -use ghostty_config::cli_args::ConfigField; -use ghostty_config::command::Command; -use ghostty_config::config::Config as CoreConfig; -use ghostty_config::types_b::{GtkSingleInstance, WindowTheme}; +use adw::{prelude::*, subclass::prelude::*}; +use ghostty_apprt::{ + action::{self, Action, Target}, + runtime_api::{AppMessage, CoreApp, RtApp, SurfaceId}, + structs::ColorScheme, +}; +use ghostty_config::{ + cli_args::ConfigField, + command::Command, + config::Config as CoreConfig, + types_b::{GtkSingleInstance, WindowTheme}, +}; use ghostty_input::binding::Action as BindingAction; use gtk::{gdk, gio, glib}; -use crate::class::close_confirmation_dialog::{self, CloseConfirmationDialog}; -use crate::class::config::Config; -use crate::class::config_errors_dialog::ConfigErrorsDialog; -use crate::class::global_shortcuts::GlobalShortcuts; -use crate::class::split_tree::SplitTree; -use crate::class::surface::{Size, Surface}; -use crate::class::tab::Tab; -use crate::class::window::{SelectTab, TabOverrides, Window}; -use crate::css::CssProviders; -use crate::winproto; -use ghostty_apprt::runtime_api::{AppMessage, CoreApp, RtApp, SurfaceId}; +use crate::{ + class::{ + close_confirmation_dialog::{self, CloseConfirmationDialog}, + config::Config, + config_errors_dialog::ConfigErrorsDialog, + global_shortcuts::GlobalShortcuts, + split_tree::SplitTree, + surface::{Size, Surface}, + tab::Tab, + window::{SelectTab, TabOverrides, Window}, + }, + css::CssProviders, + winproto, +}; /// Errors from [`Application::run_loop`]. #[derive(Debug, thiserror::Error)] @@ -268,14 +277,26 @@ impl RtApp for AppRt { } mod imp { - use super::{ - AppMessage, Cell, Config, ConfigErrorsDialog, CoreApp, CssProviders, GlobalShortcuts, - OnceCell, QuitTimer, Rc, RefCell, RtApp, glib, winproto, - }; - use adw::prelude::*; - use adw::subclass::prelude::*; + use adw::{prelude::*, subclass::prelude::*}; use gtk::gio; + use super::{ + AppMessage, + Cell, + Config, + ConfigErrorsDialog, + CoreApp, + CssProviders, + GlobalShortcuts, + OnceCell, + QuitTimer, + Rc, + RefCell, + RtApp, + glib, + winproto, + }; + #[derive(Default)] pub struct Application { /// The libghostty App instance. @@ -826,7 +847,10 @@ impl Application { fn sync_action_accelerators(&self) { use ghostty_input::binding::action::{ - CloseTabMode, CopyToClipboard, InspectorMode, SplitDirection, + CloseTabMode, + CopyToClipboard, + InspectorMode, + SplitDirection, }; let a = |name: &str, action: BindingAction| self.sync_action_accelerator(name, &action); a("app.quit", BindingAction::Quit); diff --git a/crates/ghostty-apprt-gtk/src/class/clipboard_confirmation_dialog.rs b/crates/ghostty-apprt-gtk/src/class/clipboard_confirmation_dialog.rs index d090056..1686d31 100644 --- a/crates/ghostty-apprt-gtk/src/class/clipboard_confirmation_dialog.rs +++ b/crates/ghostty-apprt-gtk/src/class/clipboard_confirmation_dialog.rs @@ -5,14 +5,15 @@ //! `clipboard-contents` (GtkTextBuffer), `blur`. Signals `confirm(bool)` and //! `deny(bool)` (bool = "remember choice"). -use adw::prelude::*; -use adw::subclass::prelude::*; +use std::{ + cell::{Cell, RefCell}, + sync::OnceLock, +}; + +use adw::{prelude::*, subclass::prelude::*}; use ghostty_apprt::structs::ClipboardRequest; use ghostty_os::i18n::tr; -use gtk::glib; -use gtk::glib::subclass::Signal; -use std::cell::{Cell, RefCell}; -use std::sync::OnceLock; +use gtk::{glib, glib::subclass::Signal}; use super::dialog::{Dialog, DialogImpl}; @@ -22,13 +23,25 @@ use super::dialog::{Dialog, DialogImpl}; pub struct ClipboardRequestBoxed(pub ClipboardRequest); mod imp { - use super::{ - AdwAlertDialogImpl, AdwDialogImpl, Cell, ClipboardRequest, ClipboardRequestBoxed, Dialog, - DialogImpl, ObjectImpl, ObjectSubclass, OnceLock, RefCell, Signal, WidgetImpl, tr, - }; use adw::prelude::*; - use gtk::glib; - use gtk::subclass::prelude::*; + use gtk::{glib, subclass::prelude::*}; + + use super::{ + AdwAlertDialogImpl, + AdwDialogImpl, + Cell, + ClipboardRequest, + ClipboardRequestBoxed, + Dialog, + DialogImpl, + ObjectImpl, + ObjectSubclass, + OnceLock, + RefCell, + Signal, + WidgetImpl, + tr, + }; #[derive(Default, glib::Properties, gtk::CompositeTemplate)] #[properties(wrapper_type = super::ClipboardConfirmationDialog)] diff --git a/crates/ghostty-apprt-gtk/src/class/close_confirmation_dialog.rs b/crates/ghostty-apprt-gtk/src/class/close_confirmation_dialog.rs index ae7d484..e0d79f1 100644 --- a/crates/ghostty-apprt-gtk/src/class/close_confirmation_dialog.rs +++ b/crates/ghostty-apprt-gtk/src/class/close_confirmation_dialog.rs @@ -2,13 +2,11 @@ //! (`GhosttyCloseConfirmationDialog`). Property `target`; signals //! `close-request` and `cancel`. -use adw::prelude::*; -use adw::subclass::prelude::*; +use std::{cell::Cell, sync::OnceLock}; + +use adw::{prelude::*, subclass::prelude::*}; use ghostty_os::i18n::tr; -use gtk::glib; -use gtk::glib::subclass::Signal; -use std::cell::Cell; -use std::sync::OnceLock; +use gtk::{glib, glib::subclass::Signal}; use super::dialog::{Dialog, DialogImpl}; @@ -47,13 +45,21 @@ impl Target { } mod imp { + use gtk::{glib, glib::prelude::*, subclass::prelude::*}; + use super::{ - AdwAlertDialogImpl, AdwDialogImpl, Cell, Dialog, DialogImpl, ObjectImpl, ObjectSubclass, - OnceLock, Signal, Target, WidgetImpl, + AdwAlertDialogImpl, + AdwDialogImpl, + Cell, + Dialog, + DialogImpl, + ObjectImpl, + ObjectSubclass, + OnceLock, + Signal, + Target, + WidgetImpl, }; - use gtk::glib; - use gtk::glib::prelude::*; - use gtk::subclass::prelude::*; #[derive(Default, glib::Properties, gtk::CompositeTemplate)] #[properties(wrapper_type = super::CloseConfirmationDialog)] diff --git a/crates/ghostty-apprt-gtk/src/class/command_palette.rs b/crates/ghostty-apprt-gtk/src/class/command_palette.rs index 4d742aa..0c27bb9 100644 --- a/crates/ghostty-apprt-gtk/src/class/command_palette.rs +++ b/crates/ghostty-apprt-gtk/src/class/command_palette.rs @@ -5,22 +5,13 @@ //! keeps itself alive (a self-reference) from `new()` until its dialog is //! closed, like the Zig `refSink`/`unref` dance. -use std::cell::RefCell; -use std::cmp::Ordering; -use std::sync::OnceLock; +use std::{cell::RefCell, cmp::Ordering, sync::OnceLock}; -use adw::prelude::*; -use adw::subclass::prelude::*; -use ghostty_input::binding::Action as BindingAction; -use ghostty_input::command::Command as InputCommand; -use gtk::glib; -use gtk::glib::subclass::Signal; -use gtk::{CompositeTemplate, TemplateChild, gio}; +use adw::{prelude::*, subclass::prelude::*}; +use ghostty_input::{binding::Action as BindingAction, command::Command as InputCommand}; +use gtk::{CompositeTemplate, TemplateChild, gio, glib, glib::subclass::Signal}; -use super::application::Application; -use super::config::Config; -use super::surface::Surface; -use super::window::Window; +use super::{application::Application, config::Config, surface::Surface, window::Window}; /// Boxed wrapper so a binding action can travel through the `trigger` /// signal (Zig passes `*const input.Binding.Action`). @@ -32,12 +23,19 @@ pub struct BoxedAction(pub BindingAction); // Command (list item) mod command_imp { - use super::{ - BindingAction, Config, InputCommand, RefCell, Surface, ghostty_command_title_for_jump, glib, - }; use adw::prelude::*; use gtk::glib::subclass::prelude::*; + use super::{ + BindingAction, + Config, + InputCommand, + RefCell, + Surface, + ghostty_command_title_for_jump, + glib, + }; + pub enum CommandData { Regular { command: InputCommand, @@ -276,14 +274,23 @@ fn is_action_supported_on_gtk(action: &BindingAction) -> bool { // CommandPalette mod imp { + use adw::{prelude::*, subclass::prelude::*}; + use gtk::{gio, glib}; + use super::{ - Application, BoxedAction, Command, CompositeTemplate, Config, OnceLock, Ordering, RefCell, - Signal, TemplateChild, compare_commands, is_action_supported_on_gtk, + Application, + BoxedAction, + Command, + CompositeTemplate, + Config, + OnceLock, + Ordering, + RefCell, + Signal, + TemplateChild, + compare_commands, + is_action_supported_on_gtk, }; - use adw::prelude::*; - use adw::subclass::prelude::*; - use gtk::gio; - use gtk::glib; #[derive(Default, glib::Properties, CompositeTemplate)] #[properties(wrapper_type = super::CommandPalette)] diff --git a/crates/ghostty-apprt-gtk/src/class/config.rs b/crates/ghostty-apprt-gtk/src/class/config.rs index 08687e7..1465142 100644 --- a/crates/ghostty-apprt-gtk/src/class/config.rs +++ b/crates/ghostty-apprt-gtk/src/class/config.rs @@ -3,19 +3,19 @@ //! Wraps a core config in a GObject so it can be reference counted and bound //! from blueprints (`diagnostics-buffer`, `has-diagnostics`). -use std::cell::RefCell; -use std::sync::Arc; +use std::{cell::RefCell, sync::Arc}; use ghostty_config::config::Config as CoreConfig; -use gtk::glib; -use gtk::glib::subclass::prelude::*; +use gtk::{glib, glib::subclass::prelude::*}; mod imp { + use gtk::{ + glib, + glib::{prelude::*, subclass::prelude::*}, + prelude::TextBufferExt, + }; + use super::{Arc, CoreConfig, RefCell}; - use gtk::glib; - use gtk::glib::prelude::*; - use gtk::glib::subclass::prelude::*; - use gtk::prelude::TextBufferExt; #[derive(glib::Properties)] #[properties(wrapper_type = super::Config)] diff --git a/crates/ghostty-apprt-gtk/src/class/config_errors_dialog.rs b/crates/ghostty-apprt-gtk/src/class/config_errors_dialog.rs index d4aca5c..1b132f8 100644 --- a/crates/ghostty-apprt-gtk/src/class/config_errors_dialog.rs +++ b/crates/ghostty-apprt-gtk/src/class/config_errors_dialog.rs @@ -2,25 +2,33 @@ //! //! Property `config` (GhosttyConfig); signal `reload-config`. -use std::cell::RefCell; +use std::{cell::RefCell, sync::OnceLock}; -use adw::prelude::*; -use adw::subclass::prelude::*; -use gtk::glib; -use gtk::glib::subclass::Signal; -use std::sync::OnceLock; +use adw::{prelude::*, subclass::prelude::*}; +use gtk::{glib, glib::subclass::Signal}; -use super::config::Config; -use super::dialog::{Dialog, DialogImpl}; +use super::{ + config::Config, + dialog::{Dialog, DialogImpl}, +}; mod imp { + use gtk::{glib, glib::prelude::*, subclass::prelude::*}; + use super::{ - AdwAlertDialogImpl, AdwDialogImpl, Config, Dialog, DialogImpl, ObjectImpl, ObjectSubclass, - ObjectSubclassExt, OnceLock, RefCell, Signal, WidgetImpl, + AdwAlertDialogImpl, + AdwDialogImpl, + Config, + Dialog, + DialogImpl, + ObjectImpl, + ObjectSubclass, + ObjectSubclassExt, + OnceLock, + RefCell, + Signal, + WidgetImpl, }; - use gtk::glib; - use gtk::glib::prelude::*; - use gtk::subclass::prelude::*; #[derive(Default, glib::Properties, gtk::CompositeTemplate)] #[properties(wrapper_type = super::ConfigErrorsDialog)] diff --git a/crates/ghostty-apprt-gtk/src/class/debug_warning.rs b/crates/ghostty-apprt-gtk/src/class/debug_warning.rs index 6051377..1d984e3 100644 --- a/crates/ghostty-apprt-gtk/src/class/debug_warning.rs +++ b/crates/ghostty-apprt-gtk/src/class/debug_warning.rs @@ -4,8 +4,7 @@ use gtk::glib; mod imp { - use gtk::glib; - use gtk::subclass::prelude::*; + use gtk::{glib, subclass::prelude::*}; #[derive(Default, gtk::CompositeTemplate)] #[template(resource = "/com/mitchellh/ghostty/ui/1.3/debug-warning.ui")] diff --git a/crates/ghostty-apprt-gtk/src/class/dialog.rs b/crates/ghostty-apprt-gtk/src/class/dialog.rs index c48685e..89f3d28 100644 --- a/crates/ghostty-apprt-gtk/src/class/dialog.rs +++ b/crates/ghostty-apprt-gtk/src/class/dialog.rs @@ -4,8 +4,7 @@ //! `adw::MessageDialog` fallback is not needed). Subclasses implement //! [`DialogImpl`] and may override `response` via `AlertDialogImpl`. -use adw::prelude::*; -use adw::subclass::prelude::*; +use adw::{prelude::*, subclass::prelude::*}; use gtk::glib; mod imp { diff --git a/crates/ghostty-apprt-gtk/src/class/global_shortcuts.rs b/crates/ghostty-apprt-gtk/src/class/global_shortcuts.rs index 7bccd62..f2006bf 100644 --- a/crates/ghostty-apprt-gtk/src/class/global_shortcuts.rs +++ b/crates/ghostty-apprt-gtk/src/class/global_shortcuts.rs @@ -8,21 +8,28 @@ #![allow(deprecated)] // gio D-Bus signal_subscribe: replacement API is awkward for portal use -use std::cell::{Cell, RefCell}; -use std::collections::HashMap; -use std::sync::OnceLock; +use std::{ + cell::{Cell, RefCell}, + collections::HashMap, + sync::OnceLock, +}; -use ghostty_input::binding::Action as BindingAction; -use ghostty_input::binding::set::Value as BindingValue; -use gtk::gio::{self, prelude::*}; -use gtk::glib::{self, subclass::Signal, subclass::prelude::*, variant::ObjectPath}; +use ghostty_input::binding::{Action as BindingAction, set::Value as BindingValue}; +use gtk::{ + gio::{self, prelude::*}, + glib::{ + self, + subclass::{Signal, prelude::*}, + variant::ObjectPath, + }, +}; use crate::class::config::Config; mod imp { + use glib::{prelude::*, subclass::prelude::*}; + use super::{BindingAction, Cell, Config, OnceLock, RefCell, Signal, gio, glib}; - use glib::prelude::*; - use glib::subclass::prelude::*; #[derive(glib::Properties, Default)] #[properties(wrapper_type = super::GlobalShortcuts)] diff --git a/crates/ghostty-apprt-gtk/src/class/imgui_widget.rs b/crates/ghostty-apprt-gtk/src/class/imgui_widget.rs index 68f9576..eaf53d4 100644 --- a/crates/ghostty-apprt-gtk/src/class/imgui_widget.rs +++ b/crates/ghostty-apprt-gtk/src/class/imgui_widget.rs @@ -9,15 +9,15 @@ //! cheaply in gtk-rs without a lot of class struct boilerplate, so subclasses //! install the two hooks with [`ImguiWidget::set_hooks`] instead. -use std::cell::{Cell, RefCell}; -use std::time::{Duration, Instant}; +use std::{ + cell::{Cell, RefCell}, + time::{Duration, Instant}, +}; -use adw::prelude::*; -use adw::subclass::prelude::*; +use adw::{prelude::*, subclass::prelude::*}; use dear_imgui_glow::GlowRenderer; use ghostty_inspector::imgui::{Context, MouseButton, Ui}; -use gtk::glib::translate::IntoGlib; -use gtk::{gdk, glib}; +use gtk::{gdk, glib, glib::translate::IntoGlib}; use crate::key; diff --git a/crates/ghostty-apprt-gtk/src/class/inspector_widget.rs b/crates/ghostty-apprt-gtk/src/class/inspector_widget.rs index 18b2ae7..fce2911 100644 --- a/crates/ghostty-apprt-gtk/src/class/inspector_widget.rs +++ b/crates/ghostty-apprt-gtk/src/class/inspector_widget.rs @@ -4,16 +4,16 @@ //! property activates the inspector on that surface's core surface and //! clearing it deactivates it again. -use std::cell::RefCell; -use std::rc::Rc; +use std::{cell::RefCell, rc::Rc}; -use adw::prelude::*; -use adw::subclass::prelude::*; +use adw::{prelude::*, subclass::prelude::*}; use ghostty_apprt::runtime_api::CoreSurface; use gtk::glib; -use super::imgui_widget::{ImguiWidget, ImguiWidgetImpl}; -use super::surface::Surface; +use super::{ + imgui_widget::{ImguiWidget, ImguiWidgetImpl}, + surface::Surface, +}; glib::wrapper! { pub struct InspectorWidget(ObjectSubclass) diff --git a/crates/ghostty-apprt-gtk/src/class/inspector_window.rs b/crates/ghostty-apprt-gtk/src/class/inspector_window.rs index bb706f0..135e0cc 100644 --- a/crates/ghostty-apprt-gtk/src/class/inspector_window.rs +++ b/crates/ghostty-apprt-gtk/src/class/inspector_window.rs @@ -2,13 +2,10 @@ //! //! Window for displaying the Ghostty inspector. -use adw::prelude::*; -use adw::subclass::prelude::*; +use adw::{prelude::*, subclass::prelude::*}; use gtk::glib; -use super::debug_warning::DebugWarning; -use super::inspector_widget::InspectorWidget; -use super::surface::Surface; +use super::{debug_warning::DebugWarning, inspector_widget::InspectorWidget, surface::Surface}; glib::wrapper! { pub struct InspectorWindow(ObjectSubclass) diff --git a/crates/ghostty-apprt-gtk/src/class/key_state_overlay.rs b/crates/ghostty-apprt-gtk/src/class/key_state_overlay.rs index 2a70aaa..d729286 100644 --- a/crates/ghostty-apprt-gtk/src/class/key_state_overlay.rs +++ b/crates/ghostty-apprt-gtk/src/class/key_state_overlay.rs @@ -7,8 +7,7 @@ //! Deviation: Zig's `ext.StringList` boxed type is replaced by `GStrv` //! (`Vec`) for the `tables` and `sequence` properties. -use adw::prelude::*; -use adw::subclass::prelude::*; +use adw::{prelude::*, subclass::prelude::*}; use gtk::glib; glib::wrapper! { diff --git a/crates/ghostty-apprt-gtk/src/class/resize_overlay.rs b/crates/ghostty-apprt-gtk/src/class/resize_overlay.rs index 0fd178b..a1495b6 100644 --- a/crates/ghostty-apprt-gtk/src/class/resize_overlay.rs +++ b/crates/ghostty-apprt-gtk/src/class/resize_overlay.rs @@ -10,8 +10,7 @@ //! 2. Set the label with `set_label` //! 3. Schedule to show it with `schedule` -use adw::prelude::*; -use adw::subclass::prelude::*; +use adw::{prelude::*, subclass::prelude::*}; use gtk::glib; glib::wrapper! { diff --git a/crates/ghostty-apprt-gtk/src/class/search_overlay.rs b/crates/ghostty-apprt-gtk/src/class/search_overlay.rs index d052f9f..6256f63 100644 --- a/crates/ghostty-apprt-gtk/src/class/search_overlay.rs +++ b/crates/ghostty-apprt-gtk/src/class/search_overlay.rs @@ -5,10 +5,8 @@ use std::sync::OnceLock; -use adw::prelude::*; -use adw::subclass::prelude::*; -use gtk::glib::subclass::Signal; -use gtk::{gdk, glib}; +use adw::{prelude::*, subclass::prelude::*}; +use gtk::{gdk, glib, glib::subclass::Signal}; glib::wrapper! { pub struct SearchOverlay(ObjectSubclass) diff --git a/crates/ghostty-apprt-gtk/src/class/split_tree.rs b/crates/ghostty-apprt-gtk/src/class/split_tree.rs index ac53e2f..5637822 100644 --- a/crates/ghostty-apprt-gtk/src/class/split_tree.rs +++ b/crates/ghostty-apprt-gtk/src/class/split_tree.rs @@ -10,19 +10,29 @@ use std::cell::{Cell, RefCell}; -use adw::prelude::*; -use adw::subclass::prelude::*; +use adw::{prelude::*, subclass::prelude::*}; use ghostty_datastruct::split_tree::{ - Direction, Goto, Handle, Layout, Node, SplitError, SplitTree as DsSplitTree, SplitTreeView, + Direction, + Goto, + Handle, + Layout, + Node, + SplitError, + SplitTree as DsSplitTree, + SplitTreeView, +}; +use gtk::{ + gio, + glib::{self, clone, subclass::Signal}, }; -use gtk::gio; -use gtk::glib::{self, clone, subclass::Signal}; use half::f16; -use super::application::Application; -use super::close_confirmation_dialog::{CloseConfirmationDialog, Target as CloseTarget}; -use super::surface::{Surface, SurfaceOverrides}; -use super::surface_scrolled_window::SurfaceScrolledWindow; +use super::{ + application::Application, + close_confirmation_dialog::{CloseConfirmationDialog, Target as CloseTarget}, + surface::{Surface, SurfaceOverrides}, + surface_scrolled_window::SurfaceScrolledWindow, +}; /// The split tree of surfaces (Zig: `Surface.Tree`). pub type Tree = DsSplitTree; diff --git a/crates/ghostty-apprt-gtk/src/class/surface.rs b/crates/ghostty-apprt-gtk/src/class/surface.rs index ed3450f..45c1d99 100644 --- a/crates/ghostty-apprt-gtk/src/class/surface.rs +++ b/crates/ghostty-apprt-gtk/src/class/surface.rs @@ -8,47 +8,71 @@ //! into) is [`RtSurfaceHandle`], which implements [`ghostty_apprt::runtime_api::RtSurface`] //! and holds only a weak reference to the widget. -use std::cell::{Cell, RefCell}; -use std::collections::HashMap; -use std::io::Write as _; -use std::rc::Rc; -use std::sync::OnceLock; - -use adw::prelude::*; -use adw::subclass::prelude::*; -use ghostty_apprt::action::{CommandFinished, Inspector, KeySequence, KeyTable, Readonly}; -use ghostty_apprt::structs::{ - Clipboard, ClipboardRequest, ContentScale, CursorPos, ImePos, SurfaceSize, +use std::{ + cell::{Cell, RefCell}, + collections::HashMap, + io::Write as _, + rc::Rc, + sync::OnceLock, }; -use ghostty_apprt::surface::{ChildExited, NewSurfaceContext, Scrollbar}; -use ghostty_config::command::Command; -use ghostty_config::config::Config as CoreConfig; -use ghostty_config::path::Path as ConfigPath; -use ghostty_config::types_a::WorkingDirectory; -use ghostty_config::types_b::{ - BellFeatures, NotifyOnCommandFinish, ResizeOverlay as ResizeOverlayMode, ResizeOverlayPosition, + +use adw::{prelude::*, subclass::prelude::*}; +use ghostty_apprt::{ + action::{CommandFinished, Inspector, KeySequence, KeyTable, Readonly}, + runtime_api::{ + ClipboardError, + CoreSurface, + DesiredFontSize, + InputEffect, + MIN_WINDOW_HEIGHT_CELLS, + MIN_WINDOW_WIDTH_CELLS, + RtSurface, + SurfaceId, + }, + structs::{Clipboard, ClipboardRequest, ContentScale, CursorPos, ImePos, SurfaceSize}, + surface::{ChildExited, NewSurfaceContext, Scrollbar}, +}; +use ghostty_config::{ + command::Command, + config::Config as CoreConfig, + path::Path as ConfigPath, + types_a::WorkingDirectory, + types_b::{ + BellFeatures, + NotifyOnCommandFinish, + ResizeOverlay as ResizeOverlayMode, + ResizeOverlayPosition, + }, }; use ghostty_input::{Action as KeyAction, Key, KeyEvent, Mods, MouseButton, MouseButtonState}; -use ghostty_vt::mouse_shape::MouseShape; -use ghostty_vt::osc::{ProgressReport, ProgressState}; -use gtk::glib::subclass::Signal; -use gtk::glib::translate::{FromGlib, IntoGlib}; -use gtk::{gdk, gio, glib}; +use ghostty_vt::{ + mouse_shape::MouseShape, + osc::{ProgressReport, ProgressState}, +}; +use gtk::{ + gdk, + gio, + glib, + glib::{ + subclass::Signal, + translate::{FromGlib, IntoGlib}, + }, +}; -use crate::class::application::Application; -use crate::class::clipboard_confirmation_dialog::ClipboardConfirmationDialog; -use crate::class::config::Config; -use crate::class::inspector_window::InspectorWindow; -use crate::class::key_state_overlay::KeyStateOverlay; -use crate::class::resize_overlay::ResizeOverlay; -use crate::class::search_overlay::SearchOverlay; -use crate::class::surface_child_exited::SurfaceChildExited; -use crate::class::title_dialog::{self, TitleDialog}; -use crate::class::window::Window; -use crate::key as gtk_key; -use ghostty_apprt::runtime_api::{ - ClipboardError, CoreSurface, DesiredFontSize, InputEffect, MIN_WINDOW_HEIGHT_CELLS, - MIN_WINDOW_WIDTH_CELLS, RtSurface, SurfaceId, +use crate::{ + class::{ + application::Application, + clipboard_confirmation_dialog::ClipboardConfirmationDialog, + config::Config, + inspector_window::InspectorWindow, + key_state_overlay::KeyStateOverlay, + resize_overlay::ResizeOverlay, + search_overlay::SearchOverlay, + surface_child_exited::SurfaceChildExited, + title_dialog::{self, TitleDialog}, + window::Window, + }, + key as gtk_key, }; /// Simple dimensions struct for the surface used by various properties @@ -2268,12 +2292,18 @@ impl RtSurface for RtSurfaceHandle { /// A namespace for our clipboard-related functions so Surface isn't SO large. mod clipboard { + use adw::{prelude::*, subclass::prelude::ObjectSubclassIsExt}; + use super::{ - Clipboard, ClipboardConfirmationDialog, ClipboardError, ClipboardRequest, Surface, gdk, - gio, glib, + Clipboard, + ClipboardConfirmationDialog, + ClipboardError, + ClipboardRequest, + Surface, + gdk, + gio, + glib, }; - use adw::prelude::*; - use adw::subclass::prelude::ObjectSubclassIsExt; /// Set the clipboard contents. pub(super) fn set( diff --git a/crates/ghostty-apprt-gtk/src/class/surface_child_exited.rs b/crates/ghostty-apprt-gtk/src/class/surface_child_exited.rs index 176685b..72821fd 100644 --- a/crates/ghostty-apprt-gtk/src/class/surface_child_exited.rs +++ b/crates/ghostty-apprt-gtk/src/class/surface_child_exited.rs @@ -6,11 +6,9 @@ use std::sync::OnceLock; -use adw::prelude::*; -use adw::subclass::prelude::*; +use adw::{prelude::*, subclass::prelude::*}; use ghostty_apprt::surface::ChildExited; -use gtk::glib; -use gtk::glib::subclass::Signal; +use gtk::{glib, glib::subclass::Signal}; /// Boxed wrapper so `ChildExited` can be a GObject property. #[derive(Debug, Clone, Copy, PartialEq, Eq, glib::Boxed)] diff --git a/crates/ghostty-apprt-gtk/src/class/surface_scrolled_window.rs b/crates/ghostty-apprt-gtk/src/class/surface_scrolled_window.rs index bb382bd..1f7a52d 100644 --- a/crates/ghostty-apprt-gtk/src/class/surface_scrolled_window.rs +++ b/crates/ghostty-apprt-gtk/src/class/surface_scrolled_window.rs @@ -11,8 +11,7 @@ //! `GtkWidget` (any `crate::class::surface::Surface` is accepted) and the //! `config` property as `GObject` (a `crate::class::config::Config`). -use adw::prelude::*; -use adw::subclass::prelude::*; +use adw::{prelude::*, subclass::prelude::*}; use gtk::glib; glib::wrapper! { @@ -75,9 +74,10 @@ mod imp { impl SurfaceScrolledWindow { #[template_callback(function)] fn scrollbar_policy(config: Option) -> gtk::PolicyType { - use crate::class::config::Config; use ghostty_config::types_b::Scrollbar; + use crate::class::config::Config; + let Some(config) = config.and_then(|c| c.downcast::().ok()) else { return gtk::PolicyType::Automatic; }; diff --git a/crates/ghostty-apprt-gtk/src/class/tab.rs b/crates/ghostty-apprt-gtk/src/class/tab.rs index 1284fc7..8fd6421 100644 --- a/crates/ghostty-apprt-gtk/src/class/tab.rs +++ b/crates/ghostty-apprt-gtk/src/class/tab.rs @@ -5,17 +5,20 @@ use std::cell::RefCell; -use adw::prelude::*; -use adw::subclass::prelude::*; +use adw::{prelude::*, subclass::prelude::*}; use ghostty_apprt::surface::NewSurfaceContext; -use gtk::gio; -use gtk::glib::{self, clone, subclass::Signal}; +use gtk::{ + gio, + glib::{self, clone, subclass::Signal}, +}; -use super::application::Application; -use super::config::Config; -use super::split_tree::{SplitTree, SurfaceTree}; -use super::surface::{Surface, SurfaceOverrides}; -use super::title_dialog::{Target as TitleTarget, TitleDialog}; +use super::{ + application::Application, + config::Config, + split_tree::{SplitTree, SurfaceTree}, + surface::{Surface, SurfaceOverrides}, + title_dialog::{Target as TitleTarget, TitleDialog}, +}; glib::wrapper! { pub struct Tab(ObjectSubclass) diff --git a/crates/ghostty-apprt-gtk/src/class/title_dialog.rs b/crates/ghostty-apprt-gtk/src/class/title_dialog.rs index 61af100..ee63f81 100644 --- a/crates/ghostty-apprt-gtk/src/class/title_dialog.rs +++ b/crates/ghostty-apprt-gtk/src/class/title_dialog.rs @@ -1,13 +1,14 @@ //! Port of apprt/gtk/class/title_dialog.zig (`GhosttyTitleDialog`). //! Properties `target`, `initial-value`; signal `set(title: string)`. -use adw::prelude::*; -use adw::subclass::prelude::*; +use std::{ + cell::{Cell, RefCell}, + sync::OnceLock, +}; + +use adw::{prelude::*, subclass::prelude::*}; use ghostty_os::i18n::tr; -use gtk::glib; -use gtk::glib::subclass::Signal; -use std::cell::{Cell, RefCell}; -use std::sync::OnceLock; +use gtk::{glib, glib::subclass::Signal}; /// `GhosttyTitleDialogTarget`. #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, glib::Enum)] @@ -29,13 +30,20 @@ impl Target { } mod imp { + use gtk::{glib, glib::prelude::*, subclass::prelude::*}; + use super::{ - AdwAlertDialogImpl, AdwDialogImpl, Cell, ObjectImpl, ObjectSubclass, OnceLock, RefCell, - Signal, Target, WidgetImpl, + AdwAlertDialogImpl, + AdwDialogImpl, + Cell, + ObjectImpl, + ObjectSubclass, + OnceLock, + RefCell, + Signal, + Target, + WidgetImpl, }; - use gtk::glib; - use gtk::glib::prelude::*; - use gtk::subclass::prelude::*; #[derive(Default, glib::Properties, gtk::CompositeTemplate)] #[properties(wrapper_type = super::TitleDialog)] diff --git a/crates/ghostty-apprt-gtk/src/class/window.rs b/crates/ghostty-apprt-gtk/src/class/window.rs index be913bf..ce51b5c 100644 --- a/crates/ghostty-apprt-gtk/src/class/window.rs +++ b/crates/ghostty-apprt-gtk/src/class/window.rs @@ -13,34 +13,51 @@ //! [`Surface`] object (Zig took the `*CoreSurface` and used //! `rt_surface.gobj()`); the core surface is looked up via `Surface::core()`. -use std::cell::{Cell, RefCell}; -use std::rc::Rc; -use std::time::Duration; +use std::{ + cell::{Cell, RefCell}, + rc::Rc, + time::Duration, +}; -use adw::prelude::*; -use adw::subclass::prelude::*; +use adw::{prelude::*, subclass::prelude::*}; use ghostty_apprt::surface::NewSurfaceContext; -use ghostty_config::command::Command as ConfigCommand; -use ghostty_config::types_a::WindowSubtitle; -use ghostty_config::types_b::{ - GtkTabsLocation, GtkTitlebarStyle, GtkToolbarStyle, WindowDecoration, WindowNewTabPosition, - WindowShowTabBar, WindowTheme, +use ghostty_config::{ + command::Command as ConfigCommand, + types_a::WindowSubtitle, + types_b::{ + GtkTabsLocation, + GtkTitlebarStyle, + GtkToolbarStyle, + WindowDecoration, + WindowNewTabPosition, + WindowShowTabBar, + WindowTheme, + }, }; use ghostty_input::binding::{Action as BindingAction, CloseTabMode}; use ghostty_os::i18n::tr; -use gtk::glib::{self, clone}; -use gtk::{CompositeTemplate, TemplateChild, gio}; +use gtk::{ + CompositeTemplate, + TemplateChild, + gio, + glib::{self, clone}, +}; -use super::application::Application; -use super::close_confirmation_dialog::{CloseConfirmationDialog, Target as CloseTarget}; -use super::command_palette::CommandPalette; -use super::config::Config; -use super::debug_warning::DebugWarning; -use super::split_tree::{SplitTree, SurfaceTree, Tree}; -use super::surface::{Surface, SurfaceOverrides}; -use super::tab::Tab; -use crate::winproto::{self, WindowHost}; -use crate::{adw_version, gtk_version}; +use super::{ + application::Application, + close_confirmation_dialog::{CloseConfirmationDialog, Target as CloseTarget}, + command_palette::CommandPalette, + config::Config, + debug_warning::DebugWarning, + split_tree::{SplitTree, SurfaceTree, Tree}, + surface::{Surface, SurfaceOverrides}, + tab::Tab, +}; +use crate::{ + adw_version, + gtk_version, + winproto::{self, WindowHost}, +}; /// Which tab to select (Zig: `Window.SelectTab`). #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -108,15 +125,30 @@ impl WindowHost for Host { } mod imp { + use std::marker::PhantomData; + + use adw::{prelude::*, subclass::prelude::*}; + use super::{ - Cell, CommandPalette, CompositeTemplate, Config, DebugWarning, NewSurfaceContext, RefCell, - SplitTree, Surface, Tab, TabOverrides, TemplateChild, TitlebarStyle, Window as WindowObj, - WindowDecoration, glib, gtk_version, + Cell, + CommandPalette, + CompositeTemplate, + Config, + DebugWarning, + NewSurfaceContext, + RefCell, + SplitTree, + Surface, + Tab, + TabOverrides, + TemplateChild, + TitlebarStyle, + Window as WindowObj, + WindowDecoration, + glib, + gtk_version, }; use crate::winproto; - use adw::prelude::*; - use adw::subclass::prelude::*; - use std::marker::PhantomData; #[derive(glib::Properties, CompositeTemplate)] #[properties(wrapper_type = WindowObj)] diff --git a/crates/ghostty-apprt-gtk/src/css.rs b/crates/ghostty-apprt-gtk/src/css.rs index 66a14f5..1abb094 100644 --- a/crates/ghostty-apprt-gtk/src/css.rs +++ b/crates/ghostty-apprt-gtk/src/css.rs @@ -12,9 +12,7 @@ use std::fmt::Write as _; -use ghostty_config::config::Config; -use ghostty_config::path::Path; -use ghostty_config::types_b::WindowTheme; +use ghostty_config::{config::Config, path::Path, types_b::WindowTheme}; use gtk::{gdk, glib, prelude::*}; /// Maximum size of a `gtk-custom-css` file. diff --git a/crates/ghostty-apprt-gtk/src/debug_input.rs b/crates/ghostty-apprt-gtk/src/debug_input.rs index 1467d83..c8f744f 100644 --- a/crates/ghostty-apprt-gtk/src/debug_input.rs +++ b/crates/ghostty-apprt-gtk/src/debug_input.rs @@ -36,17 +36,11 @@ //! with a few lowercase aliases (`enter`, `esc`, `up`, ...). Commands act on //! the active surface of the active window at the time they run. -use std::cell::RefCell; -use std::rc::Rc; -use std::time::Duration; +use std::{cell::RefCell, rc::Rc, time::Duration}; -use gtk::glib::translate::IntoGlib; -use gtk::prelude::*; -use gtk::{gdk, glib}; +use gtk::{gdk, glib, glib::translate::IntoGlib, prelude::*}; -use crate::class::application::Application; -use crate::class::surface::Surface; -use crate::class::window::Window; +use crate::class::{application::Application, surface::Surface, window::Window}; /// One parsed command. #[derive(Debug, Clone, PartialEq)] diff --git a/crates/ghostty-apprt-gtk/src/ext/actions.rs b/crates/ghostty-apprt-gtk/src/ext/actions.rs index 80ae7cb..c40bb53 100644 --- a/crates/ghostty-apprt-gtk/src/ext/actions.rs +++ b/crates/ghostty-apprt-gtk/src/ext/actions.rs @@ -1,9 +1,6 @@ //! GAction helpers (port of `apprt/gtk/ext/actions.zig`). -use gtk::gio; -use gtk::glib; -use gtk::glib::prelude::*; -use gtk::prelude::*; +use gtk::{gio, glib, glib::prelude::*, prelude::*}; fn g_action_name_is_valid(name: &str) -> bool { !name.is_empty() diff --git a/crates/ghostty-apprt-gtk/src/ext/mod.rs b/crates/ghostty-apprt-gtk/src/ext/mod.rs index d362f0e..38dbee6 100644 --- a/crates/ghostty-apprt-gtk/src/ext/mod.rs +++ b/crates/ghostty-apprt-gtk/src/ext/mod.rs @@ -6,12 +6,9 @@ pub mod actions; pub mod slice; +use gtk::{glib, glib::prelude::*, prelude::*}; pub use slice::StringList; -use gtk::glib; -use gtk::glib::prelude::*; -use gtk::prelude::*; - /// Get the first ancestor of `widget` of type `T`. pub fn get_ancestor>(widget: &impl IsA) -> Option { widget.ancestor(T::static_type()).and_downcast::() diff --git a/crates/ghostty-apprt-gtk/src/ext/slice.rs b/crates/ghostty-apprt-gtk/src/ext/slice.rs index 558c004..bffa86f 100644 --- a/crates/ghostty-apprt-gtk/src/ext/slice.rs +++ b/crates/ghostty-apprt-gtk/src/ext/slice.rs @@ -20,9 +20,10 @@ impl StringList { #[cfg(test)] mod tests { - use super::*; use gtk::glib::prelude::*; + use super::*; + #[test] fn string_list_create_and_destroy() { let list = StringList::create(&["hello", "world"]); diff --git a/crates/ghostty-apprt-gtk/src/gl.rs b/crates/ghostty-apprt-gtk/src/gl.rs index 753b79c..a459622 100644 --- a/crates/ghostty-apprt-gtk/src/gl.rs +++ b/crates/ghostty-apprt-gtk/src/gl.rs @@ -7,8 +7,7 @@ //! `glow::Context::from_loader_function` need. Call it only while the GLArea //! context is current. -use std::ffi::c_void; -use std::sync::OnceLock; +use std::{ffi::c_void, sync::OnceLock}; fn epoxy() -> Option<&'static libloading::Library> { static LIB: OnceLock> = OnceLock::new(); diff --git a/crates/ghostty-apprt-gtk/src/gsettings.rs b/crates/ghostty-apprt-gtk/src/gsettings.rs index 1dd19bf..53addca 100644 --- a/crates/ghostty-apprt-gtk/src/gsettings.rs +++ b/crates/ghostty-apprt-gtk/src/gsettings.rs @@ -1,7 +1,6 @@ //! Typed access to `GtkSettings` (port of `apprt/gtk/gsettings.zig`). -use gtk::glib; -use gtk::prelude::*; +use gtk::{glib, prelude::*}; /// Settings keys we read (the GTK property names). #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/crates/ghostty-apprt-gtk/src/ipc/dbus.rs b/crates/ghostty-apprt-gtk/src/ipc/dbus.rs index e57af0f..aeb6afd 100644 --- a/crates/ghostty-apprt-gtk/src/ipc/dbus.rs +++ b/crates/ghostty-apprt-gtk/src/ipc/dbus.rs @@ -1,9 +1,7 @@ //! D-Bus helper for IPC (port of `apprt/gtk/ipc/DBus.zig`). use ghostty_apprt::ipc::{Error, Target}; -use gtk::gio; -use gtk::glib; -use gtk::prelude::*; +use gtk::{gio, glib, prelude::*}; /// A pending `org.gtk.Actions.Activate` call. pub struct DBus { diff --git a/crates/ghostty-apprt-gtk/src/key.rs b/crates/ghostty-apprt-gtk/src/key.rs index d07f393..abf8f13 100644 --- a/crates/ghostty-apprt-gtk/src/key.rs +++ b/crates/ghostty-apprt-gtk/src/key.rs @@ -2,13 +2,12 @@ use std::fmt::Write as _; -use ghostty_input::binding::{Trigger, TriggerKey}; -use ghostty_input::key::{Action, Key as K}; -use ghostty_input::key_mods::{ModSide, Mods}; -use gtk::gdk; -use gtk::gdk::prelude::DeviceExt; -use gtk::glib::translate::IntoGlib; -use gtk::prelude::*; +use ghostty_input::{ + binding::{Trigger, TriggerKey}, + key::{Action, Key as K}, + key_mods::{ModSide, Mods}, +}; +use gtk::{gdk, gdk::prelude::DeviceExt, glib::translate::IntoGlib, prelude::*}; /// Name of a keyval (`gdk.keyvalName`). fn keyval_name(keyval: u32) -> Option { diff --git a/crates/ghostty-apprt-gtk/src/post_fork.rs b/crates/ghostty-apprt-gtk/src/post_fork.rs index 017d5e0..1d75519 100644 --- a/crates/ghostty-apprt-gtk/src/post_fork.rs +++ b/crates/ghostty-apprt-gtk/src/post_fork.rs @@ -1,10 +1,11 @@ //! Parent post-fork hook creating the transient scope (port of //! `apprt/gtk/post_fork.zig`). -use ghostty_config::config::Config; -use ghostty_config::types_b::{GtkSingleInstance, LinuxCgroup}; -use gtk::gio; -use gtk::prelude::*; +use ghostty_config::{ + config::Config, + types_b::{GtkSingleInstance, LinuxCgroup}, +}; +use gtk::{gio, prelude::*}; use crate::cgroup; diff --git a/crates/ghostty-apprt-gtk/src/pre_exec.rs b/crates/ghostty-apprt-gtk/src/pre_exec.rs index 64c19ee..a502628 100644 --- a/crates/ghostty-apprt-gtk/src/pre_exec.rs +++ b/crates/ghostty-apprt-gtk/src/pre_exec.rs @@ -4,8 +4,10 @@ //! sleeps. The wait loop is shared with `ghostty-termio` via //! `ghostty_os::cgroup::wait_for_scope`. -use ghostty_config::config::Config; -use ghostty_config::types_b::{GtkSingleInstance, LinuxCgroup}; +use ghostty_config::{ + config::Config, + types_b::{GtkSingleInstance, LinuxCgroup}, +}; use crate::cgroup; diff --git a/crates/ghostty-apprt-gtk/src/weak_ref.rs b/crates/ghostty-apprt-gtk/src/weak_ref.rs index d67e0ed..6adb167 100644 --- a/crates/ghostty-apprt-gtk/src/weak_ref.rs +++ b/crates/ghostty-apprt-gtk/src/weak_ref.rs @@ -2,8 +2,7 @@ //! already provides `glib::WeakRef`; this wrapper keeps the Zig API //! (`set`/`get`/`empty`). -use gtk::glib; -use gtk::glib::prelude::*; +use gtk::{glib, glib::prelude::*}; /// A weak reference to a GObject of type `T`. #[derive(Debug, Default)] diff --git a/crates/ghostty-apprt-gtk/src/winproto/mod.rs b/crates/ghostty-apprt-gtk/src/winproto/mod.rs index 0fa1178..9751176 100644 --- a/crates/ghostty-apprt-gtk/src/winproto/mod.rs +++ b/crates/ghostty-apprt-gtk/src/winproto/mod.rs @@ -8,15 +8,11 @@ //! code held a `*ApprtWindow` pointer; here the window GObject implements //! [`WindowHost`] (a small, weak-referencing adapter), see below. -use std::rc::Rc; -use std::sync::Arc; +use std::{rc::Rc, sync::Arc}; -use gtk::gdk; -use gtk::prelude::*; - -use ghostty_config::config::Config; -use ghostty_config::types_b::WindowDecoration; +use ghostty_config::{config::Config, types_b::WindowDecoration}; use ghostty_input::Mods; +use gtk::{gdk, prelude::*}; pub mod noop; pub mod wayland; diff --git a/crates/ghostty-apprt-gtk/src/winproto/noop.rs b/crates/ghostty-apprt-gtk/src/winproto/noop.rs index f2a33a4..b87b708 100644 --- a/crates/ghostty-apprt-gtk/src/winproto/noop.rs +++ b/crates/ghostty-apprt-gtk/src/winproto/noop.rs @@ -3,10 +3,10 @@ use std::rc::Rc; +use ghostty_input::Mods; use gtk::gdk; use super::{Result, WindowHost}; -use ghostty_input::Mods; #[derive(Debug, Default, Clone, Copy)] pub struct App; diff --git a/crates/ghostty-apprt-gtk/src/winproto/wayland.rs b/crates/ghostty-apprt-gtk/src/winproto/wayland.rs index f679cd3..df1ac1f 100644 --- a/crates/ghostty-apprt-gtk/src/winproto/wayland.rs +++ b/crates/ghostty-apprt-gtk/src/winproto/wayland.rs @@ -17,42 +17,59 @@ //! first (or run with `LD_PRELOAD=libgtk4-layer-shell.so`). Without it, //! `layer_shell::is_supported()` is false and the quick terminal is disabled. -use std::cell::RefCell; -use std::rc::Rc; -use std::sync::Arc; -use std::sync::Mutex; -use std::sync::atomic::{AtomicBool, Ordering}; - -use gdk4_wayland::WaylandDisplay; -use gdk4_wayland::prelude::*; -use gtk::gdk; -use gtk::glib; -use gtk::prelude::*; -use gtk4_layer_shell::{self as layer_shell, LayerShell}; -use wayland_client::globals::{GlobalListContents, registry_queue_init}; -use wayland_client::protocol::wl_registry::WlRegistry; -use wayland_client::protocol::wl_surface::WlSurface; -use wayland_client::{Connection, Dispatch, EventQueue, Proxy, QueueHandle}; -use wayland_protocols::xdg::activation::v1::client::xdg_activation_token_v1::{ - self, XdgActivationTokenV1, +use std::{ + cell::RefCell, + rc::Rc, + sync::{ + Arc, + Mutex, + atomic::{AtomicBool, Ordering}, + }, }; -use wayland_protocols::xdg::activation::v1::client::xdg_activation_v1::XdgActivationV1; -use wayland_protocols_plasma::blur::client::org_kde_kwin_blur::OrgKdeKwinBlur; -use wayland_protocols_plasma::blur::client::org_kde_kwin_blur_manager::OrgKdeKwinBlurManager; -use wayland_protocols_plasma::server_decoration::client::org_kde_kwin_server_decoration::OrgKdeKwinServerDecoration; -use wayland_protocols_plasma::server_decoration::client::org_kde_kwin_server_decoration_manager::{ - self, OrgKdeKwinServerDecorationManager, -}; -use wayland_protocols_plasma::slide::client::org_kde_kwin_slide::OrgKdeKwinSlide; -use wayland_protocols_plasma::slide::client::org_kde_kwin_slide_manager::OrgKdeKwinSlideManager; -use super::{Error, Result, WindowHost}; -use ghostty_config::config::Config; -use ghostty_config::types_b::{ - QuickTerminalDimensions, QuickTerminalKeyboardInteractivity, QuickTerminalLayer, - QuickTerminalPosition, WindowDecoration, +use gdk4_wayland::{WaylandDisplay, prelude::*}; +use ghostty_config::{ + config::Config, + types_b::{ + QuickTerminalDimensions, + QuickTerminalKeyboardInteractivity, + QuickTerminalLayer, + QuickTerminalPosition, + WindowDecoration, + }, }; use ghostty_input::Mods; +use gtk::{gdk, glib, prelude::*}; +use gtk4_layer_shell::{self as layer_shell, LayerShell}; +use wayland_client::{ + Connection, + Dispatch, + EventQueue, + Proxy, + QueueHandle, + globals::{GlobalListContents, registry_queue_init}, + protocol::{wl_registry::WlRegistry, wl_surface::WlSurface}, +}; +use wayland_protocols::xdg::activation::v1::client::{ + xdg_activation_token_v1::{self, XdgActivationTokenV1}, + xdg_activation_v1::XdgActivationV1, +}; +use wayland_protocols_plasma::{ + blur::client::{ + org_kde_kwin_blur::OrgKdeKwinBlur, + org_kde_kwin_blur_manager::OrgKdeKwinBlurManager, + }, + server_decoration::client::{ + org_kde_kwin_server_decoration::OrgKdeKwinServerDecoration, + org_kde_kwin_server_decoration_manager::{self, OrgKdeKwinServerDecorationManager}, + }, + slide::client::{ + org_kde_kwin_slide::OrgKdeKwinSlide, + org_kde_kwin_slide_manager::OrgKdeKwinSlideManager, + }, +}; + +use super::{Error, Result, WindowHost}; /// `org_kde_kwin_server_decoration_manager.mode` values. const DECO_NONE: u32 = 0; diff --git a/crates/ghostty-apprt-gtk/src/winproto/x11.rs b/crates/ghostty-apprt-gtk/src/winproto/x11.rs index a9b6e61..80bc387 100644 --- a/crates/ghostty-apprt-gtk/src/winproto/x11.rs +++ b/crates/ghostty-apprt-gtk/src/winproto/x11.rs @@ -5,17 +5,16 @@ //! comments. #![allow(unsafe_code)] -use std::ffi::{c_int, c_long, c_uchar, c_uint, c_ulong, c_void}; -use std::rc::Rc; +use std::{ + ffi::{c_int, c_long, c_uchar, c_uint, c_ulong, c_void}, + rc::Rc, +}; -use gdk4_x11::x11::xlib; -use gdk4_x11::{X11Display, X11Surface}; -use gtk::gdk; -use gtk::glib; -use gtk::prelude::*; +use gdk4_x11::{X11Display, X11Surface, x11::xlib}; +use ghostty_input::Mods; +use gtk::{gdk, glib, prelude::*}; use super::{Error, Result, WindowHost}; -use ghostty_input::Mods; // XKB bits we need that the `x11` crate doesn't expose (XKBlib.h / XKB.h). const XKB_MAJOR_VERSION: c_int = 1; diff --git a/crates/ghostty-apprt/src/action.rs b/crates/ghostty-apprt/src/action.rs index 55d6e00..ede94bd 100644 --- a/crates/ghostty-apprt/src/action.rs +++ b/crates/ghostty-apprt/src/action.rs @@ -3,14 +3,14 @@ //! C-ABI plumbing (`C`, `CValue`, `cval`, `ghostty.h` sync tests) is not //! ported; the enums keep their C integer discriminants via `as i32`. -use crate::surface::{ChildExited, RendererHealth, Scrollbar}; -use ghostty_config::config::Config; -use ghostty_config::types_b::Duration; -use ghostty_input::binding::Trigger; -use ghostty_vt::mouse_shape::MouseShape; -use ghostty_vt::osc::ProgressReport; use std::sync::Arc; +use ghostty_config::{config::Config, types_b::Duration}; +use ghostty_input::binding::Trigger; +use ghostty_vt::{mouse_shape::MouseShape, osc::ProgressReport}; + +use crate::surface::{ChildExited, RendererHealth, Scrollbar}; + /// The target for an action. This is generally the thing that had focus /// while the action was made but the concept of "focus" is not guaranteed /// since actions can also be triggered by timers, scripts, etc. diff --git a/crates/ghostty-apprt/src/lib.rs b/crates/ghostty-apprt/src/lib.rs index b7097c1..89aca81 100644 --- a/crates/ghostty-apprt/src/lib.rs +++ b/crates/ghostty-apprt/src/lib.rs @@ -13,6 +13,14 @@ pub mod surface; pub use action::{Action, Target}; pub use structs::{ - Clipboard, ClipboardContent, ClipboardRequest, ClipboardRequestType, ColorScheme, ContentScale, - CursorPos, ImePos, Selection, SurfaceSize, + Clipboard, + ClipboardContent, + ClipboardRequest, + ClipboardRequestType, + ColorScheme, + ContentScale, + CursorPos, + ImePos, + Selection, + SurfaceSize, }; diff --git a/crates/ghostty-apprt/src/runtime_api.rs b/crates/ghostty-apprt/src/runtime_api.rs index 4541d5c..f3cbd49 100644 --- a/crates/ghostty-apprt/src/runtime_api.rs +++ b/crates/ghostty-apprt/src/runtime_api.rs @@ -15,16 +15,24 @@ //! //! See `docs/rewrite/notes/ghostty-apprt-gtk.md` for the full spec. -use std::rc::Rc; -use std::sync::Arc; +use std::{rc::Rc, sync::Arc}; -use crate::action::{Action, Target}; -use crate::structs::{ - Clipboard, ClipboardRequest, ColorScheme, ContentScale, CursorPos, ImePos, SurfaceSize, -}; use ghostty_config::config::Config; use ghostty_input::{Mods, MouseButton, MouseButtonState, ScrollMods}; +use crate::{ + action::{Action, Target}, + structs::{ + Clipboard, + ClipboardRequest, + ColorScheme, + ContentScale, + CursorPos, + ImePos, + SurfaceSize, + }, +}; + /// Identifier for a core surface (Zig: `*CoreSurface` pointer). Allocated by /// this crate for each GTK surface; core stores it in its `Target::Surface`. pub type SurfaceId = u64; diff --git a/crates/ghostty-apprt/src/surface.rs b/crates/ghostty-apprt/src/surface.rs index 2da199a..197fc3d 100644 --- a/crates/ghostty-apprt/src/surface.rs +++ b/crates/ghostty-apprt/src/surface.rs @@ -1,15 +1,16 @@ //! Port of `surface.zig`: messages sent from the core to a surface's apprt. -use crate::structs::Clipboard; -use ghostty_config::config::Config; -use ghostty_config::types_a::WorkingDirectory; -use ghostty_datastruct::MessageData; -use ghostty_datastruct::blocking_queue::Timeout; -use ghostty_vt::mouse_shape::MouseShape; -use ghostty_vt::osc::ProgressReport; -use ghostty_vt::osc::color::ColoredTarget; use std::sync::Arc; +use ghostty_config::{config::Config, types_a::WorkingDirectory}; +use ghostty_datastruct::{MessageData, blocking_queue::Timeout}; +use ghostty_vt::{ + mouse_shape::MouseShape, + osc::{ProgressReport, color::ColoredTarget}, +}; + +use crate::structs::Clipboard; + /// Represents a write request. Magic number comes from the max size /// we want this union to be. pub type WriteReq = MessageData; @@ -233,9 +234,10 @@ pub fn new_config(config: &Config, context: NewSurfaceContext, prev_pwd: Option< #[cfg(test)] mod tests { - use super::*; use std::cell::RefCell; + use super::*; + struct Rec(RefCell>); impl AppMailbox for Rec { fn push_surface_message(&self, s: u32, m: Message, _t: Timeout) -> usize { diff --git a/crates/ghostty-bench/src/args.rs b/crates/ghostty-bench/src/args.rs index 20bb855..8cfc815 100644 --- a/crates/ghostty-bench/src/args.rs +++ b/crates/ghostty-bench/src/args.rs @@ -1,9 +1,11 @@ //! Minimal `--key=value` option parsing (the subset of `cli/args.zig` used by //! the benchmark and synthetic CLIs). -use std::collections::HashMap; -use std::fs::File; -use std::io::{self, Read}; -use std::str::FromStr; +use std::{ + collections::HashMap, + fs::File, + io::{self, Read}, + str::FromStr, +}; /// Parsed `--key[=value]` arguments. #[derive(Debug, Default)] diff --git a/crates/ghostty-bench/src/benches.rs b/crates/ghostty-bench/src/benches.rs index 14e2a9d..c162690 100644 --- a/crates/ghostty-bench/src/benches.rs +++ b/crates/ghostty-bench/src/benches.rs @@ -1,7 +1,7 @@ //! The individual benchmarks (ports of `benchmark/*.zig`) and the CLI action //! dispatch (`benchmark/cli.zig`). -use crate::args::{Args, data_file, read_short}; -use crate::benchmark::{Benchmark, BenchmarkFailed, Result, RunMode, RunResult, run}; +use std::{hint::black_box, io::Read}; + use ghostty_terminal::{ point::{Coordinate, Point}, render::RenderState, @@ -14,8 +14,11 @@ use ghostty_vt::{ stream::{Action, Handler, Stream}, utf8_decoder::Utf8Decoder, }; -use std::hint::black_box; -use std::io::Read; + +use crate::{ + args::{Args, data_file, read_short}, + benchmark::{Benchmark, BenchmarkFailed, Result, RunMode, RunResult, run}, +}; const CHUNK: usize = 4096; diff --git a/crates/ghostty-bench/src/bin/ghostty-synthetic.rs b/crates/ghostty-bench/src/bin/ghostty-synthetic.rs index 83282d4..78ea769 100644 --- a/crates/ghostty-bench/src/bin/ghostty-synthetic.rs +++ b/crates/ghostty-bench/src/bin/ghostty-synthetic.rs @@ -1,11 +1,14 @@ //! `ghostty-synthetic + [--option=value ...]`: endless //! synthetic data on stdout (port of `synthetic/main.zig`). +use std::{ + io::{BufWriter, Write}, + process::ExitCode, +}; + use ghostty_bench::{ args::Args, synthetic::{OscStyle, Rng, run_ascii, run_osc, run_sgr, run_utf8}, }; -use std::io::{BufWriter, Write}; -use std::process::ExitCode; fn run() -> Result<(), String> { let argv: Vec = std::env::args().skip(1).collect(); diff --git a/crates/ghostty-bench/src/main.rs b/crates/ghostty-bench/src/main.rs index 042b098..351ed77 100644 --- a/crates/ghostty-bench/src/main.rs +++ b/crates/ghostty-bench/src/main.rs @@ -1,7 +1,8 @@ //! `ghostty-bench + [--option=value ...]` (port of `main_bench.zig`). -use ghostty_bench::{args::Args, benches}; use std::process::ExitCode; +use ghostty_bench::{args::Args, benches}; + fn main() -> ExitCode { let argv: Vec = std::env::args().skip(1).collect(); let mut action = None; diff --git a/crates/ghostty-bench/src/synthetic.rs b/crates/ghostty-bench/src/synthetic.rs index 7247728..4a8848b 100644 --- a/crates/ghostty-bench/src/synthetic.rs +++ b/crates/ghostty-bench/src/synthetic.rs @@ -1,8 +1,9 @@ //! Synthetic data generators (port of `ZIG/src/synthetic`): random bytes, //! UTF-8 and OSC sequences, used to feed the benchmarks. -use ghostty_vt::string_encoding::url_percent_encode; use std::io::{self, Write}; +use ghostty_vt::string_encoding::url_percent_encode; + /// xoshiro256++ (what Zig's `std.Random.DefaultPrng` is). #[derive(Debug, Clone)] pub struct Rng { @@ -666,9 +667,10 @@ fn finished(r: io::Result) -> io::Result { #[cfg(test)] mod tests { - use super::*; use ghostty_vt::osc::Parser; + use super::*; + const SEED: u64 = 0xC0FFEEEEEEEEEEEE; #[test] diff --git a/crates/ghostty-build-data/src/bash.rs b/crates/ghostty-build-data/src/bash.rs index 243e527..310e5c1 100644 --- a/crates/ghostty-build-data/src/bash.rs +++ b/crates/ghostty-build-data/src/bash.rs @@ -4,8 +4,13 @@ use std::fmt::Write as _; use ghostty_config::cli_args::FieldKind; -use crate::chunks_bash::{C0, C1, C2, C3, C4, C5, C6}; -use crate::{actions, config_fields, join_names, join_packed}; +use crate::{ + actions, + chunks_bash::{C0, C1, C2, C3, C4, C5, C6}, + config_fields, + join_names, + join_packed, +}; const COMPGEN_PREFIX: &str = "_compreply compgen -W \""; const COMPGEN_SUFFIX: &str = "\" -- \"$cur\"; _add_spaces ;;"; diff --git a/crates/ghostty-build-data/src/lib.rs b/crates/ghostty-build-data/src/lib.rs index d1c5e18..e3fa2e6 100644 --- a/crates/ghostty-build-data/src/lib.rs +++ b/crates/ghostty-build-data/src/lib.rs @@ -8,9 +8,7 @@ #![cfg_attr(test, allow(clippy::expect_used))] use ghostty_cli::Action; -use ghostty_config::cli_args::FieldKind; -use ghostty_config::config::Config; -use ghostty_config::macros::ConfigStruct; +use ghostty_config::{cli_args::FieldKind, config::Config, macros::ConfigStruct}; pub mod bash; pub mod fish; diff --git a/crates/ghostty-build-data/src/main.rs b/crates/ghostty-build-data/src/main.rs index 1cdf15e..a284d39 100644 --- a/crates/ghostty-build-data/src/main.rs +++ b/crates/ghostty-build-data/src/main.rs @@ -5,8 +5,7 @@ //! +vim-ftdetect|+vim-ftplugin|+vim-compiler|+terminfo|+mdgen-ghostty-1| //! +mdgen-ghostty-5` -use std::io::Write; -use std::process::ExitCode; +use std::{io::Write, process::ExitCode}; use ghostty_build_data::Mode; diff --git a/crates/ghostty-build-data/src/sublime.rs b/crates/ghostty-build-data/src/sublime.rs index 850682a..cb24f92 100644 --- a/crates/ghostty-build-data/src/sublime.rs +++ b/crates/ghostty-build-data/src/sublime.rs @@ -1,7 +1,9 @@ //! Sublime syntax (also used by `bat`) (port of `extra/sublime.zig`). -use crate::chunks_sublime::{C0, C1}; -use crate::config_fields; +use crate::{ + chunks_sublime::{C0, C1}, + config_fields, +}; #[must_use] pub fn syntax() -> String { diff --git a/crates/ghostty-build-data/src/vim.rs b/crates/ghostty-build-data/src/vim.rs index de33879..3ae4f43 100644 --- a/crates/ghostty-build-data/src/vim.rs +++ b/crates/ghostty-build-data/src/vim.rs @@ -2,8 +2,10 @@ use std::fmt::Write as _; -use crate::chunks_vim::{C0, C1, C2, C3, C4}; -use crate::config_fields; +use crate::{ + chunks_vim::{C0, C1, C2, C3, C4}, + config_fields, +}; pub const FTDETECT: &str = C0; pub const FTPLUGIN: &str = C1; diff --git a/crates/ghostty-build-data/src/zsh.rs b/crates/ghostty-build-data/src/zsh.rs index 16bd8a9..6940ec7 100644 --- a/crates/ghostty-build-data/src/zsh.rs +++ b/crates/ghostty-build-data/src/zsh.rs @@ -4,8 +4,13 @@ use std::fmt::Write as _; use ghostty_config::cli_args::FieldKind; -use crate::chunks_zsh::{C0, C1, C2, C3}; -use crate::{actions, config_fields, join_names, join_packed}; +use crate::{ + actions, + chunks_zsh::{C0, C1, C2, C3}, + config_fields, + join_names, + join_packed, +}; const EQUALS_REQUIRED: &str = "=-:::"; diff --git a/crates/ghostty-cli/build.rs b/crates/ghostty-cli/build.rs index 04f5d69..0cb71a0 100644 --- a/crates/ghostty-cli/build.rs +++ b/crates/ghostty-cli/build.rs @@ -8,8 +8,10 @@ //! The version can be overridden with `GHOSTTY_VERSION_STRING` (Zig: //! `-Dversion-string`), which must be a semantic version. -use std::path::{Path, PathBuf}; -use std::process::Command; +use std::{ + path::{Path, PathBuf}, + process::Command, +}; fn run(cmd: &str, args: &[&str], dir: &Path) -> Option { let out = Command::new(cmd) diff --git a/crates/ghostty-cli/src/action.rs b/crates/ghostty-cli/src/action.rs index a9c7049..fdf8001 100644 --- a/crates/ghostty-cli/src/action.rs +++ b/crates/ghostty-cli/src/action.rs @@ -104,9 +104,10 @@ where #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)] - use super::*; use ghostty_config::cli_args::split_args; + use super::*; + #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum Plain { Foo, diff --git a/crates/ghostty-cli/src/boo.rs b/crates/ghostty-cli/src/boo.rs index de46050..337b19b 100644 --- a/crates/ghostty-cli/src/boo.rs +++ b/crates/ghostty-cli/src/boo.rs @@ -5,17 +5,20 @@ //! joined with `\x01` and raw-deflate compressed into `boo_frames.deflate` //! (the same format `framegen` produces for Zig's `framedata`). -use std::io::Read; -use std::time::{Duration, Instant}; +use std::{ + io::Read, + time::{Duration, Instant}, +}; use flate2::read::DeflateDecoder; -use ratatui::buffer::Buffer; -use ratatui::crossterm::event::{self, Event, KeyCode, KeyEventKind, KeyModifiers}; -use ratatui::layout::Rect; -use ratatui::style::{Color, Style}; +use ratatui::{ + buffer::Buffer, + crossterm::event::{self, Event, KeyCode, KeyEventKind, KeyModifiers}, + layout::Rect, + style::{Color, Style}, +}; -use crate::error::Error; -use crate::options::NoOptions as Options; +use crate::{error::Error, options::NoOptions as Options}; static FRAME_DATA: &[u8] = include_bytes!("boo_frames.deflate"); diff --git a/crates/ghostty-cli/src/crash_report.rs b/crates/ghostty-cli/src/crash_report.rs index 0da7e47..e1da471 100644 --- a/crates/ghostty-cli/src/crash_report.rs +++ b/crates/ghostty-cli/src/crash_report.rs @@ -4,14 +4,15 @@ //! Ghostty uses sentry for crash reporting; only the listing behaviour is //! ported. -use std::io::{IsTerminal, Write}; -use std::path::PathBuf; -use std::time::{SystemTime, UNIX_EPOCH}; +use std::{ + io::{IsTerminal, Write}, + path::PathBuf, + time::{SystemTime, UNIX_EPOCH}, +}; use ghostty_config::types_b::Duration; use crate::error::Error; - pub use crate::options::NoOptions as Options; /// A crash report file (Zig: `crash.Report`). diff --git a/crates/ghostty-cli/src/edit_config.rs b/crates/ghostty-cli/src/edit_config.rs index ddb590e..eb6a80a 100644 --- a/crates/ghostty-cli/src/edit_config.rs +++ b/crates/ghostty-cli/src/edit_config.rs @@ -1,12 +1,10 @@ //! `+edit-config` (ZIG/src/cli/edit_config.zig). -use std::io::Write; -use std::os::unix::process::CommandExt; +use std::{io::Write, os::unix::process::CommandExt}; use ghostty_config::config::Config; use crate::error::Error; - pub use crate::options::NoOptions as Options; /// The `edit-config` command opens the Ghostty configuration file in the diff --git a/crates/ghostty-cli/src/ghostty.rs b/crates/ghostty-cli/src/ghostty.rs index c4c6bfd..6a43dad 100644 --- a/crates/ghostty-cli/src/ghostty.rs +++ b/crates/ghostty-cli/src/ghostty.rs @@ -3,8 +3,10 @@ use std::io::Write; -use crate::action::{ActionEnum, DetectError, SpecialCase, detect_iter}; -use crate::error::Error; +use crate::{ + action::{ActionEnum, DetectError, SpecialCase, detect_iter}, + error::Error, +}; /// Special commands that can be invoked via CLI flags. These are all /// invoked by using `+` as a CLI flag. The only exception is @@ -117,8 +119,7 @@ impl Action { /// Used by the build-data generator for shell completions. #[must_use] pub fn option_fields(self) -> Vec<(&'static str, ghostty_config::cli_args::FieldKind)> { - use ghostty_config::cli_args::FieldKind; - use ghostty_config::macros::ConfigStruct; + use ghostty_config::{cli_args::FieldKind, macros::ConfigStruct}; fn of() -> Vec<(&'static str, FieldKind)> { T::FIELDS .iter() @@ -297,9 +298,10 @@ pub fn run_from_args(args: &[String]) -> Option { #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)] - use super::*; use ghostty_config::cli_args::split_args; + use super::*; + fn detect_str(s: &str) -> Result, DetectError> { detect_iter::(split_args(s)) } diff --git a/crates/ghostty-cli/src/help.rs b/crates/ghostty-cli/src/help.rs index bdc7622..fbe1b0e 100644 --- a/crates/ghostty-cli/src/help.rs +++ b/crates/ghostty-cli/src/help.rs @@ -4,8 +4,7 @@ use std::io::Write; use ghostty_config::config_struct; -use crate::error::Error; -use crate::ghostty::Action; +use crate::{error::Error, ghostty::Action}; config_struct! { // Note that this options struct doesn't implement the `help` decl like other diff --git a/crates/ghostty-cli/src/list_colors.rs b/crates/ghostty-cli/src/list_colors.rs index 6e6d689..1231519 100644 --- a/crates/ghostty-cli/src/list_colors.rs +++ b/crates/ghostty-cli/src/list_colors.rs @@ -1,12 +1,16 @@ //! `+list-colors` (ZIG/src/cli/list_colors.zig). -use std::cmp::Ordering; -use std::io::{IsTerminal, Write}; +use std::{ + cmp::Ordering, + io::{IsTerminal, Write}, +}; use ghostty_config::config_struct; -use crate::error::Error; -use crate::tui::{self, Color, PrettySession, Style}; +use crate::{ + error::Error, + tui::{self, Color, PrettySession, Style}, +}; config_struct! { pub struct Options { diff --git a/crates/ghostty-cli/src/list_fonts.rs b/crates/ghostty-cli/src/list_fonts.rs index a82cedd..24bd891 100644 --- a/crates/ghostty-cli/src/list_fonts.rs +++ b/crates/ghostty-cli/src/list_fonts.rs @@ -49,8 +49,7 @@ pub fn run(args: &[String]) -> Result { let mut opts = Options::default(); crate::parse_options(&mut opts, args)?; - use std::collections::HashMap; - use std::io::Write; + use std::{collections::HashMap, io::Write}; // We'll be putting our fonts into a list categorized by family // so it is easier to read the output. diff --git a/crates/ghostty-cli/src/list_keybinds.rs b/crates/ghostty-cli/src/list_keybinds.rs index d8f7b7f..50ef4e8 100644 --- a/crates/ghostty-cli/src/list_keybinds.rs +++ b/crates/ghostty-cli/src/list_keybinds.rs @@ -1,18 +1,28 @@ //! `+list-keybinds` (ZIG/src/cli/list_keybinds.zig), including its pretty //! (tty) output. -use std::cmp::Ordering; -use std::io::{IsTerminal, Write}; +use std::{ + cmp::Ordering, + io::{IsTerminal, Write}, +}; -use ghostty_config::config::Config; -use ghostty_config::config_struct; -use ghostty_config::formatter::EntryFormatter; -use ghostty_config::keybinds::Keybinds; -use ghostty_input::binding::set::{Set, Value}; -use ghostty_input::binding::{Action as BindingAction, Trigger, TriggerKey}; +use ghostty_config::{ + config::Config, + config_struct, + formatter::EntryFormatter, + keybinds::Keybinds, +}; +use ghostty_input::binding::{ + Action as BindingAction, + Trigger, + TriggerKey, + set::{Set, Value}, +}; -use crate::error::Error; -use crate::tui::{self, Color, PrettySession, Style, gwidth}; +use crate::{ + error::Error, + tui::{self, Color, PrettySession, Style, gwidth}, +}; config_struct! { pub struct Options { diff --git a/crates/ghostty-cli/src/list_themes.rs b/crates/ghostty-cli/src/list_themes.rs index aebdcdb..2957ea8 100644 --- a/crates/ghostty-cli/src/list_themes.rs +++ b/crates/ghostty-cli/src/list_themes.rs @@ -3,16 +3,20 @@ //! The non-interactive listing is a faithful port. The interactive preview //! (libvaxis in Zig) is implemented with ratatui + crossterm in [`preview`]. -use std::cmp::Ordering; -use std::fmt::Write as _; -use std::io::{IsTerminal, Write}; +use std::{ + cmp::Ordering, + fmt::Write as _, + io::{IsTerminal, Write}, +}; -use ghostty_config::config::Config; -use ghostty_config::theme::{Location, LocationIterator}; -use ghostty_config::{config_enum, config_struct}; +use ghostty_config::{ + config::Config, + config_enum, + config_struct, + theme::{Location, LocationIterator}, +}; -use crate::error::Error; -use crate::tui; +use crate::{error::Error, tui}; pub mod preview; diff --git a/crates/ghostty-cli/src/list_themes/preview.rs b/crates/ghostty-cli/src/list_themes/preview.rs index 402e918..e87e739 100644 --- a/crates/ghostty-cli/src/list_themes/preview.rs +++ b/crates/ghostty-cli/src/list_themes/preview.rs @@ -13,22 +13,32 @@ //! termina cannot parse); it starts as light //! like the Zig code does, but `COLORFGBG` is used as a hint if set. -use std::cell::RefCell; -use std::fmt::Write as _; -use std::io::Write; +use std::{cell::RefCell, fmt::Write as _, io::Write}; -use ghostty_config::config::Config; -use ghostty_config::types_a::TerminalColor; -use ratatui::Frame; -use ratatui::buffer::Buffer; -use ratatui::crossterm::event::{ - Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers, MouseButton, MouseEvent, MouseEventKind, +use ghostty_config::{config::Config, types_a::TerminalColor}; +use ratatui::{ + Frame, + buffer::Buffer, + crossterm::event::{ + Event, + KeyCode, + KeyEvent, + KeyEventKind, + KeyModifiers, + MouseButton, + MouseEvent, + MouseEventKind, + }, + layout::{Position, Rect}, + style::{Color, Modifier, Style}, }; -use ratatui::layout::{Position, Rect}; -use ratatui::style::{Color, Modifier, Style}; use super::{ - ColorScheme, SMALL_LIST_THRESHOLD, ThemeListElement, absolute_path, should_include_theme, + ColorScheme, + SMALL_LIST_THRESHOLD, + ThemeListElement, + absolute_path, + should_include_theme, }; use crate::error::Error; @@ -1667,10 +1677,12 @@ pub fn preview(themes: Vec, theme_filter: ColorScheme) -> Resu } fn run_loop(app: &mut Preview) -> Result<(), Error> { - use ratatui::Terminal as RatTerminal; - use ratatui::backend::CrosstermBackend; - use termina::escape::csi::{Csi, DecPrivateMode, DecPrivateModeCode, Mode}; - use termina::{PlatformTerminal, Terminal as _}; + use ratatui::{Terminal as RatTerminal, backend::CrosstermBackend}; + use termina::{ + PlatformTerminal, + Terminal as _, + escape::csi::{Csi, DecPrivateMode, DecPrivateModeCode, Mode}, + }; let mut tty = PlatformTerminal::new()?; tty.enter_raw_mode()?; @@ -1753,9 +1765,10 @@ fn draw_frame(app: &mut Preview, f: &mut Frame<'_>) -> Option { #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)] - use super::*; use ghostty_config::theme::Location; + use super::*; + fn make_themes(dir: &std::path::Path, names: &[(&str, &str)]) -> Vec { names .iter() diff --git a/crates/ghostty-cli/src/new_window.rs b/crates/ghostty-cli/src/new_window.rs index 35e250d..792e575 100644 --- a/crates/ghostty-cli/src/new_window.rs +++ b/crates/ghostty-cli/src/new_window.rs @@ -237,9 +237,10 @@ pub fn run(args: &[String]) -> Result { #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)] - use super::*; use ghostty_config::cli_args::{VecIterator, parse}; + use super::*; + fn parse_str(s: &str) -> Options { let mut opts = Options::default(); let mut it = VecIterator::from_str_args(s); diff --git a/crates/ghostty-cli/src/show_config.rs b/crates/ghostty-cli/src/show_config.rs index 7544b10..24c32fa 100644 --- a/crates/ghostty-cli/src/show_config.rs +++ b/crates/ghostty-cli/src/show_config.rs @@ -2,9 +2,7 @@ use std::io::Write; -use ghostty_config::config::Config; -use ghostty_config::config_struct; -use ghostty_config::file_formatter::FileFormatter; +use ghostty_config::{config::Config, config_struct, file_formatter::FileFormatter}; use crate::error::Error; diff --git a/crates/ghostty-cli/src/show_face.rs b/crates/ghostty-cli/src/show_face.rs index 05e2b34..2caa5d1 100644 --- a/crates/ghostty-cli/src/show_face.rs +++ b/crates/ghostty-cli/src/show_face.rs @@ -1,13 +1,19 @@ //! `+show-face` (ZIG/src/cli/show_face.zig). -use ghostty_config::config::Config; -use ghostty_config::diagnostics::Location; -use ghostty_config::{config_enum, config_struct, diagnostics::DiagnosticList}; -use ghostty_font::collection::EntryError; -use ghostty_font::collection::GetFaceError; -use ghostty_font::face::DesiredSize; -use ghostty_font::shared_grid_set::DerivedConfig; -use ghostty_font::{self as font, SharedGrid, SharedGridSet}; +use ghostty_config::{ + config::Config, + config_enum, + config_struct, + diagnostics::{DiagnosticList, Location}, +}; +use ghostty_font::{ + self as font, + SharedGrid, + SharedGridSet, + collection::{EntryError, GetFaceError}, + face::DesiredSize, + shared_grid_set::DerivedConfig, +}; use crate::error::Error; diff --git a/crates/ghostty-cli/src/ssh_cache/disk_cache.rs b/crates/ghostty-cli/src/ssh_cache/disk_cache.rs index 6891e70..a18d778 100644 --- a/crates/ghostty-cli/src/ssh_cache/disk_cache.rs +++ b/crates/ghostty-cli/src/ssh_cache/disk_cache.rs @@ -2,12 +2,14 @@ //! (ZIG/src/cli/ssh-cache/DiskCache.zig). The cache only stores metadata //! (hostname, terminfo value, etc.) and does not store any sensitive data. -use std::collections::BTreeMap; -use std::fs::{File, OpenOptions}; -use std::io::{Read, Write}; -use std::net::Ipv6Addr; -use std::os::unix::fs::{OpenOptionsExt, PermissionsExt}; -use std::path::PathBuf; +use std::{ + collections::BTreeMap, + fs::{File, OpenOptions}, + io::{Read, Write}, + net::Ipv6Addr, + os::unix::fs::{OpenOptionsExt, PermissionsExt}, + path::PathBuf, +}; use super::entry::{Entry, now_timestamp}; diff --git a/crates/ghostty-cli/src/ssh_cache/entry.rs b/crates/ghostty-cli/src/ssh_cache/entry.rs index a777e96..b23c3e2 100644 --- a/crates/ghostty-cli/src/ssh_cache/entry.rs +++ b/crates/ghostty-cli/src/ssh_cache/entry.rs @@ -2,8 +2,10 @@ //! Our SSH entry cache stores which hosts we've sent our terminfo to so that //! we don't have to send it again. It doesn't store any sensitive information. -use std::fmt::Write as _; -use std::time::{SystemTime, UNIX_EPOCH}; +use std::{ + fmt::Write as _, + time::{SystemTime, UNIX_EPOCH}, +}; const S_PER_DAY: i64 = 86_400; diff --git a/crates/ghostty-cli/src/validate_config.rs b/crates/ghostty-cli/src/validate_config.rs index b015250..f8d0fcc 100644 --- a/crates/ghostty-cli/src/validate_config.rs +++ b/crates/ghostty-cli/src/validate_config.rs @@ -2,8 +2,7 @@ use std::io::Write; -use ghostty_config::config::Config; -use ghostty_config::config_struct; +use ghostty_config::{config::Config, config_struct}; use crate::error::Error; diff --git a/crates/ghostty-cli/src/version.rs b/crates/ghostty-cli/src/version.rs index 02beed8..ddbd0fb 100644 --- a/crates/ghostty-cli/src/version.rs +++ b/crates/ghostty-cli/src/version.rs @@ -2,8 +2,10 @@ use std::io::{IsTerminal, Write}; -use crate::build_info::{self, BuildInfo}; -use crate::error::Error; +use crate::{ + build_info::{self, BuildInfo}, + error::Error, +}; /// The `version` command is used to display information about Ghostty. Recognized as /// either `+version` or `--version`. diff --git a/crates/ghostty-config/src/cli_args.rs b/crates/ghostty-config/src/cli_args.rs index 621a1bc..824752d 100644 --- a/crates/ghostty-config/src/cli_args.rs +++ b/crates/ghostty-config/src/cli_args.rs @@ -12,11 +12,13 @@ //! to a field and optionally provides diagnostics, compatibility handlers, //! a manual-parse hook and a `--help` hook. -use crate::comma_splitter::CommaSplitter; -use crate::diagnostics::{Diagnostic, DiagnosticList, Location}; -use crate::formatter::EntryFormatter; -use std::fmt; -use std::io::BufRead; +use std::{fmt, io::BufRead}; + +use crate::{ + comma_splitter::CommaSplitter, + diagnostics::{Diagnostic, DiagnosticList, Location}, + formatter::EntryFormatter, +}; /// For trimming pub const WHITESPACE: &str = " \t"; @@ -779,9 +781,10 @@ impl ArgIter for LineIterator { #[cfg(test)] #[allow(clippy::unwrap_used)] mod tests { + use std::io::Cursor; + use super::*; use crate::{config_enum, config_packed, config_struct}; - use std::io::Cursor; fn parse_str(dst: &mut T, s: &str) -> Result<(), ArgError> { let mut it = VecIterator::from_str_args(s); diff --git a/crates/ghostty-config/src/command.rs b/crates/ghostty-config/src/command.rs index 30b495b..d5fc252 100644 --- a/crates/ghostty-config/src/command.rs +++ b/crates/ghostty-config/src/command.rs @@ -1,9 +1,12 @@ //! A command to execute (port of `config/command.zig`). -use crate::cli_args::{ArgError, ConfigField}; -use crate::formatter::EntryFormatter; use std::fmt; +use crate::{ + cli_args::{ArgError, ConfigField}, + formatter::EntryFormatter, +}; + /// A command to execute (argv0 and args). /// /// A command is specified as a simple string such as "nvim a b c". diff --git a/crates/ghostty-config/src/config.rs b/crates/ghostty-config/src/config.rs index 06c6188..995e9d6 100644 --- a/crates/ghostty-config/src/config.rs +++ b/crates/ghostty-config/src/config.rs @@ -4,22 +4,25 @@ //! invocation below with its exact name, type, default value and doc comment. //! The doc comments are user-visible (`ghostty +show-config --docs`). -use crate::cli_args::{self, ArgError, ArgIter, CliTarget}; -use crate::command::Command; -use crate::conditional::{self, Conditional}; -use crate::config_enum; -use crate::diagnostics::{Diagnostic, DiagnosticList}; -use crate::io::RepeatableReadableIO; -use crate::key::Key; -use crate::keybinds::Keybinds; -use crate::macros::ConfigStruct; -use crate::metric_modifier::MetricModifier; -use crate::path::{Path, RepeatablePath}; -use crate::repeatable_string_map::RepeatableStringMap; -use crate::types_a::*; -use crate::types_b::*; use std::collections::HashSet; +use crate::{ + cli_args::{self, ArgError, ArgIter, CliTarget}, + command::Command, + conditional::{self, Conditional}, + config_enum, + diagnostics::{Diagnostic, DiagnosticList}, + io::RepeatableReadableIO, + key::Key, + keybinds::Keybinds, + macros::ConfigStruct, + metric_modifier::MetricModifier, + path::{Path, RepeatablePath}, + repeatable_string_map::RepeatableStringMap, + types_a::*, + types_b::*, +}; + const NS_PER_S: u64 = 1_000_000_000; const NS_PER_MS: u64 = 1_000_000; @@ -4820,10 +4823,12 @@ impl CliTarget for Config { clippy::assert_is_empty )] mod tests { + use std::io::Cursor; + + use ghostty_os::TempDir; + use super::*; use crate::cli_args::VecIterator; - use ghostty_os::TempDir; - use std::io::Cursor; fn it(args: &[&str]) -> VecIterator { VecIterator::new(args.iter().map(|s| (*s).to_string()).collect()) diff --git a/crates/ghostty-config/src/edit.rs b/crates/ghostty-config/src/edit.rs index 9317b14..47d28d5 100644 --- a/crates/ghostty-config/src/edit.rs +++ b/crates/ghostty-config/src/edit.rs @@ -1,9 +1,8 @@ //! Opening the config for editing (port of `config/edit.zig`). +use std::{fs::OpenOptions, io, path::Path}; + use crate::file_load; -use std::fs::OpenOptions; -use std::io; -use std::path::Path; /// The path to the configuration that should be opened for editing. /// diff --git a/crates/ghostty-config/src/file_formatter.rs b/crates/ghostty-config/src/file_formatter.rs index fd30f8a..76371a5 100644 --- a/crates/ghostty-config/src/file_formatter.rs +++ b/crates/ghostty-config/src/file_formatter.rs @@ -1,11 +1,14 @@ //! `FileFormatter` (part of `config/formatter.zig`): outputs the config in a //! file-like format, identical to Ghostty's `+show-config`. -use crate::config::Config; -use crate::key::Key; -use crate::macros::{ConfigStruct, help_string}; use std::fmt; +use crate::{ + config::Config, + key::Key, + macros::{ConfigStruct, help_string}, +}; + /// FileFormatter is a formatter implementation that outputs the /// config in a file-like format. This uses more generous whitespace, /// can include comments, etc. diff --git a/crates/ghostty-config/src/file_load.rs b/crates/ghostty-config/src/file_load.rs index 8fee51f..6844e72 100644 --- a/crates/ghostty-config/src/file_load.rs +++ b/crates/ghostty-config/src/file_load.rs @@ -2,9 +2,10 @@ //! //! macOS Application Support paths are not supported (Linux only). -use ghostty_os::xdg; use std::fs::File; +use ghostty_os::xdg; + /// Default path for the XDG home configuration file. pub fn default_xdg_path() -> Result { xdg::config(&xdg::Options { diff --git a/crates/ghostty-config/src/formatter.rs b/crates/ghostty-config/src/formatter.rs index 36e35e0..cd9f007 100644 --- a/crates/ghostty-config/src/formatter.rs +++ b/crates/ghostty-config/src/formatter.rs @@ -1,9 +1,10 @@ //! Config formatting (port of `config/formatter.zig`). Output matches //! Ghostty's `+show-config`. -use crate::cli_args::ConfigField; use std::fmt; +use crate::cli_args::ConfigField; + /// A single entry formatter for the given field name and writer. pub struct EntryFormatter<'a> { pub name: &'a str, diff --git a/crates/ghostty-config/src/input_fields.rs b/crates/ghostty-config/src/input_fields.rs index 9c2d650..2c8e0af 100644 --- a/crates/ghostty-config/src/input_fields.rs +++ b/crates/ghostty-config/src/input_fields.rs @@ -1,11 +1,15 @@ //! `ConfigField` implementations for types owned by `ghostty-input` //! (the input crate cannot depend on the config crate). -use crate::cli_args::{ArgError, ConfigField}; -use crate::formatter::EntryFormatter; -use ghostty_input::{KeyRemapSet, OptionAsAlt}; use std::fmt; +use ghostty_input::{KeyRemapSet, OptionAsAlt}; + +use crate::{ + cli_args::{ArgError, ConfigField}, + formatter::EntryFormatter, +}; + impl ConfigField for KeyRemapSet { fn parse_cli(&mut self, value: Option<&str>) -> Result<(), ArgError> { self.parse_cli(value).map_err(|_| ArgError::InvalidValue) diff --git a/crates/ghostty-config/src/io.rs b/crates/ghostty-config/src/io.rs index 160015d..11c33ab 100644 --- a/crates/ghostty-config/src/io.rs +++ b/crates/ghostty-config/src/io.rs @@ -1,10 +1,13 @@ //! Readable IO config values (port of `config/io.zig`). -use crate::cli_args::{ArgError, ConfigField, split_tagged_union}; -use crate::formatter::EntryFormatter; -use crate::string; use std::fmt; +use crate::{ + cli_args::{ArgError, ConfigField, split_tagged_union}, + formatter::EntryFormatter, + string, +}; + /// ReadableIO is some kind of IO source that is readable. /// /// It can be either a direct string or a filepath. The filepath will diff --git a/crates/ghostty-config/src/keybinds.rs b/crates/ghostty-config/src/keybinds.rs index c979ce8..d510365 100644 --- a/crates/ghostty-config/src/keybinds.rs +++ b/crates/ghostty-config/src/keybinds.rs @@ -1,17 +1,35 @@ //! Keybinds (port of `Config.Keybinds` from `config/Config.zig`). -use crate::cli_args::{ArgError, ConfigField}; -use crate::formatter::EntryFormatter; -use ghostty_input::binding::set::EntryFormatter as BindingEntryFormatter; -use ghostty_input::binding::set::Value; -use ghostty_input::binding::{ - Action, AdjustSelection, CloseTabMode, CopyToClipboard, Flags, InspectorMode, Set, - SplitDirection, SplitFocusDirection, SplitResizeDirection, SplitResizeParameter, Trigger, - TriggerKey, WriteScreen, -}; -use ghostty_input::{Key, Mods, ctrl_or_super}; use std::fmt; +use ghostty_input::{ + Key, + Mods, + binding::{ + Action, + AdjustSelection, + CloseTabMode, + CopyToClipboard, + Flags, + InspectorMode, + Set, + SplitDirection, + SplitFocusDirection, + SplitResizeDirection, + SplitResizeParameter, + Trigger, + TriggerKey, + WriteScreen, + set::{EntryFormatter as BindingEntryFormatter, Value}, + }, + ctrl_or_super, +}; + +use crate::{ + cli_args::{ArgError, ConfigField}, + formatter::EntryFormatter, +}; + /// The most recent binding target for `chain=` additions. /// /// This is intentionally tracked at the Keybinds level so that chains can diff --git a/crates/ghostty-config/src/metric_modifier.rs b/crates/ghostty-config/src/metric_modifier.rs index 3b1fbc8..7e8bc1a 100644 --- a/crates/ghostty-config/src/metric_modifier.rs +++ b/crates/ghostty-config/src/metric_modifier.rs @@ -3,10 +3,13 @@ //! The font crate depends on this crate (not the other way around), so the //! modifier type used by the `adjust-*` config options lives here. -use crate::cli_args::{ArgError, ConfigField}; -use crate::formatter::EntryFormatter; use std::fmt; +use crate::{ + cli_args::{ArgError, ConfigField}, + formatter::EntryFormatter, +}; + /// A modifier to apply to a metrics value. The modifier value represents /// a delta, so percent is a percentage to change, not a percentage of. /// For example, "20%" is 20% larger, not 20% of the value. Likewise, diff --git a/crates/ghostty-config/src/path.rs b/crates/ghostty-config/src/path.rs index 5321fa4..b780038 100644 --- a/crates/ghostty-config/src/path.rs +++ b/crates/ghostty-config/src/path.rs @@ -1,10 +1,15 @@ //! Path config values (port of `config/path.zig`). -use crate::cli_args::{ArgError, ConfigField}; -use crate::diagnostics::{Diagnostic, DiagnosticList}; -use crate::formatter::EntryFormatter; -use std::fmt; -use std::path::{Component, Path as StdPath, PathBuf}; +use std::{ + fmt, + path::{Component, Path as StdPath, PathBuf}, +}; + +use crate::{ + cli_args::{ArgError, ConfigField}, + diagnostics::{Diagnostic, DiagnosticList}, + formatter::EntryFormatter, +}; /// Path is like a string that represents a path value. The difference is that /// when loading the configuration the value for this will be automatically diff --git a/crates/ghostty-config/src/repeatable_string_map.rs b/crates/ghostty-config/src/repeatable_string_map.rs index 1a50495..97d4dab 100644 --- a/crates/ghostty-config/src/repeatable_string_map.rs +++ b/crates/ghostty-config/src/repeatable_string_map.rs @@ -2,10 +2,13 @@ //! string map. This isn't called "StringMap" because I find that sometimes //! leads to confusion that it _accepts_ a map such as JSON dict. -use crate::cli_args::{ArgError, ConfigField}; -use crate::formatter::EntryFormatter; use std::fmt; +use crate::{ + cli_args::{ArgError, ConfigField}, + formatter::EntryFormatter, +}; + /// std.ascii.whitespace fn is_ascii_ws(c: char) -> bool { matches!(c, ' ' | '\t' | '\n' | '\r' | '\x0b' | '\x0c') diff --git a/crates/ghostty-config/src/theme.rs b/crates/ghostty-config/src/theme.rs index 423cdff..f8af430 100644 --- a/crates/ghostty-config/src/theme.rs +++ b/crates/ghostty-config/src/theme.rs @@ -3,9 +3,9 @@ //! Zig reads the resources dir from global state; here it is passed //! explicitly (`resources_dir`, the value of `ResourcesDir.app()`). +use std::{fs::File, path::Path}; + use crate::diagnostics::{Diagnostic, DiagnosticList}; -use std::fs::File; -use std::path::Path; /// Location of possible themes. The order of this enum matters because it /// defines the priority of theme search (from top to bottom). diff --git a/crates/ghostty-config/src/types_a.rs b/crates/ghostty-config/src/types_a.rs index aad4d54..bbde9c6 100644 --- a/crates/ghostty-config/src/types_a.rs +++ b/crates/ghostty-config/src/types_a.rs @@ -2,14 +2,19 @@ //! enums, working directory, colors, palette, repeatable strings, word //! chars, font variation / codepoint maps, font style, links. -use crate::cli_args::{ArgError, ConfigField, parse_int_base0, trim_ws}; -use crate::clipboard_codepoint_map::{ClipboardCodepointMap, Entry as ClipboardEntry, Replacement}; -use crate::font_types::{CodepointMap, CodepointMapEntry, Descriptor, Variation, VariationId}; -use crate::formatter::EntryFormatter; -use crate::{config_enum, config_packed}; -use ghostty_vt::color::{DEFAULT as DEFAULT_PALETTE, Palette as TermPalette, PaletteMask, Rgb}; use std::fmt; +use ghostty_vt::color::{DEFAULT as DEFAULT_PALETTE, Palette as TermPalette, PaletteMask, Rgb}; + +use crate::{ + cli_args::{ArgError, ConfigField, parse_int_base0, trim_ws}, + clipboard_codepoint_map::{ClipboardCodepointMap, Entry as ClipboardEntry, Replacement}, + config_enum, + config_packed, + font_types::{CodepointMap, CodepointMapEntry, Descriptor, Variation, VariationId}, + formatter::EntryFormatter, +}; + /// Write `name = value\n` for a string-ish value. fn write_str(f: &mut EntryFormatter<'_>, value: &str) -> fmt::Result { writeln!(f.writer, "{} = {}", f.name, value) diff --git a/crates/ghostty-config/src/types_b.rs b/crates/ghostty-config/src/types_b.rs index f30a69d..ae93ac3 100644 --- a/crates/ghostty-config/src/types_b.rs +++ b/crates/ghostty-config/src/types_b.rs @@ -3,12 +3,17 @@ #![allow(clippy::format_push_string, clippy::single_match_else)] -use crate::cli_args::{ArgError, ConfigField, parse_auto_struct_with, parse_bool, trim_ws}; -use crate::formatter::EntryFormatter; -use crate::{config_enum, config_packed}; -use ghostty_input::binding::Action; use std::fmt; +use ghostty_input::binding::Action; + +use crate::{ + cli_args::{ArgError, ConfigField, parse_auto_struct_with, parse_bool, trim_ws}, + config_enum, + config_packed, + formatter::EntryFormatter, +}; + /// Write `name = \n` (Zig: `formatEntry([]const u8, s)`). fn fmt_str(f: &mut EntryFormatter<'_>, s: &str) -> fmt::Result { writeln!(f.writer, "{} = {}", f.name, s) diff --git a/crates/ghostty-config/src/url.rs b/crates/ghostty-config/src/url.rs index 37d330f..f10968a 100644 --- a/crates/ghostty-config/src/url.rs +++ b/crates/ghostty-config/src/url.rs @@ -116,9 +116,10 @@ pub const REGEX: &str = concatcp!( #[cfg(test)] #[allow(clippy::unwrap_used)] mod tests { - use super::*; use onig::Regex; + use super::*; + #[test] fn url_regex() { let re = Regex::new(REGEX).unwrap(); diff --git a/crates/ghostty-core/src/app.rs b/crates/ghostty-core/src/app.rs index 381e4a8..2737244 100644 --- a/crates/ghostty-core/src/app.rs +++ b/crates/ghostty-core/src/app.rs @@ -11,26 +11,38 @@ //! app keeps weak references to them (the runtime owns the strong //! `Rc`). -use std::cell::{Cell, RefCell}; -use std::rc::{Rc, Weak}; -use std::sync::Arc; -use std::time::Instant; +use std::{ + cell::{Cell, RefCell}, + rc::{Rc, Weak}, + sync::Arc, + time::Instant, +}; use crossbeam_channel::{Receiver, Sender, TrySendError}; -use ghostty_apprt::action::{Action as RtAction, QuitTimer, ReloadConfig, Target}; -use ghostty_apprt::runtime_api::{ - AppMessage, CellSize as RtCellSize, CoreApp, CoreError, CoreSurface, DesiredFontSize, RtApp, - RtSurface, SurfaceId, Waker, +use ghostty_apprt::{ + action::{Action as RtAction, QuitTimer, ReloadConfig, Target}, + runtime_api::{ + AppMessage, + CellSize as RtCellSize, + CoreApp, + CoreError, + CoreSurface, + DesiredFontSize, + RtApp, + RtSurface, + SurfaceId, + Waker, + }, + structs::ColorScheme, + surface::{AppMailbox, Message as SurfaceMessage}, }; -use ghostty_apprt::structs::ColorScheme; -use ghostty_apprt::surface::{AppMailbox, Message as SurfaceMessage}; -use ghostty_config::conditional; -use ghostty_config::config::Config; +use ghostty_config::{conditional, config::Config}; use ghostty_datastruct::blocking_queue::Timeout; use ghostty_font::SharedGridSet; -use ghostty_input::KeyEvent; -use ghostty_input::binding::set::Value as BindingValue; -use ghostty_input::binding::{Action as BindingAction, Scope}; +use ghostty_input::{ + KeyEvent, + binding::{Action as BindingAction, Scope, set::Value as BindingValue}, +}; use crate::surface::Surface; diff --git a/crates/ghostty-core/src/global.rs b/crates/ghostty-core/src/global.rs index 822cb3a..55e59e1 100644 --- a/crates/ghostty-core/src/global.rs +++ b/crates/ghostty-core/src/global.rs @@ -5,11 +5,9 @@ //! the root binary before this is initialized, so what remains is: logging, //! signal setup, rlimits and the resources directory. -use std::io::Write as _; -use std::sync::OnceLock; +use std::{io::Write as _, sync::OnceLock}; -use ghostty_os::file::Rlimit; -use ghostty_os::resourcesdir::ResourcesDir; +use ghostty_os::{file::Rlimit, resourcesdir::ResourcesDir}; /// Where logging should go (Zig: `GlobalState.Logging`, a packed struct /// parsed from `GHOSTTY_LOG`). diff --git a/crates/ghostty-core/src/surface/binding.rs b/crates/ghostty-core/src/surface/binding.rs index 12a6491..39c146b 100644 --- a/crates/ghostty-core/src/surface/binding.rs +++ b/crates/ghostty-core/src/surface/binding.rs @@ -2,42 +2,78 @@ //! `Search`, `searchCallback`, `dumpText`, `performBindingAction`, //! `closingAction`, `writeScreenFile`). -use std::io::Write as _; -use std::sync::Arc; -use std::thread::JoinHandle; +use std::{io::Write as _, sync::Arc, thread::JoinHandle}; -use ghostty_apprt::action::{ - Action as RtAction, CloseTabMode as RtCloseTabMode, FloatWindow, Fullscreen, - GotoSplit as RtGotoSplit, GotoTab, GotoWindow as RtGotoWindow, Inspector as RtInspector, - KeyTable, MoveTab, OpenUrl, OpenUrlKind, PromptTitle, Readonly, ReloadConfig, - ResizeSplit as RtResizeSplit, ResizeSplitDirection, SecureInput, SetTitle, - SplitDirection as RtSplit, StartSearch, Target, +use ghostty_apprt::{ + action::{ + Action as RtAction, + CloseTabMode as RtCloseTabMode, + FloatWindow, + Fullscreen, + GotoSplit as RtGotoSplit, + GotoTab, + GotoWindow as RtGotoWindow, + Inspector as RtInspector, + KeyTable, + MoveTab, + OpenUrl, + OpenUrlKind, + PromptTitle, + Readonly, + ReloadConfig, + ResizeSplit as RtResizeSplit, + ResizeSplitDirection, + SecureInput, + SetTitle, + SplitDirection as RtSplit, + StartSearch, + Target, + }, + runtime_api::{CoreError, RtApp, SurfaceId}, + structs::{Clipboard, ClipboardRequest}, + surface::Message as SurfaceMessage, }; -use ghostty_apprt::runtime_api::{CoreError, RtApp, SurfaceId}; -use ghostty_apprt::structs::{Clipboard, ClipboardRequest}; -use ghostty_apprt::surface::Message as SurfaceMessage; use ghostty_config::types_a::NonNativeFullscreen; use ghostty_datastruct::blocking_queue::Timeout; use ghostty_input::binding::{ - Action, AdjustSelection, CloseTabMode, CrashThread, InspectorMode, NavigateSearch, Scope, - SplitDirection, SplitFocusDirection, SplitResizeDirection, WriteScreen, WriteScreenAction, + Action, + AdjustSelection, + CloseTabMode, + CrashThread, + InspectorMode, + NavigateSearch, + Scope, + SplitDirection, + SplitFocusDirection, + SplitResizeDirection, + WriteScreen, + WriteScreenAction, WriteScreenFormat, }; -use ghostty_renderer::message::Message as RendererMessage; -use ghostty_renderer::state::SharedState; -use ghostty_renderer::thread::Handle as RendererHandle; -use ghostty_terminal::formatter::{self, Content, Format, ScreenFormatter}; -use ghostty_terminal::point::Tag; -use ghostty_terminal::screen::Scroll; -use ghostty_terminal::search::screen::Select; -use ghostty_terminal::search::thread::{ - Event, Message as SearchMessage, Options as SearchOptions, TerminalLock, TerminalRef, - Thread as SearchThread, +use ghostty_renderer::{ + message::Message as RendererMessage, + state::SharedState, + thread::Handle as RendererHandle, }; -use ghostty_terminal::selection::{Adjustment, Order, Selection}; -use ghostty_terminal::terminal::{ScrollViewport, Terminal}; -use ghostty_termio::message::Message as IoMessage; -use ghostty_termio::{SharedStateExt, TerminalGuard}; +use ghostty_terminal::{ + formatter::{self, Content, Format, ScreenFormatter}, + point::Tag, + screen::Scroll, + search::{ + screen::Select, + thread::{ + Event, + Message as SearchMessage, + Options as SearchOptions, + TerminalLock, + TerminalRef, + Thread as SearchThread, + }, + }, + selection::{Adjustment, Order, Selection}, + terminal::{ScrollViewport, Terminal}, +}; +use ghostty_termio::{SharedStateExt, TerminalGuard, message::Message as IoMessage}; use super::Surface; use crate::app::Mailbox as AppMailbox; @@ -1172,9 +1208,10 @@ impl Surface { #[cfg(test)] mod tests { - use super::*; use ghostty_terminal::terminal::Options; + use super::*; + fn term(cols: u16, rows: u16) -> Terminal { Terminal::new(Options::new(cols, rows)).unwrap() } diff --git a/crates/ghostty-core/src/surface/clipboard.rs b/crates/ghostty-core/src/surface/clipboard.rs index 95127f5..38687d0 100644 --- a/crates/ghostty-core/src/surface/clipboard.rs +++ b/crates/ghostty-core/src/surface/clipboard.rs @@ -2,27 +2,30 @@ //! `copySelectionToClipboards`, clipboard requests, paste, OSC 52 and //! desktop notifications). -use std::hash::{Hash, Hasher}; -use std::rc::Rc; -use std::sync::Arc; -use std::time::{Duration, Instant}; +use std::{ + hash::{Hash, Hasher}, + rc::Rc, + sync::Arc, + time::{Duration, Instant}, +}; -use base64::Engine as _; -use base64::engine::general_purpose::STANDARD; -use ghostty_apprt::action::{Action as RtAction, DesktopNotification}; -use ghostty_apprt::runtime_api::ClipboardError; -use ghostty_apprt::structs::{Clipboard, ClipboardRequest}; +use base64::{Engine as _, engine::general_purpose::STANDARD}; +use ghostty_apprt::{ + action::{Action as RtAction, DesktopNotification}, + runtime_api::ClipboardError, + structs::{Clipboard, ClipboardRequest}, +}; use ghostty_config::types_b::ClipboardAccess; -use ghostty_input::binding::CopyToClipboard; -use ghostty_input::paste; -use ghostty_terminal::formatter::{self, Format, ScreenFormatter}; -use ghostty_terminal::selection::Selection; -use ghostty_terminal::terminal::Terminal; +use ghostty_input::{binding::CopyToClipboard, paste}; +use ghostty_terminal::{ + formatter::{self, Format, ScreenFormatter}, + selection::Selection, + terminal::Terminal, +}; use ghostty_termio::message::Message as IoMessage; use ghostty_vt::modes::Mode; -use super::Surface; -use super::config::DerivedConfig; +use super::{Surface, config::DerivedConfig}; /// `input.paste.Options.fromTerminal`. #[must_use] diff --git a/crates/ghostty-core/src/surface/config.rs b/crates/ghostty-core/src/surface/config.rs index 6475173..695998c 100644 --- a/crates/ghostty-core/src/surface/config.rs +++ b/crates/ghostty-core/src/surface/config.rs @@ -6,14 +6,12 @@ //! it so the fields keep their Zig names (`cfg.copy_on_select`, ...). The //! few values that are *computed* in Zig live as fields of this struct. -use std::ops::Deref; -use std::sync::Arc; +use std::{ops::Deref, sync::Arc}; use ghostty_config::config::Config; use ghostty_input::link::{Action as LinkAction, Highlight}; -use onig::Regex; - use ghostty_renderer::size::Padding; +use onig::Regex; /// A link with its compiled regex (Zig: `DerivedConfig.Link`). pub struct Link { diff --git a/crates/ghostty-core/src/surface/inspector.rs b/crates/ghostty-core/src/surface/inspector.rs index 40a4b1d..f75717c 100644 --- a/crates/ghostty-core/src/surface/inspector.rs +++ b/crates/ghostty-core/src/surface/inspector.rs @@ -5,11 +5,8 @@ use std::sync::Arc; use ghostty_apprt::runtime_api::CoreError; -use ghostty_inspector::Shared as Inspector; -use ghostty_inspector::imgui::Ui; -use ghostty_inspector::widgets::surface::SurfaceInfo; -use ghostty_renderer::message::Message as RendererMessage; -use ghostty_renderer::state::InspectorHook; +use ghostty_inspector::{Shared as Inspector, imgui::Ui, widgets::surface::SurfaceInfo}; +use ghostty_renderer::{message::Message as RendererMessage, state::InspectorHook}; use ghostty_termio::message::Message as IoMessage; use super::Surface; diff --git a/crates/ghostty-core/src/surface/keyboard.rs b/crates/ghostty-core/src/surface/keyboard.rs index f1cb158..980eb77 100644 --- a/crates/ghostty-core/src/surface/keyboard.rs +++ b/crates/ghostty-core/src/surface/keyboard.rs @@ -11,20 +11,24 @@ //! time. A config change drops them anyway (`update_config` calls //! [`Surface::end_key_sequence`] and [`Surface::deactivate_all_key_tables`]). -use ghostty_apprt::action::{Action as RtAction, KeySequence, KeyTable}; -use ghostty_apprt::runtime_api::{CoreError, InputEffect}; -use ghostty_input::binding::set::Value; -use ghostty_input::binding::{Action as BindingAction, Flags, Scope, Set, Trigger, TriggerKey}; -use ghostty_input::key_encode; -use ghostty_input::{Action as KeyAction, Key, KeyEvent, Mods}; +use ghostty_apprt::{ + action::{Action as RtAction, KeySequence, KeyTable}, + runtime_api::{CoreError, InputEffect}, +}; +use ghostty_input::{ + Action as KeyAction, + Key, + KeyEvent, + Mods, + binding::{Action as BindingAction, Flags, Scope, Set, Trigger, TriggerKey, set::Value}, + key_encode, +}; use ghostty_inspector as inspector; use ghostty_terminal::terminal::{MouseEvents, ScrollViewport, Terminal}; use ghostty_termio::message::Message as IoMessage; -use ghostty_vt::modes::Mode; -use ghostty_vt::mouse_shape::MouseShape; +use ghostty_vt::{modes::Mode, mouse_shape::MouseShape}; -use super::Surface; -use super::config::DerivedConfig; +use super::{Surface, config::DerivedConfig}; /// The maximum number of key tables that can be active at any given time. /// `activate_key_table` calls after this are ignored. @@ -1017,11 +1021,11 @@ impl Surface { #[cfg(test)] #[allow(clippy::unwrap_used)] mod tests { - use super::*; - use ghostty_config::cli_args::ConfigField; - use ghostty_config::config::Config; + use ghostty_config::{cli_args::ConfigField, config::Config}; use ghostty_terminal::terminal::Options; + use super::*; + fn cfg_with(binds: &[&str]) -> DerivedConfig { let mut c = Config::default(); for b in binds { diff --git a/crates/ghostty-core/src/surface/mod.rs b/crates/ghostty-core/src/surface/mod.rs index eeff940..7662959 100644 --- a/crates/ghostty-core/src/surface/mod.rs +++ b/crates/ghostty-core/src/surface/mod.rs @@ -41,55 +41,90 @@ pub mod inspector; pub mod keyboard; pub mod mouse; -use std::cell::{Cell, RefCell}; -use std::rc::Rc; -use std::sync::Arc; -use std::thread::JoinHandle; -use std::time::{Duration as StdDuration, Instant}; - -use ghostty_apprt::action::{ - Action as RtAction, CellSize as ActionCellSize, ColorChange, ColorKind, CommandFinished, - ConfigChange, InitialSize, MouseVisibility, Pwd, ReloadConfig, SecureInput, SetTitle, - SizeLimit, Target, -}; -use ghostty_apprt::runtime_api::{ - ClipboardError, CoreError, CoreSurface, DesiredFontSize, InputEffect, RtApp, RtSurface, - SurfaceId, -}; -use ghostty_apprt::structs::{ - ClipboardRequest, ColorScheme, ContentScale, CursorPos, ImePos, SurfaceSize, -}; -use ghostty_apprt::surface::{Mailbox as SurfaceMailboxImpl, Message}; -use ghostty_config::conditional; -use ghostty_config::config::Config; -use ghostty_config::types_a::ConfirmCloseSurface; -use ghostty_datastruct::blocking_queue::Timeout; -use ghostty_font::face::DesiredSize; -use ghostty_font::metrics::Metrics; -use ghostty_font::shared_grid_set::{DerivedConfig as FontDerivedConfig, Key as FontGridKey}; -use ghostty_input::{Mods, MouseButton, MouseButtonState, ScrollMods}; -use ghostty_renderer::generic::Host as RendererHost; -use ghostty_renderer::message::{FontGridChange, Message as RendererMessage}; -use ghostty_renderer::opengl::OpenGL; -use ghostty_renderer::options::Options as RendererOptions; -use ghostty_renderer::size::{CellSize, Coordinate, Padding, ScreenSize, Size}; -use ghostty_renderer::state::{Preedit, PreeditCodepoint, State as RenderStateData}; -use ghostty_renderer::thread::{Handle as RendererHandle, Running as RendererRunning}; -use ghostty_renderer::{Health, Renderer}; -use ghostty_terminal::page_list::Scrollbar; -use ghostty_terminal::point::Coordinate as PointCoordinate; -use ghostty_terminal::selection::Selection; -use ghostty_termio::exec; -use ghostty_termio::message::Message as IoMessage; -use ghostty_termio::{ - Backend, DerivedConfig as IoDerivedConfig, Exec, Mailbox as IoMailbox, Options as IoOptions, - RendererMailbox, SharedState, SharedStateExt, TerminalGuard, Termio, Thread as IoThread, - Wakeup, +use std::{ + cell::{Cell, RefCell}, + rc::Rc, + sync::Arc, + thread::JoinHandle, + time::{Duration as StdDuration, Instant}, }; -use crate::app::{AppState, Mailbox, Message as AppMessage}; -use crate::global; use config::DerivedConfig; +use ghostty_apprt::{ + action::{ + Action as RtAction, + CellSize as ActionCellSize, + ColorChange, + ColorKind, + CommandFinished, + ConfigChange, + InitialSize, + MouseVisibility, + Pwd, + ReloadConfig, + SecureInput, + SetTitle, + SizeLimit, + Target, + }, + runtime_api::{ + ClipboardError, + CoreError, + CoreSurface, + DesiredFontSize, + InputEffect, + RtApp, + RtSurface, + SurfaceId, + }, + structs::{ClipboardRequest, ColorScheme, ContentScale, CursorPos, ImePos, SurfaceSize}, + surface::{Mailbox as SurfaceMailboxImpl, Message}, +}; +use ghostty_config::{conditional, config::Config, types_a::ConfirmCloseSurface}; +use ghostty_datastruct::blocking_queue::Timeout; +use ghostty_font::{ + face::DesiredSize, + metrics::Metrics, + shared_grid_set::{DerivedConfig as FontDerivedConfig, Key as FontGridKey}, +}; +use ghostty_input::{Mods, MouseButton, MouseButtonState, ScrollMods}; +use ghostty_renderer::{ + Health, + Renderer, + generic::Host as RendererHost, + message::{FontGridChange, Message as RendererMessage}, + opengl::OpenGL, + options::Options as RendererOptions, + size::{CellSize, Coordinate, Padding, ScreenSize, Size}, + state::{Preedit, PreeditCodepoint, State as RenderStateData}, + thread::{Handle as RendererHandle, Running as RendererRunning}, +}; +use ghostty_terminal::{ + page_list::Scrollbar, + point::Coordinate as PointCoordinate, + selection::Selection, +}; +use ghostty_termio::{ + Backend, + DerivedConfig as IoDerivedConfig, + Exec, + Mailbox as IoMailbox, + Options as IoOptions, + RendererMailbox, + SharedState, + SharedStateExt, + TerminalGuard, + Termio, + Thread as IoThread, + Wakeup, + exec, + message::Message as IoMessage, +}; + +use crate::{ + app::{AppState, Mailbox, Message as AppMessage}, + global, +}; /// Minimum window size in cells (Zig: `min_window_width_cells`). pub const MIN_WINDOW_WIDTH_CELLS: u32 = ghostty_apprt::runtime_api::MIN_WINDOW_WIDTH_CELLS; @@ -793,8 +828,7 @@ impl Surface { Message::ColorChange(change) => { // Notify our apprt, but don't send a mode 2031 DSR report // because VT sequences were used to change the color. - use ghostty_vt::color::Dynamic as D; - use ghostty_vt::osc::color::Target; + use ghostty_vt::{color::Dynamic as D, osc::color::Target}; let kind = match change.target { Target::Palette(v) => ColorKind::Palette(i32::from(v)), Target::Dynamic(dyn_) => match dyn_ { diff --git a/crates/ghostty-core/src/surface/mouse.rs b/crates/ghostty-core/src/surface/mouse.rs index 157d440..2d29a6a 100644 --- a/crates/ghostty-core/src/surface/mouse.rs +++ b/crates/ghostty-core/src/surface/mouse.rs @@ -8,24 +8,40 @@ use std::time::Instant; -use ghostty_apprt::action::{Action as RtAction, MouseOverLink, OpenUrl, OpenUrlKind}; -use ghostty_apprt::runtime_api::CoreError; -use ghostty_apprt::structs::{Clipboard, ClipboardRequest, CursorPos}; -use ghostty_config::types_a::LinkPreviews; -use ghostty_config::types_b::{ - CopyOnSelect, MouseShiftCapture as ConfigShiftCapture, RightClickAction, +use ghostty_apprt::{ + action::{Action as RtAction, MouseOverLink, OpenUrl, OpenUrlKind}, + runtime_api::CoreError, + structs::{Clipboard, ClipboardRequest, CursorPos}, }; -use ghostty_input::link::{Action as LinkAction, Highlight}; -use ghostty_input::{Mods, MouseButton, MouseButtonState, MousePressureStage, ScrollMods}; -use ghostty_renderer::size::{Coordinate as SizeCoordinate, CoordinateTag, Size, SurfaceCoord}; -use ghostty_renderer::state::State as RenderStateData; -use ghostty_terminal::page_list::{Direction, PageList, Pin, TrackedPin}; -use ghostty_terminal::point::{Coordinate as PointCoordinate, Point}; -use ghostty_terminal::screen::{Screen, SelectLine, SelectionString, SemanticClick}; -use ghostty_terminal::screen_set::Key as ScreenKey; -use ghostty_terminal::selection::Selection; -use ghostty_terminal::terminal::{ - MouseEvents, MouseFormat, MouseShiftCapture as TerminalShiftCapture, ScrollViewport, Terminal, +use ghostty_config::{ + types_a::LinkPreviews, + types_b::{CopyOnSelect, MouseShiftCapture as ConfigShiftCapture, RightClickAction}, +}; +use ghostty_input::{ + Mods, + MouseButton, + MouseButtonState, + MousePressureStage, + ScrollMods, + link::{Action as LinkAction, Highlight}, +}; +use ghostty_renderer::{ + size::{Coordinate as SizeCoordinate, CoordinateTag, Size, SurfaceCoord}, + state::State as RenderStateData, +}; +use ghostty_terminal::{ + page_list::{Direction, PageList, Pin, TrackedPin}, + point::{Coordinate as PointCoordinate, Point}, + screen::{Screen, SelectLine, SelectionString, SemanticClick}, + screen_set::Key as ScreenKey, + selection::Selection, + terminal::{ + MouseEvents, + MouseFormat, + MouseShiftCapture as TerminalShiftCapture, + ScrollViewport, + Terminal, + }, }; use ghostty_termio::message::Message as IoMessage; use ghostty_vt::modes::Mode; @@ -2239,10 +2255,11 @@ impl Drop for RenderOnDrop<'_> { #[cfg(test)] mod tests { - use super::*; use ghostty_renderer::size::{CellSize, Padding, ScreenSize}; use ghostty_terminal::screen::Options as ScreenOptions; + use super::*; + /// Our screen size is 10x5 cells that are 10x20 px, with 5px padding on /// all sides. fn test_size() -> Size { diff --git a/crates/ghostty-core/tests/common/mod.rs b/crates/ghostty-core/tests/common/mod.rs index d79364e..0a0fd8f 100644 --- a/crates/ghostty-core/tests/common/mod.rs +++ b/crates/ghostty-core/tests/common/mod.rs @@ -8,24 +8,33 @@ //! answering pending clipboard reads) while polling for conditions. #![allow(dead_code, clippy::unwrap_used, clippy::expect_used)] -use std::cell::{Cell, RefCell}; -use std::collections::{HashMap, VecDeque}; -use std::path::PathBuf; -use std::rc::Rc; -use std::sync::Arc; -use std::sync::atomic::{AtomicU64, Ordering}; -use std::time::{Duration, Instant}; - -use ghostty_apprt::action::{Action, Target}; -use ghostty_apprt::runtime_api::{ - ClipboardError, CoreApp, InputEffect, RtApp, RtSurface, SurfaceId, Waker, +use std::{ + cell::{Cell, RefCell}, + collections::{HashMap, VecDeque}, + path::PathBuf, + rc::Rc, + sync::{ + Arc, + atomic::{AtomicU64, Ordering}, + }, + time::{Duration, Instant}, }; -use ghostty_apprt::structs::{Clipboard, ClipboardRequest, ContentScale, CursorPos, SurfaceSize}; -use ghostty_config::command::Command; -use ghostty_config::config::Config; + +use ghostty_apprt::{ + action::{Action, Target}, + runtime_api::{ClipboardError, CoreApp, InputEffect, RtApp, RtSurface, SurfaceId, Waker}, + structs::{Clipboard, ClipboardRequest, ContentScale, CursorPos, SurfaceSize}, +}; +use ghostty_config::{command::Command, config::Config}; use ghostty_core::{App, Surface}; use ghostty_input::{ - Key, KeyEvent, Mods, MouseButton, MouseButtonState, ScrollMods, key::Action as KeyAction, + Key, + KeyEvent, + Mods, + MouseButton, + MouseButtonState, + ScrollMods, + key::Action as KeyAction, }; use ghostty_renderer::headless::Headless; diff --git a/crates/ghostty-core/tests/e2e_bindings.rs b/crates/ghostty-core/tests/e2e_bindings.rs index 348628a..a18a707 100644 --- a/crates/ghostty-core/tests/e2e_bindings.rs +++ b/crates/ghostty-core/tests/e2e_bindings.rs @@ -6,8 +6,10 @@ use std::fmt::Write as _; mod common; use common::*; -use ghostty_apprt::action::{Action, GotoSplit, SplitDirection}; -use ghostty_apprt::structs::Clipboard; +use ghostty_apprt::{ + action::{Action, GotoSplit, SplitDirection}, + structs::Clipboard, +}; use ghostty_input::Key; #[test] diff --git a/crates/ghostty-core/tests/e2e_mouse.rs b/crates/ghostty-core/tests/e2e_mouse.rs index dd610fd..6c99144 100644 --- a/crates/ghostty-core/tests/e2e_mouse.rs +++ b/crates/ghostty-core/tests/e2e_mouse.rs @@ -5,8 +5,7 @@ mod common; use common::*; -use ghostty_apprt::action::Action; -use ghostty_apprt::structs::Clipboard; +use ghostty_apprt::{action::Action, structs::Clipboard}; use ghostty_input::{Key, MouseButton}; const L: MouseButton = MouseButton::Left; diff --git a/crates/ghostty-core/tests/e2e_term.rs b/crates/ghostty-core/tests/e2e_term.rs index eba0caf..3c948a9 100644 --- a/crates/ghostty-core/tests/e2e_term.rs +++ b/crates/ghostty-core/tests/e2e_term.rs @@ -5,8 +5,10 @@ mod common; use common::*; -use ghostty_apprt::action::Action; -use ghostty_apprt::structs::{Clipboard, SurfaceSize}; +use ghostty_apprt::{ + action::Action, + structs::{Clipboard, SurfaceSize}, +}; use ghostty_input::Key; use ghostty_vt::osc::ProgressState; diff --git a/crates/ghostty-datastruct/src/blocking_queue.rs b/crates/ghostty-datastruct/src/blocking_queue.rs index 091db53..c3840ad 100644 --- a/crates/ghostty-datastruct/src/blocking_queue.rs +++ b/crates/ghostty-datastruct/src/blocking_queue.rs @@ -1,9 +1,11 @@ //! Blocking queue implementation aimed primarily for message passing //! between threads (`blocking_queue.zig`). -use std::collections::VecDeque; -use std::sync::{Condvar, Mutex, MutexGuard, PoisonError}; -use std::time::Duration; +use std::{ + collections::VecDeque, + sync::{Condvar, Mutex, MutexGuard, PoisonError}, + time::Duration, +}; /// The type we use for queue size types. pub type Size = u32; @@ -179,9 +181,9 @@ impl Drop for DrainIterator<'_, T, CAPACITY> { #[cfg(test)] mod tests { + use std::{sync::Arc, thread}; + use super::*; - use std::sync::Arc; - use std::thread; #[test] fn basic_push_and_pop() { diff --git a/crates/ghostty-datastruct/src/lru.rs b/crates/ghostty-datastruct/src/lru.rs index bf547b3..21e6629 100644 --- a/crates/ghostty-datastruct/src/lru.rs +++ b/crates/ghostty-datastruct/src/lru.rs @@ -4,8 +4,10 @@ //! allocated entries; here the entries live in a slab and are linked by //! index. -use std::collections::HashMap as StdHashMap; -use std::hash::{BuildHasher, Hash, RandomState}; +use std::{ + collections::HashMap as StdHashMap, + hash::{BuildHasher, Hash, RandomState}, +}; /// Create a HashMap for a key type that can be automatically hashed. /// If you want finer-grained control, use [`HashMap`] directly. diff --git a/crates/ghostty-datastruct/src/split_tree.rs b/crates/ghostty-datastruct/src/split_tree.rs index 7a8ff06..2af6d25 100644 --- a/crates/ghostty-datastruct/src/split_tree.rs +++ b/crates/ghostty-datastruct/src/split_tree.rs @@ -20,9 +20,10 @@ //! parameters / `Allocator.Error`), the arena is replaced by a `Vec`, and the //! GObject boxed-type glue (`getGObjectType`) is left to the GTK crate. -use half::f16; use std::fmt; +use half::f16; + /// The requirements on the view type stored in a [`SplitTree`]. pub trait SplitTreeView: Clone { /// Return a label that is used for the debug view. If this returns diff --git a/crates/ghostty-font/src/atlas.rs b/crates/ghostty-font/src/atlas.rs index aca4dd9..0992f24 100644 --- a/crates/ghostty-font/src/atlas.rs +++ b/crates/ghostty-font/src/atlas.rs @@ -14,8 +14,10 @@ //! that regions written INTO the atlas do not have to be square, only //! the full atlas texture itself. -use std::io::Write; -use std::sync::atomic::{AtomicUsize, Ordering}; +use std::{ + io::Write, + sync::atomic::{AtomicUsize, Ordering}, +}; /// The format of the texture data being written into the Atlas. This must be /// uniform for all textures in the Atlas. If you have some textures with diff --git a/crates/ghostty-font/src/codepoint_map.rs b/crates/ghostty-font/src/codepoint_map.rs index 1238f63..54845cb 100644 --- a/crates/ghostty-font/src/codepoint_map.rs +++ b/crates/ghostty-font/src/codepoint_map.rs @@ -7,13 +7,13 @@ //! The canonical definition lives in `ghostty-config` (the `font-codepoint-map` //! option parses straight into it); it is re-exported here. -pub use ghostty_config::font_types::CodepointMap; -pub use ghostty_config::font_types::CodepointMapEntry as Entry; +pub use ghostty_config::font_types::{CodepointMap, CodepointMapEntry as Entry}; #[cfg(test)] mod tests { - use super::*; use ghostty_config::font_types::Descriptor; + use super::*; + fn desc(family: &str) -> Descriptor { Descriptor { family: Some(family.to_string()), diff --git a/crates/ghostty-font/src/codepoint_resolver.rs b/crates/ghostty-font/src/codepoint_resolver.rs index c0de211..d928f07 100644 --- a/crates/ghostty-font/src/codepoint_resolver.rs +++ b/crates/ghostty-font/src/codepoint_resolver.rs @@ -10,13 +10,18 @@ use std::collections::HashMap; -use crate::collection::{ - AddOptions, Collection, Entry, GetFaceError, Index, PresentationMode, Special, +use crate::{ + Atlas, + CodepointMap, + Glyph, + Presentation, + SpriteFace, + Style, + collection::{AddOptions, Collection, Entry, GetFaceError, Index, PresentationMode, Special}, + discovery::Discover, + face::{RenderOptions, freetype::RenderError as FaceRenderError}, + sprite, }; -use crate::discovery::Discover; -use crate::face::{RenderOptions, freetype::RenderError as FaceRenderError}; -use crate::sprite; -use crate::{Atlas, CodepointMap, Glyph, Presentation, SpriteFace, Style}; /// Packed array of booleans to indicate if a style is enabled or not. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -449,9 +454,13 @@ impl CodepointResolver { #[cfg(test)] mod tests { use super::*; - use crate::collection::{LoadOptions, SizeAdjustment}; - use crate::face::{DesiredSize, Options}; - use crate::{Face, Library, embedded}; + use crate::{ + Face, + Library, + collection::{LoadOptions, SizeAdjustment}, + embedded, + face::{DesiredSize, Options}, + }; fn add(c: &mut Collection, lib: &Library, data: &'static [u8], style: Style, pts: f32) { let size = if pts == 12.0 { diff --git a/crates/ghostty-font/src/collection.rs b/crates/ghostty-font/src/collection.rs index 547f48f..4d6d8e9 100644 --- a/crates/ghostty-font/src/collection.rs +++ b/crates/ghostty-font/src/collection.rs @@ -16,10 +16,17 @@ #![allow(clippy::collapsible_if, clippy::if_not_else, clippy::float_cmp)] -use crate::config_types::{FontSyntheticStyle, FreetypeLoadFlags}; -use crate::face::{self, DesiredSize}; -use crate::metrics::{FaceMetrics, ModifierSet}; -use crate::{DeferredFace, Face, Library, Metrics, Presentation, Style}; +use crate::{ + DeferredFace, + Face, + Library, + Metrics, + Presentation, + Style, + config_types::{FontSyntheticStyle, FreetypeLoadFlags}, + face::{self, DesiredSize}, + metrics::{FaceMetrics, ModifierSet}, +}; /// The available faces we have. This shouldn't be modified manually. /// Instead, use the functions available on Collection. @@ -1016,8 +1023,10 @@ impl Index { #[cfg(test)] mod tests { use super::*; - use crate::embedded; - use crate::face::{DesiredSize, Options}; + use crate::{ + embedded, + face::{DesiredSize, Options}, + }; fn opts_96(points: f32) -> Options { Options::new(DesiredSize { diff --git a/crates/ghostty-font/src/config_types.rs b/crates/ghostty-font/src/config_types.rs index 6a8f297..5b1e1ec 100644 --- a/crates/ghostty-font/src/config_types.rs +++ b/crates/ghostty-font/src/config_types.rs @@ -1,5 +1,7 @@ //! The config types consumed by the font engine. The canonical definitions //! live in `ghostty-config`; they are re-exported here for convenience. -pub use ghostty_config::types_a::{FontShapingBreak, FontStyle, FontSyntheticStyle}; -pub use ghostty_config::types_b::{FreetypeLoadFlags, GraphemeWidthMethod}; +pub use ghostty_config::{ + types_a::{FontShapingBreak, FontStyle, FontSyntheticStyle}, + types_b::{FreetypeLoadFlags, GraphemeWidthMethod}, +}; diff --git a/crates/ghostty-font/src/deferred_face.rs b/crates/ghostty-font/src/deferred_face.rs index d00b5fb..1721a67 100644 --- a/crates/ghostty-font/src/deferred_face.rs +++ b/crates/ghostty-font/src/deferred_face.rs @@ -7,9 +7,13 @@ //! //! Port of `font/DeferredFace.zig` (fontconfig variant only). -use crate::face::{self, Options, Variation}; -use crate::fontconfig as fc; -use crate::{Face, Library, Presentation}; +use crate::{ + Face, + Library, + Presentation, + face::{self, Options, Variation}, + fontconfig as fc, +}; #[derive(Debug, thiserror::Error)] pub enum LoadError { diff --git a/crates/ghostty-font/src/discovery.rs b/crates/ghostty-font/src/discovery.rs index b0bdc61..418e657 100644 --- a/crates/ghostty-font/src/discovery.rs +++ b/crates/ghostty-font/src/discovery.rs @@ -3,10 +3,12 @@ use std::sync::Arc; -use crate::collection::Collection; -use crate::deferred_face::{DeferredFace, Fontconfig as DeferredFontconfig}; -use crate::face::Variation; -use crate::fontconfig as fc; +use crate::{ + collection::Collection, + deferred_face::{DeferredFace, Fontconfig as DeferredFontconfig}, + face::Variation, + fontconfig as fc, +}; /// Discover implementation for the compile options. pub type Discover = Fontconfig; diff --git a/crates/ghostty-font/src/face/freetype.rs b/crates/ghostty-font/src/face/freetype.rs index b91f71e..158179e 100644 --- a/crates/ghostty-font/src/face/freetype.rs +++ b/crates/ghostty-font/src/face/freetype.rs @@ -6,14 +6,18 @@ //! //! Port of `font/face/freetype.zig`. -use std::ffi::CString; -use std::sync::{Arc, Mutex, MutexGuard, PoisonError}; +use std::{ + ffi::CString, + sync::{Arc, Mutex, MutexGuard, PoisonError}, +}; use super::{DesiredSize, FontData, FreetypeLoadFlags, Options, RenderOptions, Variation}; -use crate::atlas::{self, Atlas}; -use crate::glyph::Glyph; -use crate::library::Library; -use crate::metrics::FaceMetrics; +use crate::{ + atlas::{self, Atlas}, + glyph::Glyph, + library::Library, + metrics::FaceMetrics, +}; pub(crate) mod ft; mod resize; diff --git a/crates/ghostty-font/src/face/freetype/ft.rs b/crates/ghostty-font/src/face/freetype/ft.rs index 78c7326..dff0f64 100644 --- a/crates/ghostty-font/src/face/freetype/ft.rs +++ b/crates/ghostty-font/src/face/freetype/ft.rs @@ -8,8 +8,10 @@ // c_long is i64 on Linux but not everywhere; keep the casts portable. #![allow(clippy::unnecessary_cast)] -use std::ffi::{CStr, c_int, c_long, c_uint, c_ulong, c_void}; -use std::ptr::{self, NonNull}; +use std::{ + ffi::{CStr, c_int, c_long, c_uint, c_ulong, c_void}, + ptr::{self, NonNull}, +}; use freetype_sys as sys; diff --git a/crates/ghostty-font/src/fontconfig.rs b/crates/ghostty-font/src/fontconfig.rs index 1904517..5817511 100644 --- a/crates/ghostty-font/src/fontconfig.rs +++ b/crates/ghostty-font/src/fontconfig.rs @@ -4,9 +4,11 @@ //! All raw FFI is confined to this module. #![allow(unsafe_code)] -use std::ffi::{CStr, CString, c_int}; -use std::ptr::{self, NonNull}; -use std::sync::Arc; +use std::{ + ffi::{CStr, CString, c_int}, + ptr::{self, NonNull}, + sync::Arc, +}; use fontconfig_sys as sys; use fontconfig_sys::constants as fc; diff --git a/crates/ghostty-font/src/lib.rs b/crates/ghostty-font/src/lib.rs index 3f4ebe8..a854a66 100644 --- a/crates/ghostty-font/src/lib.rs +++ b/crates/ghostty-font/src/lib.rs @@ -29,7 +29,6 @@ pub mod sprite; pub use atlas::Atlas; pub use backend::{Backend, OPTIONS as options}; - pub use codepoint_map::CodepointMap; pub use codepoint_resolver::CodepointResolver; pub use collection::Collection; @@ -39,7 +38,6 @@ pub use face::Face; pub use glyph::Glyph; pub use library::Library; pub use metrics::Metrics; - pub use shared_grid::SharedGrid; pub use shared_grid_set::SharedGridSet; pub use sprite::{Face as SpriteFace, Sprite}; diff --git a/crates/ghostty-font/src/metrics.rs b/crates/ghostty-font/src/metrics.rs index 581f70b..47eeff8 100644 --- a/crates/ghostty-font/src/metrics.rs +++ b/crates/ghostty-font/src/metrics.rs @@ -1,7 +1,6 @@ //! Font metrics for the terminal grid. Port of `font/Metrics.zig`. -use std::collections::HashMap; -use std::str::FromStr; +use std::{collections::HashMap, str::FromStr}; /// Metrics describing the terminal grid cell for a font. #[derive(Debug, Clone, Copy, PartialEq)] diff --git a/crates/ghostty-font/src/opentype/head.rs b/crates/ghostty-font/src/opentype/head.rs index 16579c8..0c611ea 100644 --- a/crates/ghostty-font/src/opentype/head.rs +++ b/crates/ghostty-font/src/opentype/head.rs @@ -6,8 +6,7 @@ //! Field names are in camelCase to match names in the spec. #![allow(non_snake_case)] -use super::sfnt::Fixed; -use super::{EndOfStream, Reader}; +use super::{EndOfStream, Reader, sfnt::Fixed}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Head { @@ -81,8 +80,7 @@ impl Head { #[cfg(test)] mod tests { use super::*; - use crate::embedded; - use crate::opentype::sfnt::Sfnt; + use crate::{embedded, opentype::sfnt::Sfnt}; #[test] fn head() { diff --git a/crates/ghostty-font/src/opentype/hhea.rs b/crates/ghostty-font/src/opentype/hhea.rs index c24eced..3555be7 100644 --- a/crates/ghostty-font/src/opentype/hhea.rs +++ b/crates/ghostty-font/src/opentype/hhea.rs @@ -70,8 +70,7 @@ impl Hhea { #[cfg(test)] mod tests { use super::*; - use crate::embedded; - use crate::opentype::sfnt::Sfnt; + use crate::{embedded, opentype::sfnt::Sfnt}; #[test] fn hhea() { diff --git a/crates/ghostty-font/src/opentype/os2.rs b/crates/ghostty-font/src/opentype/os2.rs index 5accee6..0ac9d19 100644 --- a/crates/ghostty-font/src/opentype/os2.rs +++ b/crates/ghostty-font/src/opentype/os2.rs @@ -212,8 +212,7 @@ impl OS2 { #[cfg(test)] mod tests { use super::*; - use crate::embedded; - use crate::opentype::sfnt::Sfnt; + use crate::{embedded, opentype::sfnt::Sfnt}; #[test] fn os_2() { diff --git a/crates/ghostty-font/src/opentype/post.rs b/crates/ghostty-font/src/opentype/post.rs index cce59d5..119e195 100644 --- a/crates/ghostty-font/src/opentype/post.rs +++ b/crates/ghostty-font/src/opentype/post.rs @@ -4,8 +4,11 @@ //! - https://learn.microsoft.com/en-us/typography/opentype/spec/post #![allow(non_snake_case)] -use super::sfnt::{Fixed, Version16Dot16}; -use super::{EndOfStream, Reader}; +use super::{ + EndOfStream, + Reader, + sfnt::{Fixed, Version16Dot16}, +}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Post { @@ -44,8 +47,7 @@ impl Post { #[cfg(test)] mod tests { use super::*; - use crate::embedded; - use crate::opentype::sfnt::Sfnt; + use crate::{embedded, opentype::sfnt::Sfnt}; #[test] fn post() { diff --git a/crates/ghostty-font/src/opentype/svg.rs b/crates/ghostty-font/src/opentype/svg.rs index 3847d9e..7c8e8f9 100644 --- a/crates/ghostty-font/src/opentype/svg.rs +++ b/crates/ghostty-font/src/opentype/svg.rs @@ -119,8 +119,7 @@ impl<'a> SVG<'a> { #[cfg(test)] mod tests { use super::*; - use crate::embedded; - use crate::opentype::sfnt::Sfnt; + use crate::{embedded, opentype::sfnt::Sfnt}; // NOTE: the Zig test obtains the table through `Face.copyTable`; we read // the same bytes through the SFNT directory (Face-based variant lives diff --git a/crates/ghostty-font/src/shape.rs b/crates/ghostty-font/src/shape.rs index e1fe4a9..608cda3 100644 --- a/crates/ghostty-font/src/shape.rs +++ b/crates/ghostty-font/src/shape.rs @@ -3,14 +3,16 @@ //! The shaper implementation for the Linux backend is HarfBuzz //! ([`crate::shaper::harfbuzz::Shaper`]). -pub use crate::shaper::cache::Cache; -pub use crate::shaper::feature::{DEFAULT_FEATURES, Feature, FeatureList}; -pub use crate::shaper::run::{RunIterator, RunIteratorHook, RunOptions, TextRun}; -pub use crate::shaper::{harfbuzz, noop}; - /// Shaper implementation for our compile options (backend /// `fontconfig_freetype` => HarfBuzz). pub use crate::shaper::harfbuzz::Shaper; +pub use crate::shaper::{ + cache::Cache, + feature::{DEFAULT_FEATURES, Feature, FeatureList}, + harfbuzz, + noop, + run::{RunIterator, RunIteratorHook, RunOptions, TextRun}, +}; /// A cell is a single single within a terminal that should be rendered /// for a shaping call. Note all terminal cells may be present; only diff --git a/crates/ghostty-font/src/shaper/harfbuzz.rs b/crates/ghostty-font/src/shaper/harfbuzz.rs index 4ff32a2..e6fe935 100644 --- a/crates/ghostty-font/src/shaper/harfbuzz.rs +++ b/crates/ghostty-font/src/shaper/harfbuzz.rs @@ -11,9 +11,11 @@ //! prepare/add/finalize/shape sequence. use super::hb; -use crate::face::freetype::Face; -use crate::shape::{self, Cell, DEFAULT_FEATURES, FeatureList, TextRun}; -use crate::shared_grid::SharedGrid; +use crate::{ + face::freetype::Face, + shape::{self, Cell, DEFAULT_FEATURES, FeatureList, TextRun}, + shared_grid::SharedGrid, +}; #[derive(Debug, thiserror::Error)] pub enum ShapeError { @@ -297,13 +299,22 @@ impl Shaper { #[cfg(test)] mod tests { use super::*; - use crate::face::{DesiredSize, FontData, Options}; - use crate::shaper::run::{RunIterator, RunOptions}; - use crate::shaper::test_util::{ - Term, TestFont, shape_all, test_shaper, test_shaper_with_discovered_font, - test_shaper_with_font, + use crate::{ + Library, + embedded, + face::{DesiredSize, FontData, Options}, + shaper::{ + run::{RunIterator, RunOptions}, + test_util::{ + Term, + TestFont, + shape_all, + test_shaper, + test_shaper_with_discovered_font, + test_shaper_with_font, + }, + }, }; - use crate::{Library, embedded}; fn text(s: &str) -> Vec<(u32, u32)> { s.chars() diff --git a/crates/ghostty-font/src/shaper/noop.rs b/crates/ghostty-font/src/shaper/noop.rs index 854e22a..be2f9ed 100644 --- a/crates/ghostty-font/src/shaper/noop.rs +++ b/crates/ghostty-font/src/shaper/noop.rs @@ -2,8 +2,10 @@ //! Each individual codepoint is mapped directly to the detected text run //! font's glyph index. -use crate::face::freetype::Face; -use crate::shape::{self, Cell}; +use crate::{ + face::freetype::Face, + shape::{self, Cell}, +}; #[derive(Debug, Clone, Copy)] struct Codepoint { diff --git a/crates/ghostty-font/src/shaper/run.rs b/crates/ghostty-font/src/shaper/run.rs index df5d063..639c6b8 100644 --- a/crates/ghostty-font/src/shaper/run.rs +++ b/crates/ghostty-font/src/shaper/run.rs @@ -12,12 +12,17 @@ use std::hash::{DefaultHasher, Hash, Hasher}; use ghostty_config::types_a::FontShapingBreak; -use ghostty_terminal::page::{Cell, ContentTag, Page, Wide}; -use ghostty_terminal::style::{Color, Style as TermStyle}; +use ghostty_terminal::{ + page::{Cell, ContentTag, Page, Wide}, + style::{Color, Style as TermStyle}, +}; -use crate::collection::Index; -use crate::shared_grid::{Error as GridError, SharedGrid}; -use crate::{Presentation, Style}; +use crate::{ + Presentation, + Style, + collection::Index, + shared_grid::{Error as GridError, SharedGrid}, +}; /// The Kitty graphics unicode placeholder codepoint /// (`terminal.kitty.graphics.unicode.placeholder`). diff --git a/crates/ghostty-font/src/shaper/test_util.rs b/crates/ghostty-font/src/shaper/test_util.rs index 0e9f1de..9621ef4 100644 --- a/crates/ghostty-font/src/shaper/test_util.rs +++ b/crates/ghostty-font/src/shaper/test_util.rs @@ -9,19 +9,29 @@ #![allow(clippy::collapsible_if)] -use ghostty_terminal::page::Cell; -use ghostty_terminal::point::{Coordinate, Point}; -use ghostty_terminal::screen::{Options, Screen}; -use ghostty_vt::color::Rgb; -use ghostty_vt::sgr::Attribute; +use ghostty_terminal::{ + page::Cell, + point::{Coordinate, Point}, + screen::{Options, Screen}, +}; +use ghostty_vt::{color::Rgb, sgr::Attribute}; -use crate::codepoint_resolver::CodepointResolver; -use crate::collection::{AddOptions, Collection, LoadOptions, SizeAdjustment}; -use crate::discovery::{Descriptor, Fontconfig}; -use crate::face::{DesiredSize, FontData, Options as FaceOptions}; -use crate::shaper::harfbuzz::Shaper; -use crate::shaper::run::{RunCell, RunIterator, RunOptions}; -use crate::{Face, Library, SharedGrid, Style, embedded, shape}; +use crate::{ + Face, + Library, + SharedGrid, + Style, + codepoint_resolver::CodepointResolver, + collection::{AddOptions, Collection, LoadOptions, SizeAdjustment}, + discovery::{Descriptor, Fontconfig}, + embedded, + face::{DesiredSize, FontData, Options as FaceOptions}, + shape, + shaper::{ + harfbuzz::Shaper, + run::{RunCell, RunIterator, RunOptions}, + }, +}; #[derive(Clone, Copy)] pub(crate) enum TestFont { diff --git a/crates/ghostty-font/src/shared_grid.rs b/crates/ghostty-font/src/shared_grid.rs index ee20f5b..92fd2d4 100644 --- a/crates/ghostty-font/src/shared_grid.rs +++ b/crates/ghostty-font/src/shared_grid.rs @@ -19,14 +19,22 @@ #![allow(clippy::collapsible_if, clippy::if_not_else, clippy::float_cmp)] -use std::collections::HashMap; -use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; +use std::{ + collections::HashMap, + sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}, +}; -use crate::atlas::{self, Atlas}; -use crate::codepoint_resolver::{CodepointResolver, RenderGlyphError}; -use crate::collection::{self, Collection, GetFaceError, Index, PresentationMode}; -use crate::face::{Constraint, ConstraintSize, RenderOptions}; -use crate::{Glyph, Metrics, Presentation, SpriteFace, Style}; +use crate::{ + Glyph, + Metrics, + Presentation, + SpriteFace, + Style, + atlas::{self, Atlas}, + codepoint_resolver::{CodepointResolver, RenderGlyphError}, + collection::{self, Collection, GetFaceError, Index, PresentationMode}, + face::{Constraint, ConstraintSize, RenderOptions}, +}; /// The size of a grid cell in pixels. // TODO(integration): replace with `renderer::CellSize` once the renderer @@ -386,9 +394,13 @@ impl State { #[cfg(test)] mod tests { use super::*; - use crate::collection::{AddOptions, LoadOptions, SizeAdjustment}; - use crate::face::{DesiredSize, Options}; - use crate::{Face, Library, embedded}; + use crate::{ + Face, + Library, + collection::{AddOptions, LoadOptions, SizeAdjustment}, + embedded, + face::{DesiredSize, Options}, + }; fn test_grid(lib: &Library) -> SharedGrid { let mut c = Collection::new(); diff --git a/crates/ghostty-font/src/shared_grid_set.rs b/crates/ghostty-font/src/shared_grid_set.rs index abd6d2a..6b9a845 100644 --- a/crates/ghostty-font/src/shared_grid_set.rs +++ b/crates/ghostty-font/src/shared_grid_set.rs @@ -8,28 +8,38 @@ //! This structure is thread-safe when the operations are documented //! as thread-safe. -use std::collections::HashMap; -use std::hash::{DefaultHasher, Hash, Hasher}; -use std::sync::{Arc, Mutex, MutexGuard}; - -use ghostty_config::config::Config; -use ghostty_config::font_types::Variation; -use ghostty_config::font_types::VariationId; -use ghostty_config::types_a::{ - FontStyle, FontSyntheticStyle, RepeatableCodepointMap, RepeatableFontVariation, - RepeatableString, +use std::{ + collections::HashMap, + hash::{DefaultHasher, Hash, Hasher}, + sync::{Arc, Mutex, MutexGuard}, }; -use ghostty_config::types_b::FreetypeLoadFlags; -use crate::codepoint_map::CodepointMap; -use crate::codepoint_resolver::{CodepointResolver, StyleStatus}; -use crate::collection::{self, AddOptions, Collection, LoadOptions, SizeAdjustment}; -use crate::discovery::{Descriptor, Discover, Fontconfig}; -use crate::face::{self, DesiredSize, FontData}; -use crate::library::{Library, LibraryError}; -use crate::metrics::{Key as MetricsKey, Modifier, ModifierSet}; -use crate::shared_grid::{self, SharedGrid}; -use crate::{Face, Style, embedded}; +use ghostty_config::{ + config::Config, + font_types::{Variation, VariationId}, + types_a::{ + FontStyle, + FontSyntheticStyle, + RepeatableCodepointMap, + RepeatableFontVariation, + RepeatableString, + }, + types_b::FreetypeLoadFlags, +}; + +use crate::{ + Face, + Style, + codepoint_map::CodepointMap, + codepoint_resolver::{CodepointResolver, StyleStatus}, + collection::{self, AddOptions, Collection, LoadOptions, SizeAdjustment}, + discovery::{Descriptor, Discover, Fontconfig}, + embedded, + face::{self, DesiredSize, FontData}, + library::{Library, LibraryError}, + metrics::{Key as MetricsKey, Modifier, ModifierSet}, + shared_grid::{self, SharedGrid}, +}; /// Errors from [`SharedGridSet::ref_`]. #[derive(Debug, thiserror::Error)] diff --git a/crates/ghostty-font/src/sprite/draw/block.rs b/crates/ghostty-font/src/sprite/draw/block.rs index e44b766..827dc6f 100644 --- a/crates/ghostty-font/src/sprite/draw/block.rs +++ b/crates/ghostty-font/src/sprite/draw/block.rs @@ -7,11 +7,27 @@ //! Port of `sprite/draw/block.zig`. use super::common::{ - Alignment, DrawFn, FIVE_EIGHTHS, Fraction, HALF, HAlign, ONE_EIGHTH, ONE_QUARTER, Quads, Range, - SEVEN_EIGHTHS, Shade, THREE_EIGHTHS, THREE_QUARTERS, VAlign, fill, + Alignment, + DrawFn, + FIVE_EIGHTHS, + Fraction, + HALF, + HAlign, + ONE_EIGHTH, + ONE_QUARTER, + Quads, + Range, + SEVEN_EIGHTHS, + Shade, + THREE_EIGHTHS, + THREE_QUARTERS, + VAlign, + fill, +}; +use crate::{ + metrics::Metrics, + sprite::canvas::{Canvas, Color, DrawError, Rect}, }; -use crate::metrics::Metrics; -use crate::sprite::canvas::{Canvas, Color, DrawError, Rect}; pub const RANGES: &[Range] = &[Range { min: 0x2580, diff --git a/crates/ghostty-font/src/sprite/draw/box_.rs b/crates/ghostty-font/src/sprite/draw/box_.rs index 732bd44..cc5ec5c 100644 --- a/crates/ghostty-font/src/sprite/draw/box_.rs +++ b/crates/ghostty-font/src/sprite/draw/box_.rs @@ -15,8 +15,10 @@ #![allow(clippy::needless_update)] use super::common::{Corner, DrawFn, Range, Thickness, hline, hline_middle, vline, vline_middle}; -use crate::metrics::Metrics; -use crate::sprite::canvas::{Canvas, CapMode, Color, DrawError, Line, Path, Point, StrokeOptions}; +use crate::{ + metrics::Metrics, + sprite::canvas::{Canvas, CapMode, Color, DrawError, Line, Path, Point, StrokeOptions}, +}; pub const RANGES: &[Range] = &[Range { min: 0x2500, diff --git a/crates/ghostty-font/src/sprite/draw/braille.rs b/crates/ghostty-font/src/sprite/draw/braille.rs index 940eba4..090c50e 100644 --- a/crates/ghostty-font/src/sprite/draw/braille.rs +++ b/crates/ghostty-font/src/sprite/draw/braille.rs @@ -24,8 +24,10 @@ //! Port of `sprite/draw/braille.zig`. use super::common::{DrawFn, Range}; -use crate::metrics::Metrics; -use crate::sprite::canvas::{Canvas, Color, DrawError}; +use crate::{ + metrics::Metrics, + sprite::canvas::{Canvas, Color, DrawError}, +}; pub const RANGES: &[Range] = &[Range { min: 0x2800, diff --git a/crates/ghostty-font/src/sprite/draw/branch.rs b/crates/ghostty-font/src/sprite/draw/branch.rs index 6412505..8344d78 100644 --- a/crates/ghostty-font/src/sprite/draw/branch.rs +++ b/crates/ghostty-font/src/sprite/draw/branch.rs @@ -14,10 +14,14 @@ use std::f64::consts::PI; -use super::box_; -use super::common::{Corner, DrawFn, Edge, Range, Shade, Thickness, hline_middle, vline_middle}; -use crate::metrics::Metrics; -use crate::sprite::canvas::{Canvas, CapMode, Color, DrawError, Path, StrokeOptions}; +use super::{ + box_, + common::{Corner, DrawFn, Edge, Range, Shade, Thickness, hline_middle, vline_middle}, +}; +use crate::{ + metrics::Metrics, + sprite::canvas::{Canvas, CapMode, Color, DrawError, Path, StrokeOptions}, +}; pub const RANGES: &[Range] = &[Range { min: 0xf5d0, diff --git a/crates/ghostty-font/src/sprite/draw/common.rs b/crates/ghostty-font/src/sprite/draw/common.rs index 0a2f1ed..6b79022 100644 --- a/crates/ghostty-font/src/sprite/draw/common.rs +++ b/crates/ghostty-font/src/sprite/draw/common.rs @@ -3,8 +3,10 @@ //! are generally applicable to multiple sets of glyphs //! rather than being single-use. Port of `sprite/draw/common.zig`. -use crate::metrics::Metrics; -use crate::sprite::canvas::{Canvas, Color, DrawError}; +use crate::{ + metrics::Metrics, + sprite::canvas::{Canvas, Color, DrawError}, +}; /// A function that draws a glyph on the provided canvas. pub type DrawFn = fn( diff --git a/crates/ghostty-font/src/sprite/draw/geometric_shapes.rs b/crates/ghostty-font/src/sprite/draw/geometric_shapes.rs index 60092c2..0710e14 100644 --- a/crates/ghostty-font/src/sprite/draw/geometric_shapes.rs +++ b/crates/ghostty-font/src/sprite/draw/geometric_shapes.rs @@ -14,8 +14,10 @@ //! Port of `sprite/draw/geometric_shapes.zig`. use super::common::{Corner, DrawFn, Range, Shade, Thickness}; -use crate::metrics::Metrics; -use crate::sprite::canvas::{Canvas, CapMode, Color, DrawError, Path, StrokeOptions}; +use crate::{ + metrics::Metrics, + sprite::canvas::{Canvas, CapMode, Color, DrawError, Path, StrokeOptions}, +}; pub const RANGES: &[Range] = &[ Range { diff --git a/crates/ghostty-font/src/sprite/draw/powerline.rs b/crates/ghostty-font/src/sprite/draw/powerline.rs index f40e1ad..d155644 100644 --- a/crates/ghostty-font/src/sprite/draw/powerline.rs +++ b/crates/ghostty-font/src/sprite/draw/powerline.rs @@ -11,11 +11,13 @@ use std::f64::consts::SQRT_2; -use super::box_; -use super::common::{DrawFn, Range, Thickness}; -use crate::metrics::Metrics; -use crate::sprite::canvas::{ - Canvas, CapMode, Color, DrawError, Path, Point, StrokeOptions, Triangle, +use super::{ + box_, + common::{DrawFn, Range, Thickness}, +}; +use crate::{ + metrics::Metrics, + sprite::canvas::{Canvas, CapMode, Color, DrawError, Path, Point, StrokeOptions, Triangle}, }; pub const RANGES: &[Range] = &[ diff --git a/crates/ghostty-font/src/sprite/draw/special.rs b/crates/ghostty-font/src/sprite/draw/special.rs index dc86c0e..3f48359 100644 --- a/crates/ghostty-font/src/sprite/draw/special.rs +++ b/crates/ghostty-font/src/sprite/draw/special.rs @@ -6,8 +6,10 @@ use std::f64::consts::{FRAC_1_SQRT_2, PI, TAU}; -use crate::metrics::Metrics; -use crate::sprite::canvas::{Canvas, CapMode, Color, DrawError, Path, Rect, StrokeOptions}; +use crate::{ + metrics::Metrics, + sprite::canvas::{Canvas, CapMode, Color, DrawError, Path, Rect, StrokeOptions}, +}; pub fn underline( _cp: u32, diff --git a/crates/ghostty-font/src/sprite/draw/symbols_for_legacy_computing.rs b/crates/ghostty-font/src/sprite/draw/symbols_for_legacy_computing.rs index 8985115..dbf02aa 100644 --- a/crates/ghostty-font/src/sprite/draw/symbols_for_legacy_computing.rs +++ b/crates/ghostty-font/src/sprite/draw/symbols_for_legacy_computing.rs @@ -3,16 +3,38 @@ //! //! Port of `sprite/draw/symbols_for_legacy_computing.zig`. -use super::block; -use super::box_; -use super::common::{ - Alignment, Corner, DrawFn, Edge, FIVE_EIGHTHS, Fraction, HALF, HAlign, ONE_EIGHTH, ONE_QUARTER, - ONE_THIRD, Quads, Range, SEVEN_EIGHTHS, Shade, THREE_EIGHTHS, THREE_QUARTERS, TWO_THIRDS, - Thickness, VAlign, fill, +use super::{ + block, + box_, + common::{ + Alignment, + Corner, + DrawFn, + Edge, + FIVE_EIGHTHS, + Fraction, + HALF, + HAlign, + ONE_EIGHTH, + ONE_QUARTER, + ONE_THIRD, + Quads, + Range, + SEVEN_EIGHTHS, + Shade, + THREE_EIGHTHS, + THREE_QUARTERS, + TWO_THIRDS, + Thickness, + VAlign, + fill, + }, + geometric_shapes as geo, +}; +use crate::{ + metrics::Metrics, + sprite::canvas::{Canvas, Color, DrawError, Line, Path, Point, Rect, StrokeOptions}, }; -use super::geometric_shapes as geo; -use crate::metrics::Metrics; -use crate::sprite::canvas::{Canvas, Color, DrawError, Line, Path, Point, Rect, StrokeOptions}; const _: (f64, f64) = (ONE_THIRD, TWO_THIRDS); diff --git a/crates/ghostty-font/src/sprite/draw/symbols_for_legacy_computing_supplement.rs b/crates/ghostty-font/src/sprite/draw/symbols_for_legacy_computing_supplement.rs index 86df137..de0b291 100644 --- a/crates/ghostty-font/src/sprite/draw/symbols_for_legacy_computing_supplement.rs +++ b/crates/ghostty-font/src/sprite/draw/symbols_for_legacy_computing_supplement.rs @@ -5,11 +5,15 @@ use std::sync::OnceLock; -use super::box_::{self, Lines, Style}; -use super::common::{Alignment, Corner, DrawFn, Fraction, Range, fill}; -use super::symbols_for_legacy_computing as sflc; -use crate::metrics::Metrics; -use crate::sprite::canvas::{Canvas, CapMode, Color, DrawError, Path, StrokeOptions}; +use super::{ + box_::{self, Lines, Style}, + common::{Alignment, Corner, DrawFn, Fraction, Range, fill}, + symbols_for_legacy_computing as sflc, +}; +use crate::{ + metrics::Metrics, + sprite::canvas::{Canvas, CapMode, Color, DrawError, Path, StrokeOptions}, +}; pub const RANGES: &[Range] = &[ Range { diff --git a/crates/ghostty-font/src/sprite/face.rs b/crates/ghostty-font/src/sprite/face.rs index 9c30a71..b5bda7c 100644 --- a/crates/ghostty-font/src/sprite/face.rs +++ b/crates/ghostty-font/src/sprite/face.rs @@ -15,19 +15,28 @@ use std::sync::OnceLock; -use super::Sprite; -use super::canvas::{Canvas, DrawError}; -use super::draw::common::{DrawFn, Range}; -use super::draw::{ - block, box_, braille, branch, geometric_shapes, powerline, special, - symbols_for_legacy_computing, symbols_for_legacy_computing_supplement, +use super::{ + Sprite, + canvas::{Canvas, DrawError}, + draw::{ + block, + box_, + braille, + branch, + common::{DrawFn, Range}, + geometric_shapes, + powerline, + special, + symbols_for_legacy_computing, + symbols_for_legacy_computing_supplement, + }, +}; +pub use crate::{Presentation, face::RenderOptions}; +use crate::{ + atlas::{self, Atlas}, + glyph::Glyph, + metrics::Metrics, }; -use crate::atlas::{self, Atlas}; -use crate::glyph::Glyph; -use crate::metrics::Metrics; - -pub use crate::Presentation; -pub use crate::face::RenderOptions; /// Errors from [`Face::render_glyph`]. #[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] diff --git a/crates/ghostty-input/src/binding/action.rs b/crates/ghostty-input/src/binding/action.rs index 7d2996f..8b357be 100644 --- a/crates/ghostty-input/src/binding/action.rs +++ b/crates/ghostty-input/src/binding/action.rs @@ -3,8 +3,10 @@ #![allow(clippy::needless_raw_string_hashes)] -use std::fmt; -use std::hash::{Hash, Hasher}; +use std::{ + fmt, + hash::{Hash, Hasher}, +}; use super::Error; diff --git a/crates/ghostty-input/src/binding/mod.rs b/crates/ghostty-input/src/binding/mod.rs index cc5f3e4..562d56e 100644 --- a/crates/ghostty-input/src/binding/mod.rs +++ b/crates/ghostty-input/src/binding/mod.rs @@ -4,19 +4,38 @@ pub mod action; pub mod set; -use std::collections::hash_map::DefaultHasher; -use std::fmt; -use std::hash::{Hash, Hasher}; +use std::{ + collections::hash_map::DefaultHasher, + fmt, + hash::{Hash, Hasher}, +}; pub use action::{ - Action, ActionKey, AdjustSelection, CloseTabMode, CopyToClipboard, CrashThread, CursorKey, - GotoWindow, InspectorMode, NavigateSearch, Scope, SplitDirection, SplitFocusDirection, - SplitResizeDirection, SplitResizeParameter, WriteScreen, WriteScreenAction, WriteScreenFormat, + Action, + ActionKey, + AdjustSelection, + CloseTabMode, + CopyToClipboard, + CrashThread, + CursorKey, + GotoWindow, + InspectorMode, + NavigateSearch, + Scope, + SplitDirection, + SplitFocusDirection, + SplitResizeDirection, + SplitResizeParameter, + WriteScreen, + WriteScreenAction, + WriteScreenFormat, }; pub use set::Set; -use crate::key; -use crate::key_mods::{self, Mods}; +use crate::{ + key, + key_mods::{self, Mods}, +}; #[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)] pub enum Error { diff --git a/crates/ghostty-input/src/binding/tests.rs b/crates/ghostty-input/src/binding/tests.rs index 961fa3f..3d232c6 100644 --- a/crates/ghostty-input/src/binding/tests.rs +++ b/crates/ghostty-input/src/binding/tests.rs @@ -1,9 +1,13 @@ #![allow(clippy::unwrap_used)] -use super::set::{AppendChainError, EntryFormatter, Value}; -use super::*; -use crate::key::{Key, KeyEvent}; -use crate::key_mods::Mods; +use super::{ + set::{AppendChainError, EntryFormatter, Value}, + *, +}; +use crate::{ + key::{Key, KeyEvent}, + key_mods::Mods, +}; fn uni(c: char) -> Trigger { Trigger { diff --git a/crates/ghostty-input/src/command.rs b/crates/ghostty-input/src/command.rs index e8e762d..26ad62d 100644 --- a/crates/ghostty-input/src/command.rs +++ b/crates/ghostty-input/src/command.rs @@ -3,8 +3,17 @@ use std::sync::OnceLock; use crate::binding::{ - Action, CloseTabMode, CopyToClipboard, GotoWindow, InspectorMode, NavigateSearch, - SplitDirection, SplitFocusDirection, WriteScreen, WriteScreenAction, WriteScreenFormat, + Action, + CloseTabMode, + CopyToClipboard, + GotoWindow, + InspectorMode, + NavigateSearch, + SplitDirection, + SplitFocusDirection, + WriteScreen, + WriteScreenAction, + WriteScreenFormat, }; /// A command is a named binding action that can be executed from diff --git a/crates/ghostty-input/src/lib.rs b/crates/ghostty-input/src/lib.rs index 4d7e2ae..248d012 100644 --- a/crates/ghostty-input/src/lib.rs +++ b/crates/ghostty-input/src/lib.rs @@ -21,6 +21,8 @@ pub use key_mods::{Mods, RemapSet as KeyRemapSet}; pub use keyboard::Layout as KeyboardLayout; pub use link::Link; pub use mouse::{ - Button as MouseButton, ButtonState as MouseButtonState, PressureStage as MousePressureStage, + Button as MouseButton, + ButtonState as MouseButtonState, + PressureStage as MousePressureStage, ScrollMods, }; diff --git a/crates/ghostty-inspector/src/inspector.rs b/crates/ghostty-inspector/src/inspector.rs index 48f72e2..d460a4f 100644 --- a/crates/ghostty-inspector/src/inspector.rs +++ b/crates/ghostty-inspector/src/inspector.rs @@ -3,8 +3,7 @@ use std::sync::{Mutex, MutexGuard, PoisonError}; use dear_imgui_rs::{ConfigFlags, Context, FontSource, StbTrueTypeFontData, Ui}; -use ghostty_renderer::overlay::Feature; -use ghostty_renderer::state::InspectorHook; +use ghostty_renderer::{overlay::Feature, state::InspectorHook}; use ghostty_terminal::terminal::Terminal; use crate::widgets; @@ -111,13 +110,14 @@ impl InspectorHook for Shared { #[cfg(test)] mod tests { - use super::*; - use crate::widgets::surface::SurfaceInfo; use ghostty_input::{Action, Key, KeyEvent}; use ghostty_renderer::size::{CellSize, Padding, ScreenSize, Size}; use ghostty_terminal::terminal::Options; use ghostty_vt::stream::Stream; + use super::*; + use crate::widgets::surface::SurfaceInfo; + fn surface_info() -> SurfaceInfo { SurfaceInfo { size: Size { diff --git a/crates/ghostty-inspector/src/widgets/key.rs b/crates/ghostty-inspector/src/widgets/key.rs index beb585c..5f98dff 100644 --- a/crates/ghostty-inspector/src/widgets/key.rs +++ b/crates/ghostty-inspector/src/widgets/key.rs @@ -3,8 +3,7 @@ use std::collections::VecDeque; use dear_imgui_rs::{InputTextFlags, TableColumnFlags, TableColumnWidth, TableFlags, Ui}; -use ghostty_input::binding::Action as BindingAction; -use ghostty_input::{Action, Key, KeyEvent, Mods}; +use ghostty_input::{Action, Key, KeyEvent, Mods, binding::Action as BindingAction}; /// The maximum number of recorded events (Zig: the ring grows by doubling up /// to this capacity, after which the oldest event is dropped). diff --git a/crates/ghostty-inspector/src/widgets/page.rs b/crates/ghostty-inspector/src/widgets/page.rs index 83b3dc4..249cafe 100644 --- a/crates/ghostty-inspector/src/widgets/page.rs +++ b/crates/ghostty-inspector/src/widgets/page.rs @@ -1,8 +1,7 @@ //! Page inspector (ZIG/src/inspector/widgets/page.zig). use dear_imgui_rs::{ChildFlags, TableColumnFlags, TableColumnWidth, TableFlags, Ui}; -use ghostty_terminal::hyperlink::HyperlinkId; -use ghostty_terminal::page::Page; +use ghostty_terminal::{hyperlink::HyperlinkId, page::Page}; use super::{help_marker, style}; use crate::units::to_kibi_bytes; diff --git a/crates/ghostty-inspector/src/widgets/pagelist.rs b/crates/ghostty-inspector/src/widgets/pagelist.rs index 846be15..5c9c9d5 100644 --- a/crates/ghostty-inspector/src/widgets/pagelist.rs +++ b/crates/ghostty-inspector/src/widgets/pagelist.rs @@ -1,12 +1,20 @@ //! PageList inspector (ZIG/src/inspector/widgets/pagelist.zig). use dear_imgui_rs::{ - ComboBoxHeight, ComboBoxOptions, ItemHoveredFlags, MouseButton, StyleColor, TableFlags, - TreeNodeFlags, Ui, + ComboBoxHeight, + ComboBoxOptions, + ItemHoveredFlags, + MouseButton, + StyleColor, + TableFlags, + TreeNodeFlags, + Ui, +}; +use ghostty_terminal::{ + page_list::{PageList, Scroll, Scrollbar}, + point::{Coordinate, Point, Tag}, + style::DEFAULT_ID, }; -use ghostty_terminal::page_list::{PageList, Scroll, Scrollbar}; -use ghostty_terminal::point::{Coordinate, Point, Tag}; -use ghostty_terminal::style::DEFAULT_ID; use super::{help_marker, page, style}; use crate::units::to_kibi_bytes; diff --git a/crates/ghostty-inspector/src/widgets/screen.rs b/crates/ghostty-inspector/src/widgets/screen.rs index 18c2e54..1aaf240 100644 --- a/crates/ghostty-inspector/src/widgets/screen.rs +++ b/crates/ghostty-inspector/src/widgets/screen.rs @@ -1,10 +1,12 @@ //! Screen information (ZIG/src/inspector/widgets/screen.zig). use dear_imgui_rs::{DockNodeFlags, TableFlags, TreeNodeFlags, Ui, WindowFlags}; -use ghostty_terminal::kitty::graphics_storage::ImageStorage; -use ghostty_terminal::screen::{Cursor, Screen, SemanticClick, SemanticPrompt}; -use ghostty_terminal::screen_set::Key as ScreenKey; -use ghostty_terminal::style::Style; +use ghostty_terminal::{ + kitty::graphics_storage::ImageStorage, + screen::{Cursor, Screen, SemanticClick, SemanticPrompt}, + screen_set::Key as ScreenKey, + style::Style, +}; use ghostty_vt::color::{DynamicPalette, Palette}; use super::{help_marker, pagelist, style as style_widget}; diff --git a/crates/ghostty-inspector/src/widgets/surface.rs b/crates/ghostty-inspector/src/widgets/surface.rs index e27cef9..20f4822 100644 --- a/crates/ghostty-inspector/src/widgets/surface.rs +++ b/crates/ghostty-inspector/src/widgets/surface.rs @@ -3,9 +3,11 @@ use dear_imgui_rs::{DockNodeFlags, TableFlags, TreeNodeFlags, Ui, WindowFlags}; use ghostty_renderer::size::{Coordinate, CoordinateTag, Size, SurfaceCoord}; -use ghostty_terminal::page_list::Pin; -use ghostty_terminal::point::{Coordinate as PointCoordinate, Tag}; -use ghostty_terminal::terminal::Terminal; +use ghostty_terminal::{ + page_list::Pin, + point::{Coordinate as PointCoordinate, Tag}, + terminal::Terminal, +}; use super::{key, renderer, terminal, termio}; use crate::dock::begin_window; diff --git a/crates/ghostty-inspector/src/widgets/terminal.rs b/crates/ghostty-inspector/src/widgets/terminal.rs index ef3a121..ad021dc 100644 --- a/crates/ghostty-inspector/src/widgets/terminal.rs +++ b/crates/ghostty-inspector/src/widgets/terminal.rs @@ -1,13 +1,25 @@ //! Terminal information (ZIG/src/inspector/widgets/terminal.zig). use dear_imgui_rs::{ - ColorEditFlags, Condition, ItemHoveredFlags, StyleVar, TableColumnFlags, TableColumnWidth, - TableFlags, TableRowFlags, Ui, WindowFlags, + ColorEditFlags, + Condition, + ItemHoveredFlags, + StyleVar, + TableColumnFlags, + TableColumnWidth, + TableFlags, + TableRowFlags, + Ui, + WindowFlags, +}; +use ghostty_terminal::{ + screen_set::Key as ScreenKey, + terminal::{MouseShiftCapture, Terminal}, +}; +use ghostty_vt::{ + color::{DynamicRgb, Palette}, + modes::ENTRIES as MODE_ENTRIES, }; -use ghostty_terminal::screen_set::Key as ScreenKey; -use ghostty_terminal::terminal::{MouseShiftCapture, Terminal}; -use ghostty_vt::color::{DynamicRgb, Palette}; -use ghostty_vt::modes::ENTRIES as MODE_ENTRIES; use super::{DetachableHeader, help_marker, screen, style::rgb_f32}; use crate::keys::tag_name; diff --git a/crates/ghostty-inspector/src/widgets/termio.rs b/crates/ghostty-inspector/src/widgets/termio.rs index ec6aaf4..09cce95 100644 --- a/crates/ghostty-inspector/src/widgets/termio.rs +++ b/crates/ghostty-inspector/src/widgets/termio.rs @@ -1,18 +1,24 @@ //! VT event stream inspector (ZIG/src/inspector/widgets/termio.zig). -use std::collections::VecDeque; -use std::convert::Infallible; -use std::fmt::Write as _; +use std::{collections::VecDeque, convert::Infallible, fmt::Write as _}; use dear_imgui_rs::{ - FocusedFlags, Key, SelectableFlags, TableColumnFlags, TableColumnWidth, TableFlags, Ui, + FocusedFlags, + Key, + SelectableFlags, + TableColumnFlags, + TableColumnWidth, + TableFlags, + Ui, WindowFlags, }; use ghostty_terminal::terminal::{ScrollingRegion, Terminal}; -use ghostty_vt::color::Palette; -use ghostty_vt::osc::{self, Command as OscCommand}; -use ghostty_vt::parser::Action as ParserAction; -use ghostty_vt::stream::{Action as StreamAction, Handler, Stream as VtStream}; +use ghostty_vt::{ + color::Palette, + osc::{self, Command as OscCommand}, + parser::Action as ParserAction, + stream::{Action as StreamAction, Handler, Stream as VtStream}, +}; use super::screen::{CursorSnapshot, cursor_style, cursor_table}; diff --git a/crates/ghostty-onig/src/lib.rs b/crates/ghostty-onig/src/lib.rs index 0fc8845..74dfcd6 100644 --- a/crates/ghostty-onig/src/lib.rs +++ b/crates/ghostty-onig/src/lib.rs @@ -26,9 +26,10 @@ pub fn set_retry_limit_in_search(param: &mut MatchParam, limit: u32) { #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)] - use super::*; use onig::{Regex, SearchOptions}; + use super::*; + fn search(re: &Regex, text: &str, limit: Option) -> Result, onig::Error> { let mut param = MatchParam::default(); if let Some(l) = limit { diff --git a/crates/ghostty-os/src/env.rs b/crates/ghostty-os/src/env.rs index f6fc7f9..903b451 100644 --- a/crates/ghostty-os/src/env.rs +++ b/crates/ghostty-os/src/env.rs @@ -1,5 +1,7 @@ -use std::collections::HashMap; -use std::ffi::{OsStr, OsString}; +use std::{ + collections::HashMap, + ffi::{OsStr, OsString}, +}; use crate::flatpak::is_flatpak; @@ -214,9 +216,10 @@ pub fn getenv_not_empty(key: &str) -> Option { #[cfg(test)] mod tests { - use super::*; use std::os::unix::ffi::OsStringExt; + use super::*; + #[test] fn env_map_preserves_non_utf8() { let mut env = EnvMap::new(); diff --git a/crates/ghostty-os/src/flatpak.rs b/crates/ghostty-os/src/flatpak.rs index 2224407..8fe0ff9 100644 --- a/crates/ghostty-os/src/flatpak.rs +++ b/crates/ghostty-os/src/flatpak.rs @@ -1,10 +1,15 @@ -use std::collections::HashMap; -use std::os::fd::{AsFd, OwnedFd}; -use std::sync::{Arc, Condvar, Mutex}; +use std::{ + collections::HashMap, + os::fd::{AsFd, OwnedFd}, + sync::{Arc, Condvar, Mutex}, +}; -use zbus::blocking::{Connection, MessageIterator}; -use zbus::zvariant::Fd; -use zbus::{MatchRule, message::Type as MessageType}; +use zbus::{ + MatchRule, + blocking::{Connection, MessageIterator}, + message::Type as MessageType, + zvariant::Fd, +}; const BUS_NAME: &str = "org.freedesktop.Flatpak"; const OBJECT_PATH: &str = "/org/freedesktop/Flatpak/Development"; diff --git a/crates/ghostty-os/src/lib.rs b/crates/ghostty-os/src/lib.rs index eff4c7b..2e8dc9f 100644 --- a/crates/ghostty-os/src/lib.rs +++ b/crates/ghostty-os/src/lib.rs @@ -48,8 +48,16 @@ pub(crate) mod testutil; pub use dbus::launched_by_dbus_activation; pub use desktop::{DesktopEnvironment, desktop_environment, launched_from_desktop}; pub use env::{ - EnvMap, append_env, append_env_always, append_env_os, filter_snap_paths, get_env_map, getenv, - getenv_not_empty, prepend_env, prepend_env_os, + EnvMap, + append_env, + append_env_always, + append_env_os, + filter_snap_paths, + get_env_map, + getenv, + getenv_not_empty, + prepend_env, + prepend_env_os, }; pub use file::{Rlimit, alloc_tmp_dir, fix_max_files, restore_max_files}; pub use flatpak::{FlatpakHostCommand, is_flatpak}; diff --git a/crates/ghostty-os/src/open.rs b/crates/ghostty-os/src/open.rs index 34d349a..6535440 100644 --- a/crates/ghostty-os/src/open.rs +++ b/crates/ghostty-os/src/open.rs @@ -1,5 +1,7 @@ -use std::io; -use std::process::{Command, Stdio}; +use std::{ + io, + process::{Command, Stdio}, +}; /// Kind of URL being opened (`apprt.action.OpenUrl.Kind`). On Linux the /// kind is ignored by [`open`] (it only matters for macOS `open -t`). diff --git a/crates/ghostty-os/src/passwd.rs b/crates/ghostty-os/src/passwd.rs index 52b7eb8..857c8d7 100644 --- a/crates/ghostty-os/src/passwd.rs +++ b/crates/ghostty-os/src/passwd.rs @@ -47,10 +47,13 @@ pub fn get() -> std::io::Result { /// `Pty`) depends on this crate, so a minimal openpt/ptsname pair is opened /// here with rustix instead. Like Zig, only `shell` and `home` are filled in. fn host_entry(name: &str) -> std::io::Result { - use rustix::fs::{Mode, OFlags}; - use rustix::pty::{OpenptFlags, grantpt, openpt, ptsname, unlockpt}; use std::io::Read; + use rustix::{ + fs::{Mode, OFlags}, + pty::{OpenptFlags, grantpt, openpt, ptsname, unlockpt}, + }; + let err = std::io::Error::from; let master = openpt(OpenptFlags::RDWR | OpenptFlags::NOCTTY | OpenptFlags::CLOEXEC).map_err(err)?; diff --git a/crates/ghostty-os/src/path.rs b/crates/ghostty-os/src/path.rs index 51c1826..1146c5a 100644 --- a/crates/ghostty-os/src/path.rs +++ b/crates/ghostty-os/src/path.rs @@ -1,5 +1,4 @@ -use std::io; -use std::os::unix::fs::PermissionsExt; +use std::{io, os::unix::fs::PermissionsExt}; /// Equivalent of `std.fs.max_path_bytes` on Linux. const MAX_PATH_BYTES: usize = 4096; diff --git a/crates/ghostty-os/src/pipe.rs b/crates/ghostty-os/src/pipe.rs index 885220b..8319f97 100644 --- a/crates/ghostty-os/src/pipe.rs +++ b/crates/ghostty-os/src/pipe.rs @@ -1,5 +1,4 @@ -use std::io; -use std::os::fd::OwnedFd; +use std::{io, os::fd::OwnedFd}; /// pipe() for POSIX. Sets CLOEXEC on the file descriptors. /// Returns `(read, write)`. @@ -9,9 +8,10 @@ pub fn pipe() -> io::Result<(OwnedFd, OwnedFd)> { #[cfg(test)] mod tests { - use super::*; use std::io::{Read, Write}; + use super::*; + #[test] fn pipe_roundtrip_cloexec() { let (r, w) = pipe().unwrap(); diff --git a/crates/ghostty-os/src/resourcesdir.rs b/crates/ghostty-os/src/resourcesdir.rs index 968a9ed..59cfbd9 100644 --- a/crates/ghostty-os/src/resourcesdir.rs +++ b/crates/ghostty-os/src/resourcesdir.rs @@ -1,5 +1,4 @@ -use std::io; -use std::path::Path; +use std::{io, path::Path}; use crate::path_join; diff --git a/crates/ghostty-os/src/shell.rs b/crates/ghostty-os/src/shell.rs index 67ba462..0139947 100644 --- a/crates/ghostty-os/src/shell.rs +++ b/crates/ghostty-os/src/shell.rs @@ -1,5 +1,7 @@ -use std::ffi::{CString, NulError}; -use std::io::{self, Write}; +use std::{ + ffi::{CString, NulError}, + io::{self, Write}, +}; /// Builder for constructing space-separated shell command strings. #[derive(Debug, Default, Clone)] diff --git a/crates/ghostty-os/src/string_encoding.rs b/crates/ghostty-os/src/string_encoding.rs index c55a39a..17f7035 100644 --- a/crates/ghostty-os/src/string_encoding.rs +++ b/crates/ghostty-os/src/string_encoding.rs @@ -4,5 +4,8 @@ //! vt cannot depend on os); this module re-exports it. pub use ghostty_vt::string_encoding::{ - Error, printf_q_decode, url_percent_decode, url_percent_encode, + Error, + printf_q_decode, + url_percent_decode, + url_percent_encode, }; diff --git a/crates/ghostty-os/src/systemd.rs b/crates/ghostty-os/src/systemd.rs index 8459ce9..0d71c2c 100644 --- a/crates/ghostty-os/src/systemd.rs +++ b/crates/ghostty-os/src/systemd.rs @@ -70,7 +70,13 @@ pub fn launched_by_systemd() -> bool { /// variable set and these functions essentially become a no-op. pub mod notify { use rustix::net::{ - AddressFamily, SendFlags, SocketAddrUnix, SocketFlags, SocketType, connect, send, + AddressFamily, + SendFlags, + SocketAddrUnix, + SocketFlags, + SocketType, + connect, + send, socket_with, }; @@ -168,9 +174,10 @@ pub mod notify { #[cfg(test)] mod tests { - use super::*; use std::os::unix::net::UnixDatagram; + use super::*; + #[test] fn not_launched_without_env() { temp_env::with_vars( diff --git a/crates/ghostty-os/src/temp_dir.rs b/crates/ghostty-os/src/temp_dir.rs index 2072ba3..20585fd 100644 --- a/crates/ghostty-os/src/temp_dir.rs +++ b/crates/ghostty-os/src/temp_dir.rs @@ -1,9 +1,11 @@ //! Creates a temporary directory at runtime that can be safely used to //! store temporary data and is destroyed on drop. -use std::io; -use std::os::unix::fs::DirBuilderExt; -use std::path::{Path, PathBuf}; +use std::{ + io, + os::unix::fs::DirBuilderExt, + path::{Path, PathBuf}, +}; use crate::file::alloc_tmp_dir; diff --git a/crates/ghostty-os/src/uri.rs b/crates/ghostty-os/src/uri.rs index 711aa5e..0d75931 100644 --- a/crates/ghostty-os/src/uri.rs +++ b/crates/ghostty-os/src/uri.rs @@ -1,8 +1,7 @@ //! URI parsing. Extends a faithful port of Zig's `std.Uri.parse` with the //! additional [`ParseOptions`] from `os/uri.zig`. -use std::borrow::Cow; -use std::fmt::Write as _; +use std::{borrow::Cow, fmt::Write as _}; #[derive(Debug, Clone, Copy, Default)] pub struct ParseOptions { diff --git a/crates/ghostty-os/src/xdg.rs b/crates/ghostty-os/src/xdg.rs index 51fae5b..8f1af85 100644 --- a/crates/ghostty-os/src/xdg.rs +++ b/crates/ghostty-os/src/xdg.rs @@ -3,8 +3,7 @@ use std::ffi::CStr; -use crate::env::getenv_not_empty; -use crate::{homedir, path_join}; +use crate::{env::getenv_not_empty, homedir, path_join}; #[derive(Debug, Clone, Default)] pub struct Options<'a> { diff --git a/crates/ghostty-renderer/src/cell.rs b/crates/ghostty-renderer/src/cell.rs index 02b5c31..9683ae8 100644 --- a/crates/ghostty-renderer/src/cell.rs +++ b/crates/ghostty-renderer/src/cell.rs @@ -6,9 +6,11 @@ use ghostty_terminal::page::Cell as PageCell; -use crate::cursor::Style as CursorStyle; -use crate::opengl::shaders::{CellBg, CellText}; -use crate::size::{CellCountInt, GridSize}; +use crate::{ + cursor::Style as CursorStyle, + opengl::shaders::{CellBg, CellText}, + size::{CellCountInt, GridSize}, +}; /// The possible cell content keys that exist. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -297,9 +299,12 @@ fn is_powerline(ch: u32) -> bool { #[cfg(test)] mod tests { + use ghostty_terminal::{ + render::RenderState, + terminal::{Options, Terminal}, + }; + use super::*; - use ghostty_terminal::render::RenderState; - use ghostty_terminal::terminal::{Options, Terminal}; fn fg(x: u16, y: u16) -> CellText { CellText { diff --git a/crates/ghostty-renderer/src/cursor.rs b/crates/ghostty-renderer/src/cursor.rs index 64e8d1b..8f1f9e0 100644 --- a/crates/ghostty-renderer/src/cursor.rs +++ b/crates/ghostty-renderer/src/cursor.rs @@ -84,10 +84,11 @@ pub fn style(state: &RenderState, opts: StyleOptions) -> Option