diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2018-11-11 12:55:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-11 12:55:28 +0000 |
commit | dba3cccf6948fb993e02d03ca8891fbc7f6cd3e6 (patch) | |
tree | f329f86bed6a185a8d7dc4b38bc13155071e6b9f /src/tty/mod.rs | |
parent | 021b424858d0b2fcf50c4199e152e93596cc8d5d (diff) | |
download | alacritty-dba3cccf6948fb993e02d03ca8891fbc7f6cd3e6.tar.gz alacritty-dba3cccf6948fb993e02d03ca8891fbc7f6cd3e6.zip |
Set env variables before window start
The environment variables specified in the configuration file are now
all set before the window is created. As a result, this makes it
possible to add the `WINIT_HIDPI_FACTOR` env variable directly to the
Alacritty configuration.
This fixes https://github.com/jwilm/alacritty/issues/1768.
Diffstat (limited to 'src/tty/mod.rs')
-rw-r--r-- | src/tty/mod.rs | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/tty/mod.rs b/src/tty/mod.rs index 5657b0fd..faed276d 100644 --- a/src/tty/mod.rs +++ b/src/tty/mod.rs @@ -13,9 +13,12 @@ // limitations under the License. // //! tty related functionality - use mio; -use std::io; +use std::{env, io}; + +use terminfo::Database; + +use config::Config; #[cfg(not(windows))] mod unix; @@ -34,7 +37,13 @@ pub trait EventedReadWrite { type Reader: io::Read; type Writer: io::Write; - fn register(&mut self, &mio::Poll, &mut Iterator<Item = &usize>, mio::Ready, mio::PollOpt) -> io::Result<()>; + fn register( + &mut self, + &mio::Poll, + &mut Iterator<Item = &usize>, + mio::Ready, + mio::PollOpt, + ) -> io::Result<()>; fn reregister(&mut self, &mio::Poll, mio::Ready, mio::PollOpt) -> io::Result<()>; fn deregister(&mut self, &mio::Poll) -> io::Result<()>; @@ -43,3 +52,26 @@ pub trait EventedReadWrite { fn writer(&mut self) -> &mut Self::Writer; fn write_token(&self) -> mio::Token; } + +// Setup environment variables +pub fn setup_env(config: &Config) { + // Default to 'alacritty' terminfo if it is available, otherwise + // default to 'xterm-256color'. May be overridden by user's config + // below. + env::set_var( + "TERM", + if Database::from_name("alacritty").is_ok() { + "alacritty" + } else { + "xterm-256color" + }, + ); + + // Advertise 24-bit color support + env::set_var("COLORTERM", "truecolor"); + + // Set env vars from config + for (key, value) in config.env().iter() { + env::set_var(key, value); + } +} |