Fix first startup on macOS 2

This commit is contained in:
Uber Veng
2026-05-29 13:17:30 +07:00
parent 03e1311e90
commit 80d2e7fd71
3 changed files with 16 additions and 2 deletions

View File

@@ -12,6 +12,8 @@ mod updater;
use std::io;
use anyhow::Result;
#[cfg(unix)]
use libc;
use crossterm::{
event::{DisableMouseCapture, EnableMouseCapture},
execute,
@@ -29,6 +31,18 @@ async fn main() -> Result<()> {
config::Config::create_with_endpoint(&url, &name)?
};
// Before initializing the TUI, ensure our process group is the terminal's
// foreground group. When launched from a non-interactive install script on
// macOS, the parent shell may not have granted terminal ownership, causing
// crossterm's kqueue-based input reader to fail silently.
#[cfg(unix)]
{
use std::os::unix::io::AsRawFd;
if let Ok(tty) = std::fs::File::open("/dev/tty") {
unsafe { libc::tcsetpgrp(tty.as_raw_fd(), libc::getpgrp()); }
}
}
enable_raw_mode()?;
let mut stdout = io::stdout();
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;