fix: Windows core build, embedded init, byte-exact paths, version info
Closes the remaining core/lib/termio/GTK rows (final-Z2.md): - ghostty-core compiles for Windows (Unix-only exec fields and file modes gated); checked with cargo check --target x86_64-pc-windows-gnu. - Embedded init: ensure_locale, SIGPIPE ignored in ghostty_init for C/Swift hosts, Apple crash tags; the argv passed to ghostty_init feeds ghostty_config_load_cli_args; ghostty_config_load_file accepts non-UTF-8 paths. - OSC 7 pwd, embedded surface cwd/command/env/initial input, ghostty_surface_text and GTK file drops keep raw bytes. - XTVERSION, TERM_PROGRAM_VERSION, the About dialog and crash metadata use ghostty_build_info instead of hardcoded versions. Test Plan: - cargo test --workspace (3327 passed) - cargo clippy --workspace --all-targets -- -D warnings
This commit is contained in:
1 parent
8519f1ba1b
commit
ebefad5031
30 files changed
+863
-80
No files matched your search
@@ -23,6 +23,7 @@ ghostty-config.workspace = true
|
||||
ghostty-input.workspace = true
|
||||
ghostty-datastruct.workspace = true
|
||||
ghostty-inspector.workspace = true
|
||||
ghostty-build-info.workspace = true
|
||||
ghostty-os.workspace = true
|
||||
ghostty-vt.workspace = true
|
||||
log = "0.4"
|
||||
|
||||
@@ -69,6 +69,17 @@ fn main() {
|
||||
println!("cargo:rerun-if-changed=resources");
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
|
||||
// Source tarballs ship the prebuilt GResource bundle so packagers need
|
||||
// neither blueprint-compiler nor glib-compile-resources (Zig:
|
||||
// `GhosttyDist.Resource` for `ghostty_resources.{c,h}`). As in Zig, it is
|
||||
// never used in a git checkout.
|
||||
println!("cargo:rerun-if-changed=dist/ghostty.gresource");
|
||||
let prebuilt = manifest.join("dist/ghostty.gresource");
|
||||
if prebuilt.is_file() && !manifest.join("../../.git").exists() {
|
||||
std::fs::copy(&prebuilt, out.join("ghostty.gresource")).unwrap();
|
||||
return;
|
||||
}
|
||||
|
||||
let mut xml = String::new();
|
||||
xml.push_str("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<gresources>\n");
|
||||
|
||||
|
||||
@@ -1512,6 +1512,12 @@ impl Surface {
|
||||
clipboard::paste(self, text);
|
||||
}
|
||||
|
||||
/// [`Surface::paste`] for raw bytes (e.g. dropped file names that are
|
||||
/// not valid UTF-8 must reach the pty unchanged).
|
||||
pub fn paste_bytes(&self, bytes: &[u8]) {
|
||||
clipboard::paste_bytes(self, bytes);
|
||||
}
|
||||
|
||||
/// Focus this surface. This properly focuses the input part of
|
||||
/// our surface. (Shadows `WidgetExt::grab_focus` on purpose, like Zig.)
|
||||
pub fn grab_focus(&self) {
|
||||
@@ -2622,6 +2628,26 @@ mod clipboard {
|
||||
}
|
||||
}
|
||||
|
||||
/// Paste explicit bytes. Valid UTF-8 takes the normal text path; other
|
||||
/// bytes use the byte-preserving paste (the confirmation dialog, which
|
||||
/// is text based, carries them with the reversible byte escape).
|
||||
pub(super) fn paste_bytes(surface: &Surface, bytes: &[u8]) {
|
||||
if let Ok(text) = std::str::from_utf8(bytes) {
|
||||
paste(surface, text);
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(core) = surface.core() else { return };
|
||||
match core.complete_paste_bytes(bytes, false) {
|
||||
Ok(()) => {}
|
||||
Err(ClipboardError::UnsafePaste | ClipboardError::UnauthorizedPaste) => {
|
||||
let text = ghostty_os::osbytes::bytes_to_config_string(bytes);
|
||||
show_clipboard_confirmation(surface, ClipboardRequest::Paste, &text);
|
||||
}
|
||||
Err(err) => log::warn!("failed to complete clipboard request err={err}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the specific type of clipboard for a widget.
|
||||
fn get(widget: >k::Widget, clipboard: Clipboard) -> gdk::Clipboard {
|
||||
match clipboard {
|
||||
@@ -2661,7 +2687,13 @@ mod clipboard {
|
||||
|
||||
// Get our text
|
||||
let text = buf.text(&buf.start_iter(), &buf.end_iter(), false);
|
||||
if let Err(err) = core.complete_clipboard_request(req, &text, true) {
|
||||
let result = if matches!(req, ClipboardRequest::Paste) {
|
||||
// Undo the byte escape used for non-UTF-8 pastes.
|
||||
core.complete_paste_bytes(&ghostty_os::osbytes::config_str_to_bytes(&text), true)
|
||||
} else {
|
||||
core.complete_clipboard_request(req, &text, true)
|
||||
};
|
||||
if let Err(err) = result {
|
||||
log::warn!("failed to complete clipboard request: {err}");
|
||||
}
|
||||
});
|
||||
@@ -3375,17 +3407,14 @@ mod imp {
|
||||
let mut w = ghostty_os::ShellEscapeWriter::new(&mut escaped);
|
||||
for file in list.files() {
|
||||
let Some(path) = file.path() else { continue };
|
||||
let path = path.to_string_lossy().into_owned();
|
||||
if let Err(err) = w
|
||||
.write_all(path.as_bytes())
|
||||
.and_then(|()| w.write_all(b"\n"))
|
||||
{
|
||||
// Raw path bytes: non-UTF-8 names must survive.
|
||||
let path = ghostty_os::osbytes::os_bytes(path.as_os_str());
|
||||
if let Err(err) = w.write_all(&path).and_then(|()| w.write_all(b"\n")) {
|
||||
log::error!("unable to write path to buffer: {err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
let string = String::from_utf8_lossy(&escaped).into_owned();
|
||||
this.paste(&string);
|
||||
this.paste_bytes(&escaped);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3397,7 +3426,7 @@ mod imp {
|
||||
{
|
||||
let mut w = ghostty_os::ShellEscapeWriter::new(&mut escaped);
|
||||
if let Err(err) = w
|
||||
.write_all(path.to_string_lossy().as_bytes())
|
||||
.write_all(&ghostty_os::osbytes::os_bytes(path.as_os_str()))
|
||||
.and_then(|()| w.write_all(b"\n"))
|
||||
{
|
||||
log::error!("unable to write path to buffer: {err}");
|
||||
|
||||
@@ -113,11 +113,11 @@ mod imp {
|
||||
return;
|
||||
};
|
||||
if data.exit_code == 0 {
|
||||
banner.set_title("Command succeeded");
|
||||
banner.set_title(&ghostty_os::i18n::tr("Command succeeded"));
|
||||
this.add_css_class("normal");
|
||||
this.remove_css_class("abnormal");
|
||||
} else {
|
||||
banner.set_title("Command failed");
|
||||
banner.set_title(&ghostty_os::i18n::tr("Command failed"));
|
||||
this.remove_css_class("normal");
|
||||
this.add_css_class("abnormal");
|
||||
}
|
||||
|
||||
@@ -1662,7 +1662,7 @@ impl Window {
|
||||
.application_name(name)
|
||||
.developer_name(tr("Ghostty Developers"))
|
||||
.application_icon(icon)
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
.version(ghostty_build_info::VERSION_STRING)
|
||||
.issue_url("https://github.com/ghostty-org/ghostty/issues")
|
||||
.website(website)
|
||||
.build();
|
||||
@@ -1675,7 +1675,7 @@ impl Window {
|
||||
("program-name", &name),
|
||||
("logo-icon-name", &icon),
|
||||
("title", &tr("About Ghostty")),
|
||||
("version", &env!("CARGO_PKG_VERSION")),
|
||||
("version", &ghostty_build_info::VERSION_STRING),
|
||||
("website", &website),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -649,6 +649,11 @@ impl std::fmt::Display for SetTitle {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Pwd {
|
||||
/// The working directory as reported by OSC 7. Zig keeps raw bytes; here
|
||||
/// non-UTF-8 bytes are carried with the reversible escape of
|
||||
/// `ghostty_os::osbytes` (valid UTF-8 is unchanged). Decode with
|
||||
/// `osbytes::config_str_to_bytes` / `config_str_to_os` before using it
|
||||
/// as a path or handing it to C.
|
||||
pub pwd: String,
|
||||
}
|
||||
|
||||
|
||||
@@ -201,6 +201,15 @@ pub trait CoreSurface {
|
||||
data: &str,
|
||||
confirmed: bool,
|
||||
) -> Result<(), ClipboardError>;
|
||||
/// [`CoreSurface::complete_clipboard_request`] for a paste of raw bytes
|
||||
/// (Zig data is `[]const u8`). The default converts lossily.
|
||||
fn complete_paste_bytes(&self, data: &[u8], confirmed: bool) -> Result<(), ClipboardError> {
|
||||
self.complete_clipboard_request(
|
||||
ClipboardRequest::Paste,
|
||||
&String::from_utf8_lossy(data),
|
||||
confirmed,
|
||||
)
|
||||
}
|
||||
/// After the user confirms (`surface.config.clipboard_read = .allow`).
|
||||
fn set_clipboard_read_allowed(&self, allow: bool);
|
||||
/// See [`CoreSurface::set_clipboard_read_allowed`] (`clipboard_write`).
|
||||
|
||||
@@ -14,6 +14,7 @@ ghostty-datastruct.workspace = true
|
||||
ghostty-font.workspace = true
|
||||
ghostty-inspector.workspace = true
|
||||
ghostty-input.workspace = true
|
||||
ghostty-build-info.workspace = true
|
||||
ghostty-os.workspace = true
|
||||
ghostty-renderer.workspace = true
|
||||
ghostty-terminal.workspace = true
|
||||
|
||||
@@ -116,7 +116,7 @@ pub struct GlobalState {
|
||||
static STATE: OnceLock<GlobalState> = OnceLock::new();
|
||||
|
||||
/// Options for [`init`].
|
||||
#[derive(Clone, Copy, Default)]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct InitOptions {
|
||||
/// A CLI action is being executed: disable stderr logging by default
|
||||
/// since the action writes to stderr/stdout itself.
|
||||
@@ -126,6 +126,32 @@ pub struct InitOptions {
|
||||
/// `apprt.runtime.resourcesDir`, e.g. GTK's Flatpak host path lookup).
|
||||
/// `None` uses the generic `ghostty_os::resourcesdir::resources_dir`.
|
||||
pub resources_dir: Option<fn() -> std::io::Result<ResourcesDir>>,
|
||||
|
||||
/// Crash reporting metadata (version, build mode, runtime, font backend
|
||||
/// and renderer tags; Zig: `build_config`). `None` uses
|
||||
/// [`default_crash_options`].
|
||||
pub crash: Option<ghostty_crash::Options>,
|
||||
}
|
||||
|
||||
/// Crash metadata for this build when the caller supplies none: the
|
||||
/// version from the shared build info and the compile-time platform
|
||||
/// defaults (Metal + CoreText on Apple targets, fontconfig + OpenGL
|
||||
/// elsewhere).
|
||||
#[must_use]
|
||||
pub fn default_crash_options() -> ghostty_crash::Options {
|
||||
let mut o = ghostty_crash::Options {
|
||||
release: ghostty_build_info::VERSION_STRING.to_owned(),
|
||||
build_mode: ghostty_build_info::BUILD_MODE
|
||||
.trim_start_matches('.')
|
||||
.to_owned(),
|
||||
..ghostty_crash::Options::default()
|
||||
};
|
||||
if cfg!(target_vendor = "apple") {
|
||||
"none".clone_into(&mut o.app_runtime);
|
||||
"coretext".clone_into(&mut o.font_backend);
|
||||
"metal".clone_into(&mut o.renderer);
|
||||
}
|
||||
o
|
||||
}
|
||||
|
||||
/// The global state. If [`init`] was never called, a default state (no
|
||||
@@ -182,13 +208,17 @@ fn init_with(opts: InitOptions, default_logging: Logging) -> &'static GlobalStat
|
||||
let rlimits = ResourceLimits::init();
|
||||
|
||||
// Initialize our crash reporting.
|
||||
if let Err(err) = ghostty_crash::init(&ghostty_crash::Options {
|
||||
release: ghostty_termio::stream_handler::VERSION_STRING.to_owned(),
|
||||
..ghostty_crash::Options::default()
|
||||
}) {
|
||||
let crash_opts = opts.crash.clone().unwrap_or_else(default_crash_options);
|
||||
if let Err(err) = ghostty_crash::init(&crash_opts) {
|
||||
log::warn!("sentry init failed, no crash capture available err={err}");
|
||||
}
|
||||
|
||||
// We need to make sure the process locale is set properly. Locale
|
||||
// affects a lot of behaviors in a shell.
|
||||
if let Some(locale) = ghostty_os::ensure_locale() {
|
||||
log::debug!("locale set locale={locale}");
|
||||
}
|
||||
|
||||
// Find our resources directory once for the app so every launch
|
||||
// hereafter can use this cached value.
|
||||
let discover = opts
|
||||
@@ -352,6 +382,19 @@ mod tests {
|
||||
assert_eq!(log_scope("other::x"), "other");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn crash_defaults_use_shared_version() {
|
||||
let o = default_crash_options();
|
||||
assert_eq!(o.release, ghostty_build_info::VERSION_STRING);
|
||||
if cfg!(target_vendor = "apple") {
|
||||
assert_eq!(o.renderer, "metal");
|
||||
assert_eq!(o.font_backend, "coretext");
|
||||
assert_eq!(o.app_runtime, "none");
|
||||
} else {
|
||||
assert_eq!(o.renderer, "opengl");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn logging_parse() {
|
||||
assert!(Logging::parse("stderr").stderr);
|
||||
|
||||
@@ -424,6 +424,7 @@ pub fn write_screen_temp_file(
|
||||
loc: WriteScreenLoc,
|
||||
emit: WriteScreenFormat,
|
||||
) -> Result<String, CoreError> {
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::fs::OpenOptionsExt as _;
|
||||
|
||||
// Create a temporary directory to store our scrollback.
|
||||
@@ -432,12 +433,11 @@ pub fn write_screen_temp_file(
|
||||
let file_path = tmp_dir.path().join(&filename);
|
||||
|
||||
let result = (|| -> Result<String, CoreError> {
|
||||
let mut file = std::fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.mode(0o600)
|
||||
.open(&file_path)?;
|
||||
let mut opts = std::fs::OpenOptions::new();
|
||||
opts.write(true).create(true).truncate(true);
|
||||
#[cfg(unix)]
|
||||
opts.mode(0o600);
|
||||
let mut file = opts.open(&file_path)?;
|
||||
file.write_all(contents.as_bytes())?;
|
||||
file.flush()?;
|
||||
Ok(std::fs::canonicalize(&file_path)?
|
||||
@@ -1272,10 +1272,13 @@ mod tests {
|
||||
assert!(path.ends_with("screen.txt"));
|
||||
let read = std::fs::read_to_string(&path).unwrap();
|
||||
assert_eq!(read, s);
|
||||
let mode = std::os::unix::fs::PermissionsExt::mode(
|
||||
&std::fs::metadata(&path).unwrap().permissions(),
|
||||
);
|
||||
assert_eq!(mode & 0o777, 0o600);
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let mode = std::os::unix::fs::PermissionsExt::mode(
|
||||
&std::fs::metadata(&path).unwrap().permissions(),
|
||||
);
|
||||
assert_eq!(mode & 0o777, 0o600);
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(std::path::Path::new(&path).parent().unwrap());
|
||||
}
|
||||
|
||||
|
||||
@@ -215,6 +215,12 @@ impl Surface {
|
||||
}
|
||||
}
|
||||
|
||||
/// [`Surface::complete_clipboard_request`] for a paste of raw bytes
|
||||
/// (Zig passes `[]const u8`; e.g. dropped non-UTF-8 file names).
|
||||
pub fn complete_paste_bytes(&self, data: &[u8], confirmed: bool) -> Result<(), ClipboardError> {
|
||||
self.complete_clipboard_paste(data, confirmed)
|
||||
}
|
||||
|
||||
/// Paste text (also the target of `text_callback`).
|
||||
pub(crate) fn complete_clipboard_paste(
|
||||
&self,
|
||||
@@ -390,7 +396,13 @@ impl Surface {
|
||||
|
||||
/// `textCallback`: text input that is pasted verbatim.
|
||||
pub fn text_callback(&self, text: &str) -> Result<(), ClipboardError> {
|
||||
self.text_callback_bytes(text.as_bytes())
|
||||
}
|
||||
|
||||
/// [`Surface::text_callback`] for raw bytes (Zig takes `[]const u8`;
|
||||
/// the embedded `ghostty_surface_text` forwards the host bytes as is).
|
||||
pub fn text_callback_bytes(&self, text: &[u8]) -> Result<(), ClipboardError> {
|
||||
let _crash = self.crash_guard();
|
||||
self.complete_clipboard_paste(text.as_bytes(), true)
|
||||
self.complete_clipboard_paste(text, true)
|
||||
}
|
||||
}
|
||||
@@ -471,10 +471,15 @@ impl Surface {
|
||||
.and_then(|wd| wd.value())
|
||||
.map(str::to_owned);
|
||||
ecfg.resources_dir = global::state().resources_dir.host().map(str::to_owned);
|
||||
ecfg.rt_pre_exec_info = ghostty_termio::command::RtPreExecInfo::init(&config);
|
||||
ecfg.rt_post_fork_info = ghostty_termio::command::RtPostForkInfo::init(&config);
|
||||
ecfg.create_scope = rt_surface.create_scope_fn();
|
||||
ecfg.restore_rlimit = global::state().rlimits.nofile;
|
||||
// The Windows exec backend has no pre-exec/post-fork hooks,
|
||||
// cgroup scopes or rlimits (Zig: Linux/POSIX only).
|
||||
#[cfg(unix)]
|
||||
{
|
||||
ecfg.rt_pre_exec_info = ghostty_termio::command::RtPreExecInfo::init(&config);
|
||||
ecfg.rt_post_fork_info = ghostty_termio::command::RtPostForkInfo::init(&config);
|
||||
ecfg.create_scope = rt_surface.create_scope_fn();
|
||||
ecfg.restore_rlimit = global::state().rlimits.nofile;
|
||||
}
|
||||
|
||||
let exec = Exec::new(ecfg)?;
|
||||
let args = exec.args().to_vec();
|
||||
@@ -935,7 +940,9 @@ impl Surface {
|
||||
}
|
||||
|
||||
Message::PwdChange(w) => {
|
||||
let pwd = String::from_utf8_lossy(w.slice()).into_owned();
|
||||
// Keep the OSC 7 bytes (see `Pwd`): non-UTF-8 bytes are
|
||||
// carried with the reversible byte escape.
|
||||
let pwd = ghostty_os::osbytes::bytes_to_config_string(w.slice());
|
||||
self.perform(RtAction::Pwd(Pwd { pwd }));
|
||||
}
|
||||
|
||||
@@ -1364,7 +1371,14 @@ impl Surface {
|
||||
pub fn pwd(&self) -> Option<String> {
|
||||
let t = self.lock_terminal();
|
||||
let pwd = t.get_pwd()?;
|
||||
Some(String::from_utf8_lossy(pwd).into_owned())
|
||||
Some(ghostty_os::osbytes::bytes_to_config_string(pwd))
|
||||
}
|
||||
|
||||
/// The raw bytes of [`Surface::pwd`] (Zig returns the OSC 7 bytes as is).
|
||||
#[must_use]
|
||||
pub fn pwd_bytes(&self) -> Option<Vec<u8>> {
|
||||
let t = self.lock_terminal();
|
||||
t.get_pwd().map(<[u8]>::to_vec)
|
||||
}
|
||||
|
||||
/// Returns the x/y coordinate of where the IME (Input Method Editor)
|
||||
@@ -2055,6 +2069,10 @@ impl CoreSurface for Surface {
|
||||
Surface::complete_clipboard_request(self, req, data, confirmed)
|
||||
}
|
||||
|
||||
fn complete_paste_bytes(&self, data: &[u8], confirmed: bool) -> Result<(), ClipboardError> {
|
||||
Surface::complete_paste_bytes(self, data, confirmed)
|
||||
}
|
||||
|
||||
fn set_clipboard_read_allowed(&self, allow: bool) {
|
||||
use ghostty_config::types_b::ClipboardAccess;
|
||||
self.set_config_clipboard(
|
||||
|
||||
@@ -1664,7 +1664,7 @@ impl Surface {
|
||||
sel: link.selection,
|
||||
trim: false,
|
||||
});
|
||||
let pwd = t.get_pwd().map(|p| String::from_utf8_lossy(p).into_owned());
|
||||
let pwd = t.get_pwd().map(ghostty_os::osbytes::bytes_to_config_string);
|
||||
resolve_path_for_opening(pwd.as_deref(), &str).unwrap_or(str)
|
||||
}
|
||||
|
||||
|
||||
@@ -114,6 +114,24 @@ fn pwd_osc7() {
|
||||
assert_eq!(h.surface.pwd().as_deref(), Some("/tmp/a b"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pwd_osc7_keeps_non_utf8_bytes() {
|
||||
let h = harness!(Harness::recorder(
|
||||
r"\033]7;file://localhost/tmp/a%%FFb\033\\",
|
||||
&[]
|
||||
));
|
||||
let pwd = h.wait_action("pwd", |a| match a {
|
||||
Action::Pwd(p) if !p.pwd.is_empty() => Some(p.pwd.clone()),
|
||||
_ => None,
|
||||
});
|
||||
assert_eq!(
|
||||
ghostty_os::osbytes::config_str_to_bytes(&pwd),
|
||||
b"/tmp/a\xffb"
|
||||
);
|
||||
assert_eq!(h.surface.pwd_bytes().as_deref(), Some(&b"/tmp/a\xffb"[..]));
|
||||
assert_eq!(h.surface.pwd().as_deref(), Some(pwd.as_str()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bell_rings_once_per_burst() {
|
||||
let h = harness!(Harness::recorder(r"\007", &[]));
|
||||
|
||||
@@ -23,6 +23,7 @@ ghostty-bench.workspace = true
|
||||
ghostty-cli.workspace = true
|
||||
ghostty-config.workspace = true
|
||||
ghostty-core.workspace = true
|
||||
ghostty-crash.workspace = true
|
||||
ghostty-input.workspace = true
|
||||
ghostty-inspector.workspace = true
|
||||
ghostty-os.workspace = true
|
||||
@@ -31,6 +32,9 @@ ghostty-terminal.workspace = true
|
||||
ghostty-vt.workspace = true
|
||||
log = "0.4.34"
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
libc = "0.2.190"
|
||||
|
||||
[target.'cfg(target_vendor = "apple")'.dependencies]
|
||||
block2 = "0.6.2"
|
||||
dispatch2 = "0.3.1"
|
||||
@@ -40,6 +44,7 @@ objc2-foundation = "0.3.2"
|
||||
objc2-metal = { version = "0.3.2", features = ["block2"] }
|
||||
|
||||
[dev-dependencies]
|
||||
ghostty-build-info.workspace = true
|
||||
tempfile = "3"
|
||||
|
||||
# The workspace forbids `unsafe`; this crate is the C ABI boundary, so it
|
||||
|
||||
@@ -36,7 +36,14 @@ pub struct Keep {
|
||||
impl Keep {
|
||||
/// A NUL terminated copy of `s` (interior NULs are dropped).
|
||||
fn cstr(&mut self, s: &str) -> *const c_char {
|
||||
let c = CString::new(s.replace('\0', "")).unwrap_or_default();
|
||||
self.cstr_bytes(s.as_bytes())
|
||||
}
|
||||
|
||||
/// [`Keep::cstr`] for raw bytes.
|
||||
fn cstr_bytes(&mut self, s: &[u8]) -> *const c_char {
|
||||
let mut s = s.to_vec();
|
||||
s.retain(|&b| b != 0);
|
||||
let c = CString::new(s).unwrap_or_default();
|
||||
let ptr = c.as_ptr();
|
||||
// The heap buffer of a CString doesn't move when the Vec grows.
|
||||
self.strings.push(c);
|
||||
@@ -123,7 +130,9 @@ pub fn action_to_c(action: &Action, keep: &mut Keep) -> ghostty_action_s {
|
||||
Action::SetTitle(t) => v.set_title.title = keep.cstr(&t.title),
|
||||
Action::SetTabTitle(t) => v.set_tab_title.title = keep.cstr(&t.title),
|
||||
Action::PromptTitle(p) => v.prompt_title = *p as c_int,
|
||||
Action::Pwd(p) => v.pwd.pwd = keep.cstr(&p.pwd),
|
||||
Action::Pwd(p) => {
|
||||
v.pwd.pwd = keep.cstr_bytes(&ghostty_os::osbytes::config_str_to_bytes(&p.pwd));
|
||||
}
|
||||
Action::MouseShape(s) => v.mouse_shape = *s as c_int,
|
||||
Action::MouseVisibility(m) => v.mouse_visibility = *m as c_int,
|
||||
Action::MouseOverLink(l) => {
|
||||
|
||||
@@ -249,9 +249,10 @@ pub unsafe extern "C" fn ghostty_config_load_file(ptr: ghostty_config_t, path: *
|
||||
return;
|
||||
}
|
||||
// SAFETY: `path` is NUL terminated.
|
||||
let path = unsafe { CStr::from_ptr(path) }
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
// Non-UTF-8 file names are valid on Unix; keep the bytes (reversible
|
||||
// escape understood by the config file loader).
|
||||
let path =
|
||||
ghostty_os::osbytes::bytes_to_config_string(unsafe { CStr::from_ptr(path) }.to_bytes());
|
||||
if let Err(err) = c.config.load_file(&path) {
|
||||
log::error!("error loading config from file path={path} err={err}");
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ use ghostty_input::{
|
||||
binding::Action as BindingAction,
|
||||
keycodes,
|
||||
};
|
||||
use ghostty_os::osbytes;
|
||||
use ghostty_terminal::{
|
||||
point::{Coordinate, Point, Tag as PointTag},
|
||||
selection::Selection,
|
||||
@@ -884,17 +885,22 @@ fn string_escape(input: &str) -> String {
|
||||
unsafe fn apply_surface_options(config: &mut Config, opts: &ghostty_surface_config_s) {
|
||||
// If we have a working directory from the options then we set it.
|
||||
// SAFETY: per the function contract.
|
||||
if let Some(wd) =
|
||||
unsafe { cstr(opts.working_directory) }.map(|c| c.to_string_lossy().into_owned())
|
||||
if let Some(wd) = unsafe { cstr(opts.working_directory) }.map(CStr::to_bytes)
|
||||
&& !wd.is_empty()
|
||||
{
|
||||
match std::fs::metadata(&wd) {
|
||||
Err(err) => log::warn!("error opening requested working directory dir={wd} err={err}"),
|
||||
// Raw bytes are kept (reversible escape in the String based config).
|
||||
let wd_str = osbytes::bytes_to_config_string(wd);
|
||||
let wd_os = osbytes::os_from_bytes(wd.to_vec());
|
||||
let wd_disp = String::from_utf8_lossy(wd);
|
||||
match std::fs::metadata(&wd_os) {
|
||||
Err(err) => {
|
||||
log::warn!("error opening requested working directory dir={wd_disp} err={err}");
|
||||
}
|
||||
Ok(m) if !m.is_dir() => {
|
||||
log::warn!("requested working directory is not a directory dir={wd}");
|
||||
log::warn!("requested working directory is not a directory dir={wd_disp}");
|
||||
}
|
||||
Ok(_) => {
|
||||
let mut wd_val = WorkingDirectory::Path(wd);
|
||||
let mut wd_val = WorkingDirectory::Path(wd_str);
|
||||
wd_val.finalize();
|
||||
config.working_directory = Some(wd_val);
|
||||
}
|
||||
@@ -903,10 +909,10 @@ unsafe fn apply_surface_options(config: &mut Config, opts: &ghostty_surface_conf
|
||||
|
||||
// If we have a command from the options then we set it.
|
||||
// SAFETY: per the function contract.
|
||||
if let Some(cmd) = unsafe { cstr(opts.command) }.map(|c| c.to_string_lossy().into_owned())
|
||||
if let Some(cmd) = unsafe { cstr(opts.command) }.map(CStr::to_bytes)
|
||||
&& !cmd.is_empty()
|
||||
{
|
||||
config.command = Some(Command::Shell(cmd));
|
||||
config.command = Some(Command::Shell(osbytes::bytes_to_config_string(cmd)));
|
||||
config.wait_after_command = true;
|
||||
}
|
||||
|
||||
@@ -919,7 +925,10 @@ unsafe fn apply_surface_options(config: &mut Config, opts: &ghostty_surface_conf
|
||||
let (Some(k), Some(v)) = (unsafe { cstr(var.key) }, unsafe { cstr(var.value) }) else {
|
||||
continue;
|
||||
};
|
||||
config.env.put(&k.to_string_lossy(), &v.to_string_lossy());
|
||||
config.env.put(
|
||||
&osbytes::bytes_to_config_string(k.to_bytes()),
|
||||
&osbytes::bytes_to_config_string(v.to_bytes()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -929,10 +938,9 @@ unsafe fn apply_surface_options(config: &mut Config, opts: &ghostty_surface_conf
|
||||
// We need to escape the string because the "raw" field expects a
|
||||
// Zig string.
|
||||
config.input.list.clear();
|
||||
config
|
||||
.input
|
||||
.list
|
||||
.push(ReadableIO::Raw(string_escape(&input.to_string_lossy())));
|
||||
config.input.list.push(ReadableIO::Raw(string_escape(
|
||||
&osbytes::bytes_to_config_string(input.to_bytes()),
|
||||
)));
|
||||
}
|
||||
|
||||
// Wait after command
|
||||
@@ -1107,7 +1115,7 @@ pub unsafe extern "C" fn ghostty_surface_inherited_config(
|
||||
}
|
||||
|
||||
if should_inherit_working_directory(context, &config)
|
||||
&& let Some(cwd) = core.pwd()
|
||||
&& let Some(cwd) = core.pwd_bytes()
|
||||
&& let Ok(c) = CString::new(cwd)
|
||||
{
|
||||
let mut keep = s.inherited_wd.borrow_mut();
|
||||
@@ -1593,7 +1601,7 @@ pub unsafe extern "C" fn ghostty_surface_text(
|
||||
// SAFETY: `text` points to `len` readable bytes.
|
||||
unsafe { std::slice::from_raw_parts(text.cast::<u8>(), len) }
|
||||
};
|
||||
if let Err(err) = core.text_callback(&String::from_utf8_lossy(bytes)) {
|
||||
if let Err(err) = core.text_callback_bytes(bytes) {
|
||||
log::error!("error in key callback err={err}");
|
||||
}
|
||||
}
|
||||
@@ -2155,3 +2163,61 @@ mod darwin {
|
||||
fill_text(core, t, sel, result)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
|
||||
use super::*;
|
||||
use crate::types::ghostty_env_var_s;
|
||||
|
||||
/// Surface options are raw C bytes in Zig; non-UTF-8 values must reach
|
||||
/// the config unchanged (reversible byte escape).
|
||||
#[test]
|
||||
fn surface_options_keep_non_utf8_bytes() {
|
||||
let td = tempfile::tempdir().unwrap();
|
||||
let mut dir = td.path().as_os_str().as_bytes().to_vec();
|
||||
dir.extend_from_slice(b"/d\xff");
|
||||
std::fs::create_dir(std::ffi::OsStr::from_bytes(&dir)).unwrap();
|
||||
|
||||
let wd = CString::new(dir.clone()).unwrap();
|
||||
let cmd = CString::new(&b"echo \xfe"[..]).unwrap();
|
||||
let key = CString::new(&b"K\xfd"[..]).unwrap();
|
||||
let val = CString::new(&b"v\xfc"[..]).unwrap();
|
||||
let input = CString::new(&b"in\xff\n"[..]).unwrap();
|
||||
let mut env = [ghostty_env_var_s {
|
||||
key: key.as_ptr(),
|
||||
value: val.as_ptr(),
|
||||
}];
|
||||
|
||||
// SAFETY: all-zero is a valid value (null pointers, 0 enums).
|
||||
let mut opts: ghostty_surface_config_s = unsafe { std::mem::zeroed() };
|
||||
opts.working_directory = wd.as_ptr();
|
||||
opts.command = cmd.as_ptr();
|
||||
opts.env_vars = env.as_mut_ptr();
|
||||
opts.env_var_count = 1;
|
||||
opts.initial_input = input.as_ptr();
|
||||
|
||||
let mut config = Config::default();
|
||||
// SAFETY: the pointers above are valid NUL terminated strings.
|
||||
unsafe { apply_surface_options(&mut config, &opts) };
|
||||
|
||||
let got_wd = config
|
||||
.working_directory
|
||||
.as_ref()
|
||||
.and_then(|w| w.value())
|
||||
.unwrap();
|
||||
assert_eq!(osbytes::config_str_to_bytes(got_wd), dir);
|
||||
let Some(Command::Shell(c)) = &config.command else {
|
||||
panic!("no command");
|
||||
};
|
||||
assert_eq!(osbytes::config_str_to_bytes(c), b"echo \xfe");
|
||||
let (k, v) = config.env.iter().next().unwrap();
|
||||
assert_eq!(osbytes::config_str_to_bytes(k), b"K\xfd");
|
||||
assert_eq!(osbytes::config_str_to_bytes(v), b"v\xfc");
|
||||
assert!(matches!(
|
||||
config.input.list.first(),
|
||||
Some(ReadableIO::Raw(_))
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,13 @@
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
ffi::{CStr, CString, c_char, c_int},
|
||||
ffi::{CStr, CString, OsString, c_char, c_int},
|
||||
sync::{Mutex, OnceLock},
|
||||
};
|
||||
|
||||
use ghostty_cli::build_info::{self, BuildInfo};
|
||||
use ghostty_core::global::{self, InitOptions};
|
||||
use ghostty_os::osbytes;
|
||||
|
||||
use crate::types::{build_mode, ghostty_info_s, ghostty_string_s};
|
||||
|
||||
@@ -77,7 +78,8 @@ pub(crate) fn alloc_c_text(bytes: &[u8]) -> *const c_char {
|
||||
/// `argv` must be null or point to `argc` valid NUL terminated strings.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn ghostty_init(argc: usize, argv: *mut *mut c_char) -> c_int {
|
||||
let mut args = Vec::with_capacity(argc);
|
||||
// Raw argument bytes (Zig: `std.os.argv = argv[0..argc]`).
|
||||
let mut raw: Vec<OsString> = Vec::with_capacity(argc);
|
||||
if !argv.is_null() {
|
||||
for i in 0..argc {
|
||||
// SAFETY: the caller guarantees `argv[0..argc]` are valid.
|
||||
@@ -87,10 +89,18 @@ pub unsafe extern "C" fn ghostty_init(argc: usize, argv: *mut *mut c_char) -> c_
|
||||
}
|
||||
// SAFETY: each argv entry is a NUL terminated string.
|
||||
let c = unsafe { CStr::from_ptr(p) };
|
||||
args.push(c.to_string_lossy().into_owned());
|
||||
raw.push(osbytes::os_from_bytes(c.to_bytes().to_vec()));
|
||||
}
|
||||
}
|
||||
|
||||
// Later config CLI loading (`ghostty_config_load_cli_args`) must see
|
||||
// these arguments rather than the process arguments.
|
||||
ghostty_os::args::set_argv(raw.clone());
|
||||
let args: Vec<String> = raw
|
||||
.iter()
|
||||
.map(|a| osbytes::os_to_config_string(a))
|
||||
.collect();
|
||||
|
||||
// We first try to parse any action that we may be executing.
|
||||
let action = match ghostty_cli::ghostty::detect(&args) {
|
||||
Ok(a) => a,
|
||||
@@ -101,16 +111,48 @@ pub unsafe extern "C" fn ghostty_init(argc: usize, argv: *mut *mut c_char) -> c_
|
||||
};
|
||||
let _ = ARGS.set(args);
|
||||
|
||||
// `+version` and friends report the library build.
|
||||
build_info::set(lib_build_info());
|
||||
|
||||
// Setup our signal handlers before logging (Zig: `initSignals`). A C or
|
||||
// Swift host does not get the Rust runtime's SIGPIPE ignore.
|
||||
init_signals();
|
||||
|
||||
global::init_lib(InitOptions {
|
||||
action: action.is_some(),
|
||||
resources_dir: None,
|
||||
crash: Some(lib_crash_options()),
|
||||
});
|
||||
|
||||
// `+version` and friends report the library build.
|
||||
build_info::set(lib_build_info());
|
||||
0
|
||||
}
|
||||
|
||||
/// Ignore SIGPIPE: it is common with how termio shuts down read threads
|
||||
/// (Zig: `GlobalState.initSignals`; not on Windows).
|
||||
fn init_signals() {
|
||||
#[cfg(unix)]
|
||||
// SAFETY: installing SIG_IGN for SIGPIPE has no memory safety impact.
|
||||
unsafe {
|
||||
libc::signal(libc::SIGPIPE, libc::SIG_IGN);
|
||||
}
|
||||
}
|
||||
|
||||
/// Crash metadata for the library artifact: no app runtime, CoreText +
|
||||
/// Metal on Apple targets (so the GTK / fontconfig / OpenGL defaults are
|
||||
/// not reported for the macOS app).
|
||||
fn lib_crash_options() -> ghostty_crash::Options {
|
||||
let info = build_info::get();
|
||||
let tag = |s: &str| s.trim_start_matches('.').to_owned();
|
||||
let mut o = global::default_crash_options();
|
||||
o.release.clone_from(&info.version_string);
|
||||
o.app_runtime = tag(&lib_build_info().app_runtime);
|
||||
if cfg!(target_vendor = "apple") {
|
||||
"coretext".clone_into(&mut o.font_backend);
|
||||
"metal".clone_into(&mut o.renderer);
|
||||
}
|
||||
o
|
||||
}
|
||||
|
||||
/// The build info of the library (Zig: `build_config` for the lib artifact:
|
||||
/// no app runtime, CoreText + Metal on Apple targets).
|
||||
fn lib_build_info() -> BuildInfo {
|
||||
|
||||
@@ -43,7 +43,10 @@ fn host_program_passes() {
|
||||
"host failed\nstdout:\n{stdout}\nstderr:\n{stderr}"
|
||||
);
|
||||
assert!(stdout.contains("OK"), "stdout:\n{stdout}");
|
||||
assert!(stdout.contains("version=1.3.1"), "stdout:\n{stdout}");
|
||||
assert!(
|
||||
stdout.contains(&format!("version={}", ghostty_build_info::VERSION_STRING)),
|
||||
"stdout:\n{stdout}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -55,7 +58,10 @@ fn cli_try_action_runs_version_and_exits() {
|
||||
"stderr: {}",
|
||||
String::from_utf8_lossy(&out.stderr)
|
||||
);
|
||||
assert!(stdout.starts_with("Ghostty 1.3.1"), "stdout:\n{stdout}");
|
||||
assert!(
|
||||
stdout.starts_with(&format!("Ghostty {}", ghostty_build_info::VERSION_STRING)),
|
||||
"stdout:\n{stdout}"
|
||||
);
|
||||
// The action ran instead of the rest of the program.
|
||||
assert!(!stdout.contains("OK"));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
//! `ghostty_init(argc, argv)` semantics from `main_c.zig`: the supplied
|
||||
//! argument vector (not the process arguments) feeds the later config CLI
|
||||
//! loading, and SIGPIPE is ignored for C / Swift hosts.
|
||||
#![cfg(unix)]
|
||||
#![allow(
|
||||
unsafe_code,
|
||||
clippy::unwrap_used,
|
||||
clippy::expect_used,
|
||||
clippy::undocumented_unsafe_blocks
|
||||
)]
|
||||
|
||||
use std::ffi::{CString, c_char};
|
||||
|
||||
use ghostty::{config_capi::*, main_c::ghostty_init, types::ghostty_config_t};
|
||||
|
||||
fn get_bool(cfg: ghostty_config_t, key: &str) -> bool {
|
||||
let mut out = false;
|
||||
let ok =
|
||||
unsafe { ghostty_config_get(cfg, (&raw mut out).cast(), key.as_ptr().cast(), key.len()) };
|
||||
assert!(ok);
|
||||
out
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn init_argv_feeds_config_cli_and_ignores_sigpipe() {
|
||||
// Start from the default disposition so that the check is meaningful.
|
||||
unsafe { libc::signal(libc::SIGPIPE, libc::SIG_DFL) };
|
||||
|
||||
// Not the process argv: the test harness argv has no `--maximize`.
|
||||
let owned: Vec<CString> = [&b"ghostty"[..], b"--maximize=true"]
|
||||
.iter()
|
||||
.map(|a| CString::new(*a).unwrap())
|
||||
.collect();
|
||||
let mut argv: Vec<*mut c_char> = owned.iter().map(|c| c.as_ptr().cast_mut()).collect();
|
||||
assert_eq!(unsafe { ghostty_init(argv.len(), argv.as_mut_ptr()) }, 0);
|
||||
|
||||
let mut sa: libc::sigaction = unsafe { std::mem::zeroed() };
|
||||
unsafe { libc::sigaction(libc::SIGPIPE, std::ptr::null(), &mut sa) };
|
||||
assert_eq!(sa.sa_sigaction, libc::SIG_IGN);
|
||||
|
||||
let cfg = ghostty_config_new();
|
||||
unsafe { ghostty_config_load_cli_args(cfg) };
|
||||
assert!(get_bool(cfg, "maximize"));
|
||||
unsafe { ghostty_config_free(cfg) };
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_load_file_accepts_non_utf8_path() {
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut name = dir.path().as_os_str().as_bytes().to_vec();
|
||||
name.extend_from_slice(b"/cfg\xff");
|
||||
let path = std::ffi::OsStr::from_bytes(&name);
|
||||
std::fs::write(path, "maximize = true\n").unwrap();
|
||||
|
||||
let cfg = ghostty_config_new();
|
||||
let c = CString::new(name).unwrap();
|
||||
unsafe { ghostty_config_load_file(cfg, c.as_ptr()) };
|
||||
assert!(get_bool(cfg, "maximize"));
|
||||
unsafe { ghostty_config_free(cfg) };
|
||||
}
|
||||
@@ -10,6 +10,7 @@ ghostty-apprt.workspace = true
|
||||
ghostty-config.workspace = true
|
||||
ghostty-crash.workspace = true
|
||||
ghostty-datastruct.workspace = true
|
||||
ghostty-build-info.workspace = true
|
||||
ghostty-os.workspace = true
|
||||
ghostty-renderer.workspace = true
|
||||
ghostty-terminal.workspace = true
|
||||
|
||||
@@ -18,7 +18,7 @@ use std::{
|
||||
panic::{AssertUnwindSafe, catch_unwind},
|
||||
};
|
||||
|
||||
use ghostty_os::file::Rlimit;
|
||||
use ghostty_os::{file::Rlimit, osbytes::config_str_to_bytes};
|
||||
use rustix::{
|
||||
io::Errno,
|
||||
process::{self, WaitOptions},
|
||||
@@ -264,13 +264,13 @@ impl Command {
|
||||
}
|
||||
|
||||
fn prepare(&self) -> Result<Prepared, NulError> {
|
||||
let path = CString::new(self.path.as_str())?;
|
||||
let path = CString::new(config_str_to_bytes(&self.path))?;
|
||||
let argv = if self.args.is_empty() {
|
||||
vec![path.clone()]
|
||||
} else {
|
||||
self.args
|
||||
.iter()
|
||||
.map(|a| CString::new(a.as_str()))
|
||||
.map(|a| CString::new(config_str_to_bytes(a)))
|
||||
.collect::<Result<_, _>>()?
|
||||
};
|
||||
let envp = match &self.env {
|
||||
@@ -297,7 +297,7 @@ impl Command {
|
||||
#[cfg(target_vendor = "apple")]
|
||||
let candidates = exec_candidates(&self.path, std::env::var("PATH").ok().as_deref())
|
||||
.into_iter()
|
||||
.map(CString::new)
|
||||
.map(|c| CString::new(config_str_to_bytes(&c)))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
Ok(Prepared {
|
||||
path,
|
||||
@@ -315,7 +315,10 @@ impl Command {
|
||||
pub fn start(&mut self) -> Result<(), StartError> {
|
||||
// IMPORTANT: do all allocation prior to the fork().
|
||||
let prep = self.prepare()?;
|
||||
let cwd = self.cwd.as_deref().and_then(|c| CString::new(c).ok());
|
||||
let cwd = self
|
||||
.cwd
|
||||
.as_deref()
|
||||
.and_then(|c| CString::new(config_str_to_bytes(c)).ok());
|
||||
|
||||
let mut argv_ptrs: Vec<*const c_char> = prep.argv.iter().map(|c| c.as_ptr()).collect();
|
||||
argv_ptrs.push(std::ptr::null());
|
||||
@@ -876,6 +879,35 @@ mod tests {
|
||||
assert_eq!("/tmp\n", read_all(stdout));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_utf8_cwd_and_args_are_preserved() {
|
||||
use ghostty_os::osbytes::{bytes_to_config_string, os_from_bytes};
|
||||
let td = TempDir::init().unwrap();
|
||||
let stdout = test_file(&td, "stdout.txt");
|
||||
|
||||
// A directory whose name is not valid UTF-8, handed over with the
|
||||
// reversible byte escape used by the String based layers.
|
||||
let mut raw = ghostty_os::osbytes::os_bytes(td.path().as_os_str());
|
||||
raw.extend_from_slice(b"/d\xff");
|
||||
std::fs::create_dir(os_from_bytes(raw.clone())).unwrap();
|
||||
|
||||
let mut cmd = Command::new("/bin/sh", &["/bin/sh", "-c", "pwd -P; printf %s \"$0\""]);
|
||||
cmd.args.push(bytes_to_config_string(b"a\xffb"));
|
||||
cmd.stdout = Some(stdout.try_clone().unwrap().into());
|
||||
cmd.cwd = Some(bytes_to_config_string(&raw));
|
||||
cmd.start().unwrap();
|
||||
assert_eq!(cmd.wait(true).unwrap(), Exit::Exited(0));
|
||||
|
||||
let mut bytes = Vec::new();
|
||||
std::io::Read::read_to_end(
|
||||
&mut std::fs::File::open(td.path().join("stdout.txt")).unwrap(),
|
||||
&mut bytes,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(bytes.windows(2).any(|w| w == b"d\xff"), "{bytes:?}");
|
||||
assert!(bytes.ends_with(b"a\xffb"), "{bytes:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_cwd_is_ignored() {
|
||||
let td = TempDir::init().unwrap();
|
||||
|
||||
@@ -181,7 +181,7 @@ impl Exec {
|
||||
// set that on the terminal now. This allows rapidly initializing
|
||||
// new surfaces to use the proper pwd.
|
||||
if let Some(cwd) = &self.subprocess.cwd
|
||||
&& let Err(err) = term.set_pwd(cwd.as_bytes())
|
||||
&& let Err(err) = term.set_pwd(&ghostty_os::osbytes::config_str_to_bytes(cwd))
|
||||
{
|
||||
log::warn!("error setting initial pwd err={err:?}");
|
||||
}
|
||||
@@ -907,7 +907,10 @@ impl Subprocess {
|
||||
|
||||
// Add the environment variables that override any others.
|
||||
for (k, v) in cfg.env_override.iter() {
|
||||
env.insert(k, v);
|
||||
env.insert(
|
||||
ghostty_os::osbytes::config_str_to_os(k),
|
||||
ghostty_os::osbytes::config_str_to_os(v),
|
||||
);
|
||||
}
|
||||
|
||||
// Build our args list
|
||||
@@ -925,7 +928,7 @@ impl Subprocess {
|
||||
// https://github.com/kovidgoyal/kitty/issues/1595
|
||||
// https://github.com/ghostty-org/ghostty/discussions/7769
|
||||
if let Some(pwd) = &cwd {
|
||||
env.insert("PWD", pwd.clone());
|
||||
env.insert("PWD", ghostty_os::osbytes::config_str_to_os(pwd));
|
||||
}
|
||||
|
||||
Ok(Subprocess {
|
||||
@@ -1037,7 +1040,7 @@ impl Subprocess {
|
||||
}
|
||||
}
|
||||
Some(proposed) => {
|
||||
if std::path::Path::new(proposed).exists() {
|
||||
if std::path::Path::new(&ghostty_os::osbytes::config_str_to_os(proposed)).exists() {
|
||||
Some(proposed.clone())
|
||||
} else {
|
||||
log::warn!("cannot access cwd, ignoring: {proposed}");
|
||||
|
||||
@@ -86,7 +86,7 @@ use crate::{
|
||||
};
|
||||
|
||||
/// `build_config.version_string`.
|
||||
pub const VERSION_STRING: &str = "1.3.1";
|
||||
pub const VERSION_STRING: &str = ghostty_build_info::VERSION_STRING;
|
||||
|
||||
/// The long-lived state of the handler (everything but the terminal).
|
||||
pub struct HandlerState {
|
||||
@@ -1693,7 +1693,11 @@ mod tests {
|
||||
fn xtversion() {
|
||||
let mut h = Harness::new();
|
||||
h.feed(b"\x1b[>q");
|
||||
assert_eq!(b"\x1bP>|ghostty 1.3.1\x1b\\".as_slice(), h.written());
|
||||
let want = format!(
|
||||
"\x1bP>|ghostty {}\x1b\\",
|
||||
ghostty_build_info::VERSION_STRING
|
||||
);
|
||||
assert_eq!(want.as_bytes(), h.written());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -173,7 +173,7 @@ impl ThreadEnterState {
|
||||
let mut out = Vec::with_capacity(self.input.len());
|
||||
for item in &self.input {
|
||||
match item {
|
||||
ReadableIO::Raw(v) => out.push(v.clone().into_bytes()),
|
||||
ReadableIO::Raw(v) => out.push(ghostty_os::osbytes::config_str_to_bytes(v)),
|
||||
ReadableIO::Path(path) => {
|
||||
let f = std::fs::File::open(path).map_err(|err| {
|
||||
log::warn!("failed to open input file={path} err={err}");
|
||||
|
||||
Reference in new issue
Block a user