aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorZac Pullar-Strecker <zacps@users.noreply.github.com>2018-10-17 06:02:52 +1300
committerJoe Wilm <jwilm@users.noreply.github.com>2018-10-16 10:02:52 -0700
commit15e0deae2b49078b47a782679300cdf99d9ce687 (patch)
tree8175fbed0def1af08cd2db41583975adbb27dff1 /src/config.rs
parentb41c6b736d67d61e92b174dfea58ae46813934cd (diff)
downloadalacritty-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/config.rs')
-rw-r--r--src/config.rs48
1 files changed, 46 insertions, 2 deletions
diff --git a/src/config.rs b/src/config.rs
index 0f250522..c7d7ea58 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -555,10 +555,12 @@ fn failure_default<'a, D, T>(deserializer: D)
}
}
-#[cfg(not(target_os="macos"))]
+#[cfg(not(any(windows, target_os="macos")))]
static DEFAULT_ALACRITTY_CONFIG: &'static str = include_str!("../alacritty.yml");
#[cfg(target_os="macos")]
static DEFAULT_ALACRITTY_CONFIG: &'static str = include_str!("../alacritty_macos.yml");
+#[cfg(windows)]
+static DEFAULT_ALACRITTY_CONFIG: &'static str = include_str!("../alacritty_windows.yml");
impl Default for Config {
fn default() -> Self {
@@ -1444,6 +1446,7 @@ impl Config {
/// 2. $XDG_CONFIG_HOME/alacritty.yml
/// 3. $HOME/.config/alacritty/alacritty.yml
/// 4. $HOME/.alacritty.yml
+ #[cfg(not(windows))]
pub fn installed_config<'a>() -> Option<Cow<'a, Path>> {
// Try using XDG location by default
::xdg::BaseDirectories::with_prefix("alacritty")
@@ -1472,6 +1475,19 @@ impl Config {
.map(|path| path.into())
}
+ #[cfg(windows)]
+ pub fn installed_config() -> Option<Cow<'static, Path>> {
+ if let Some(mut path) = ::std::env::home_dir() {
+ path.push("alacritty");
+ path.set_extension("yml");
+ if path.exists() {
+ return Some(path.into());
+ }
+ }
+ None
+ }
+
+ #[cfg(not(windows))]
pub fn write_defaults() -> io::Result<Cow<'static, Path>> {
let path = ::xdg::BaseDirectories::with_prefix("alacritty")
.map_err(|err| io::Error::new(io::ErrorKind::NotFound, ::std::error::Error::description(&err)))
@@ -1480,6 +1496,15 @@ impl Config {
Ok(path.into())
}
+ #[cfg(windows)]
+ pub fn write_defaults() -> io::Result<Cow<'static, Path>> {
+ let path = ::std::env::home_dir()
+ .ok_or(io::Error::new(io::ErrorKind::NotFound, "could not find profile directory"))
+ .and_then(|mut p| {p.push("alacritty"); p.set_extension("yml"); Ok(p)})?;
+ File::create(&path)?.write_all(DEFAULT_ALACRITTY_CONFIG.as_bytes())?;
+ Ok(path.into())
+ }
+
/// Get list of colors
///
/// The ordering returned here is expected by the terminal. Colors are simply indexed in this
@@ -1894,6 +1919,22 @@ impl Default for Font {
}
}
+#[cfg(windows)]
+impl Default for Font {
+ fn default() -> Font {
+ Font {
+ normal: FontDescription::new_with_family("Consolas"),
+ bold: FontDescription::new_with_family("Consolas"),
+ italic: FontDescription::new_with_family("Consolas"),
+ size: Size::new(11.0),
+ use_thin_strokes: false,
+ offset: Default::default(),
+ glyph_offset: Default::default(),
+ scale_with_dpi: false,
+ }
+ }
+}
+
pub struct Monitor {
_thread: ::std::thread::JoinHandle<()>,
rx: mpsc::Receiver<Config>,
@@ -1977,7 +2018,10 @@ mod tests {
#[cfg(target_os="macos")]
static ALACRITTY_YML: &'static str =
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/alacritty_macos.yml"));
- #[cfg(not(target_os="macos"))]
+ #[cfg(windows)]
+ static ALACRITTY_YML: &'static str =
+ include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/alacritty_windows.yml"));
+ #[cfg(not(any(target_os="macos", windows)))]
static ALACRITTY_YML: &'static str =
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/alacritty.yml"));