feat(macos): foundation of the macOS app ported from Swift to Rust

Phase 9, MA1: crates/ghostty-macos (AppKit via objc2; empty stub on
non-Apple targets) ports the foundation of Ghostty 1.3.1's Swift macOS
app (ghostty/macos): main, AppDelegate (+Ghostty) with lifecycle, dock
menu, open-file, notifications, shortcut sync and quit/reopen paths;
MainMenu.xib as generated menu tables built into NSMenus; the
Ghostty.App/Config/Surface wrappers driving libghostty in-process via
ghostty-lib; the generic helpers; scripts/macos-bundle.sh to assemble
Ghostty.app (dry-run on Linux). Feature areas are stubbed for MA2-MA5.
Design and type mapping: docs/rewrite/notes/macos-app-design.md
(App Intents is a Swift-only framework and cannot be ported).

Compile-checked only (no macOS here): just check-macos passes for
aarch64/x86_64-apple-darwin with -D warnings; 125 platform-independent
tests run on Linux.

Test Plan:
- just check-macos
- cargo test -p ghostty-macos
This commit is contained in:
ddidderr committed 2026-10-12 19:25:44 +02:00
1 parent fb79cc8d5c
commit 0137168c66
112 files changed
+18438 -2

No files matched your search

@@ -0,0 +1,64 @@
//! Duration formatting used by `Ghostty.App.commandFinished` notifications.
//! Portable (and tested) so the formatting rules are checked on every target.
use std::time::Duration;
/// `Duration.formatted(.units(allowed: [.hours, .minutes, .seconds,
/// .milliseconds], width: .abbreviated, fractionalPart: .hide))` in the en_US
/// locale: zero-valued units are hidden, units are joined with ", " and use
/// the abbreviations `hr`, `min`, `sec`, `ms` (e.g. "1 hr, 2 min, 3 sec").
/// A zero duration formats as "0 ms" (the smallest allowed unit). Sub
/// millisecond remainders are hidden (truncated).
///
/// Note: the exact rounding of `fractionalPart: .hide` and non-English locales
/// are Foundation behaviour that cannot be verified off macOS.
#[must_use]
pub fn format_duration_abbreviated(duration: Duration) -> String {
let total_ms = duration.as_millis();
let hours = total_ms / 3_600_000;
let minutes = (total_ms / 60_000) % 60;
let seconds = (total_ms / 1000) % 60;
let millis = total_ms % 1000;
let mut parts = Vec::new();
if hours > 0 {
parts.push(format!("{hours} hr"));
}
if minutes > 0 {
parts.push(format!("{minutes} min"));
}
if seconds > 0 {
parts.push(format!("{seconds} sec"));
}
if millis > 0 || parts.is_empty() {
parts.push(format!("{millis} ms"));
}
parts.join(", ")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn duration_formatting() {
assert_eq!(format_duration_abbreviated(Duration::from_secs(5)), "5 sec");
assert_eq!(
format_duration_abbreviated(Duration::from_secs(3723)),
"1 hr, 2 min, 3 sec"
);
assert_eq!(
format_duration_abbreviated(Duration::from_millis(1500)),
"1 sec, 500 ms"
);
assert_eq!(
format_duration_abbreviated(Duration::from_secs(60)),
"1 min"
);
assert_eq!(format_duration_abbreviated(Duration::ZERO), "0 ms");
// Sub-millisecond remainders are hidden.
assert_eq!(
format_duration_abbreviated(Duration::from_nanos(2_000_999_999)),
"2 sec"
);
}
}