diff options
author | Zac Pullar-Strecker <zacps@users.noreply.github.com> | 2018-10-17 06:02:52 +1300 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2018-10-16 10:02:52 -0700 |
commit | 15e0deae2b49078b47a782679300cdf99d9ce687 (patch) | |
tree | 8175fbed0def1af08cd2db41583975adbb27dff1 /src/main.rs | |
parent | b41c6b736d67d61e92b174dfea58ae46813934cd (diff) | |
download | alacritty-15e0deae2b49078b47a782679300cdf99d9ce687.tar.gz alacritty-15e0deae2b49078b47a782679300cdf99d9ce687.zip |
Add support for Windows (#1374)
Initial support for Windows is implemented using the winpty translation
layer. Clipboard support for Windows is provided through the `clipboard`
crate, and font rasterization is provided by RustType.
The tty.rs file has been split into OS-specific files to separate
standard pty handling from the winpty implementation.
Several binary components are fetched via build script on windows
including libclang and winpty. These could be integrated more directly
in the future either by building those dependencies as part of the
Alacritty build process or by leveraging git lfs to store the artifacts.
Fixes #28.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 65 |
1 files changed, 55 insertions, 10 deletions
diff --git a/src/main.rs b/src/main.rs index 03a372df..651c5abd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,12 @@ #![cfg_attr(feature = "nightly", feature(core_intrinsics))] #![cfg_attr(all(test, feature = "bench"), feature(test))] +// With the default subsystem, 'console', windows creates an additional console +// 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")] + #[macro_use] extern crate alacritty; @@ -29,6 +35,8 @@ use std::error::Error; use std::sync::Arc; #[cfg(target_os = "macos")] use std::env; +#[cfg(not(windows))] +use std::os::unix::io::AsRawFd; use alacritty::cli; use alacritty::config::{self, Config}; @@ -39,7 +47,7 @@ use alacritty::event_loop::{self, EventLoop, Msg}; use alacritty::locale; use alacritty::logging; use alacritty::sync::FairMutex; -use alacritty::term::{Term}; +use alacritty::term::Term; use alacritty::tty::{self, process_should_exit}; use alacritty::util::fmt::Red; @@ -67,7 +75,8 @@ fn main() { /// /// If a configuration file is given as a command line argument we don't /// generate a default file. If an empty configuration file is given, i.e. -/// /dev/null, we load the compiled-in defaults. +/// /dev/null, we load the compiled-in defaults.) +#[cfg(not(windows))] fn load_config(options: &cli::Options) -> Config { let config_path = options.config_path() .or_else(Config::installed_config) @@ -81,6 +90,27 @@ fn load_config(options: &cli::Options) -> Config { Config::default() }) } +#[cfg(windows)] +fn load_config(options: &cli::Options) -> Config { + let config_path = options + .config_path() + .or_else(|| Config::installed_config()) + .unwrap_or_else(|| { + Config::write_defaults() + .unwrap_or_else(|err| die!("Write defaults config failure: {}", err)) + }); + + Config::load_from(&*config_path).unwrap_or_else(|err| match err { + config::Error::NotFound => { + die!("Config file not found after writing: {}", config_path.display()); + } + config::Error::Empty => { + eprintln!("Empty config; Loading defaults"); + Config::default() + } + _ => die!("{}", err), + }) +} /// Run Alacritty /// @@ -122,7 +152,17 @@ fn run(mut config: Config, options: &cli::Options) -> Result<(), Box<Error>> { // The pty forks a process to run the shell on the slave side of the // pseudoterminal. A file descriptor for the master side is retained for // reading/writing to the shell. - let mut pty = tty::new(&config, options, &display.size(), window_id); + let pty = tty::new(&config, options, &display.size(), window_id); + + // Get a reference to something that we can resize + // + // This exists because rust doesn't know the interface is thread-safe + // and we need to be able to resize the PTY from the main thread while the IO + // thread owns the EventedRW object. + #[cfg(windows)] + let resize_handle = unsafe { &mut *pty.winpty.get() }; + #[cfg(not(windows))] + let mut resize_handle = pty.fd.as_raw_fd(); // Create the pseudoterminal I/O loop // @@ -133,7 +173,7 @@ fn run(mut config: Config, options: &cli::Options) -> Result<(), Box<Error>> { let event_loop = EventLoop::new( Arc::clone(&terminal), display.notifier(), - pty.reader(), + pty, options.ref_test, ); @@ -168,7 +208,9 @@ fn run(mut config: Config, options: &cli::Options) -> Result<(), Box<Error>> { }; // Kick off the I/O thread - let io_thread = event_loop.spawn(None); + let _io_thread = event_loop.spawn(None); + + info!("Initialisation complete"); // Main display loop loop { @@ -195,7 +237,11 @@ fn run(mut config: Config, options: &cli::Options) -> Result<(), Box<Error>> { // // The second argument is a list of types that want to be notified // of display size changes. - display.handle_resize(&mut terminal_lock, &config, &mut [&mut pty, &mut processor]); + #[cfg(windows)] + display.handle_resize(&mut terminal_lock, &config, &mut [resize_handle, &mut processor]); + #[cfg(not(windows))] + display.handle_resize(&mut terminal_lock, &config, &mut [&mut resize_handle, &mut processor]); + drop(terminal_lock); // Draw the current state of the terminal @@ -208,13 +254,12 @@ fn run(mut config: Config, options: &cli::Options) -> Result<(), Box<Error>> { } } - loop_tx.send(Msg::Shutdown).expect("Error sending shutdown to event loop"); + loop_tx + .send(Msg::Shutdown) + .expect("Error sending shutdown to event loop"); // FIXME patch notify library to have a shutdown method // config_reloader.join().ok(); - // Wait for the I/O thread thread to finish - let _ = io_thread.join(); - Ok(()) } |