feat(os): port Ghostty's Linux OS helpers
Ports ZIG/src/os for Linux into ghostty-os: XDG dirs, home dir, hostname, env/PATH helpers, passwd lookup (via nix), shell detection, resources dir discovery, string encodings (printf-q, URL percent), systemd sd_notify, i18n via gettextrs, xdg-open, desktop/cgroup/kernel info, temp dirs, URI parsing (port of std.Uri incl. Ghostty's extra options), and a zbus-based Flatpak HostCommand implementation. The crate stays free of unsafe. Consequences, all tracked as TODO(integration) in docs/rewrite/notes/ghostty-os.md: - locale::ensure_locale is a no-op (setlocale/setenv are unsafe; GTK calls setlocale itself); setenv/unsetenv are not exposed. - passwd's Flatpak branch needs the termio pty and falls back to the sandbox entry for now. - FlatpakHostCommand's D-Bus path is untested (no portal here). Intentional fix: a leading '@' in NOTIFY_SOCKET is treated as an abstract socket. macOS/Windows/WASM modules are out of scope. Test Plan: - cargo test -p ghostty-os (88 tests) - cargo clippy -p ghostty-os --all-targets -- -D warnings
This commit is contained in:
1 parent
1388f117d3
commit
f8c5ce06d6
30 files changed
+3736
-1
No files matched your search
@@ -0,0 +1,29 @@
|
||||
use std::io::Read;
|
||||
|
||||
/// Returns the kernel release string (`/proc/sys/kernel/osrelease`).
|
||||
pub fn get_kernel_info() -> Option<String> {
|
||||
let file = std::fs::File::open("/proc/sys/kernel/osrelease").ok()?;
|
||||
|
||||
// 128 bytes should be enough to hold the kernel information. Zig's
|
||||
// readToEndAlloc fails if the file is larger than the limit.
|
||||
let mut buf = Vec::new();
|
||||
file.take(129).read_to_end(&mut buf).ok()?;
|
||||
if buf.len() > 128 {
|
||||
return None;
|
||||
}
|
||||
let s = String::from_utf8_lossy(&buf);
|
||||
Some(s.trim_matches(|c: char| c.is_ascii_whitespace()).to_owned())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn read_proc_sys_kernel_osrelease() {
|
||||
let kernel_info = get_kernel_info().unwrap();
|
||||
// Since we can't hardcode the info in tests, just check
|
||||
// if something was read from the file
|
||||
assert!(!kernel_info.is_empty());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user