Attach to the console of the parent process on windows

This fixes not seeing console output on windows release builds.
This commit is contained in:
Zac Pullar-Strecker 2018-10-18 15:58:58 +13:00 committed by Zac Pullar-Strecker
parent f3a76e24f1
commit a7e59d393d
1 changed files with 14 additions and 1 deletions

View File

@ -21,7 +21,7 @@
// window for the program.
// This is silently ignored on non-windows systems.
// See https://msdn.microsoft.com/en-us/library/4cc7ya5b.aspx for more details.
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
#![windows_subsystem = "windows"]
#[macro_use]
extern crate alacritty;
@ -33,11 +33,18 @@ extern crate dirs;
use std::error::Error;
use std::sync::Arc;
#[cfg(target_os = "macos")]
use std::env;
#[cfg(not(windows))]
use std::os::unix::io::AsRawFd;
#[cfg(windows)]
extern crate winapi;
#[cfg(windows)]
use winapi::um::wincon::{AttachConsole, ATTACH_PARENT_PROCESS};
use alacritty::cli;
use alacritty::config::{self, Config};
use alacritty::display::Display;
@ -52,6 +59,12 @@ use alacritty::tty::{self, process_should_exit};
use alacritty::util::fmt::Red;
fn main() {
// When linked with the windows subsystem windows won't automatically attach
// to the console of the parent process, so we do it explicitly. This fails
// silently if the parent has no console.
#[cfg(windows)]
unsafe {AttachConsole(ATTACH_PARENT_PROCESS);}
// Load command line options and config
let options = cli::Options::load();
let config = load_config(&options).update_dynamic_title(&options);