summaryrefslogtreecommitdiffstats
path: root/alacritty_terminal
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2022-08-31 22:48:38 +0000
committerGitHub <noreply@github.com>2022-09-01 01:48:38 +0300
commit4ddb608563d985060d69594d1004550a680ae3bd (patch)
tree0b02a330b3e59300cff80a147f3c1bdab7f9ea57 /alacritty_terminal
parent18f9c2793924aec91c80a69ccb45f529adaffae5 (diff)
Add IPC config subcommand
This patch adds a new mechanism for changing configuration options without editing the configuration file, by sending options to running instances through `alacritty msg`. Each window will load Alacritty's configuration file by default and then accept IPC messages for config updates using the `alacritty msg config` subcommand. By default all windows will be updated, individual windows can be addressed using `alacritty msg config --window-id "$ALACRITTY_WINDOW_ID"`. Each option will replace the config's current value and cannot be reset until Alacritty is restarted or the option is overwritten with a new value. Configuration options are passed in the format `field.subfield=value`, where `value` is interpreted as yaml. Closes #472.
Diffstat (limited to 'alacritty_terminal')
-rw-r--r--alacritty_terminal/Cargo.toml4
-rw-r--r--alacritty_terminal/src/config/mod.rs8
-rw-r--r--alacritty_terminal/src/config/scrolling.rs4
-rw-r--r--alacritty_terminal/src/index.rs16
-rw-r--r--alacritty_terminal/src/term/color.rs6
-rw-r--r--alacritty_terminal/src/tty/unix.rs9
-rw-r--r--alacritty_terminal/src/tty/windows/mod.rs2
7 files changed, 35 insertions, 14 deletions
diff --git a/alacritty_terminal/Cargo.toml b/alacritty_terminal/Cargo.toml
index fb5d2d22..06d3961a 100644
--- a/alacritty_terminal/Cargo.toml
+++ b/alacritty_terminal/Cargo.toml
@@ -13,6 +13,10 @@ rust-version = "1.57.0"
path = "../alacritty_config_derive"
version = "0.1.0"
+[dependencies.alacritty_config]
+path = "../alacritty_config"
+version = "0.1.0"
+
[dependencies]
libc = "0.2"
bitflags = "1"
diff --git a/alacritty_terminal/src/config/mod.rs b/alacritty_terminal/src/config/mod.rs
index 5822d591..53a0eb77 100644
--- a/alacritty_terminal/src/config/mod.rs
+++ b/alacritty_terminal/src/config/mod.rs
@@ -4,7 +4,7 @@ use std::path::PathBuf;
use serde::Deserialize;
-use alacritty_config_derive::ConfigDeserialize;
+use alacritty_config_derive::{ConfigDeserialize, SerdeReplace};
mod scrolling;
@@ -17,7 +17,7 @@ pub const LOG_TARGET_CONFIG: &str = "alacritty_config_derive";
const MIN_BLINK_INTERVAL: u64 = 10;
/// Top-level config type.
-#[derive(ConfigDeserialize, Debug, PartialEq, Default)]
+#[derive(ConfigDeserialize, Clone, Debug, PartialEq, Default)]
pub struct Config {
/// TERM env variable.
pub env: HashMap<String, String>,
@@ -125,7 +125,7 @@ impl Cursor {
}
}
-#[derive(Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
+#[derive(SerdeReplace, Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum ConfigCursorStyle {
Shape(CursorShape),
@@ -222,7 +222,7 @@ impl Program {
}
/// Wrapper around f32 that represents a percentage value between 0.0 and 1.0.
-#[derive(Deserialize, Clone, Copy, Debug, PartialEq)]
+#[derive(SerdeReplace, Deserialize, Clone, Copy, Debug, PartialEq)]
pub struct Percentage(f32);
impl Default for Percentage {
diff --git a/alacritty_terminal/src/config/scrolling.rs b/alacritty_terminal/src/config/scrolling.rs
index 9a5a718c..f4e55787 100644
--- a/alacritty_terminal/src/config/scrolling.rs
+++ b/alacritty_terminal/src/config/scrolling.rs
@@ -1,7 +1,7 @@
use serde::de::Error as SerdeError;
use serde::{Deserialize, Deserializer};
-use alacritty_config_derive::ConfigDeserialize;
+use alacritty_config_derive::{ConfigDeserialize, SerdeReplace};
/// Maximum scrollback amount configurable.
pub const MAX_SCROLLBACK_LINES: u32 = 100_000;
@@ -31,7 +31,7 @@ impl Scrolling {
}
}
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+#[derive(SerdeReplace, Copy, Clone, Debug, PartialEq, Eq)]
struct ScrollingHistory(u32);
impl Default for ScrollingHistory {
diff --git a/alacritty_terminal/src/index.rs b/alacritty_terminal/src/index.rs
index e672c752..9464b8d8 100644
--- a/alacritty_terminal/src/index.rs
+++ b/alacritty_terminal/src/index.rs
@@ -7,6 +7,8 @@ use std::ops::{Add, AddAssign, Deref, Sub, SubAssign};
use serde::{Deserialize, Serialize};
+use alacritty_config_derive::SerdeReplace;
+
use crate::grid::Dimensions;
/// The side of a cell.
@@ -222,7 +224,19 @@ impl PartialEq<usize> for Line {
/// A column.
///
/// Newtype to avoid passing values incorrectly.
-#[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, Default, Ord, PartialOrd)]
+#[derive(
+ SerdeReplace,
+ Serialize,
+ Deserialize,
+ Debug,
+ Copy,
+ Clone,
+ Eq,
+ PartialEq,
+ Default,
+ Ord,
+ PartialOrd,
+)]
pub struct Column(pub usize);
impl fmt::Display for Column {
diff --git a/alacritty_terminal/src/term/color.rs b/alacritty_terminal/src/term/color.rs
index 1cfdec6b..3c545b28 100644
--- a/alacritty_terminal/src/term/color.rs
+++ b/alacritty_terminal/src/term/color.rs
@@ -7,12 +7,14 @@ use serde::de::{Error as _, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
use serde_yaml::Value;
+use alacritty_config_derive::SerdeReplace;
+
use crate::ansi::NamedColor;
/// Number of terminal colors.
pub const COUNT: usize = 269;
-#[derive(Debug, Eq, PartialEq, Copy, Clone, Default, Serialize)]
+#[derive(SerdeReplace, Debug, Eq, PartialEq, Copy, Clone, Default, Serialize)]
pub struct Rgb {
pub r: u8,
pub g: u8,
@@ -170,7 +172,7 @@ impl FromStr for Rgb {
}
/// RGB color optionally referencing the cell's foreground or background.
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+#[derive(SerdeReplace, Copy, Clone, Debug, PartialEq, Eq)]
pub enum CellRgb {
CellForeground,
CellBackground,
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs
index f52f0920..63da4f9c 100644
--- a/alacritty_terminal/src/tty/unix.rs
+++ b/alacritty_terminal/src/tty/unix.rs
@@ -148,7 +148,7 @@ fn default_shell_command(pw: &Passwd<'_>) -> Command {
}
/// Create a new TTY and return a handle to interact with it.
-pub fn new(config: &PtyConfig, window_size: WindowSize, window_id: Option<usize>) -> Result<Pty> {
+pub fn new(config: &PtyConfig, window_size: WindowSize, window_id: u64) -> Result<Pty> {
let (master, slave) = make_pty(window_size.to_winsize())?;
#[cfg(any(target_os = "linux", target_os = "macos"))]
@@ -178,13 +178,14 @@ pub fn new(config: &PtyConfig, window_size: WindowSize, window_id: Option<usize>
builder.stdout(unsafe { Stdio::from_raw_fd(slave) });
// Setup shell environment.
+ let window_id = window_id.to_string();
+ builder.env("ALACRITTY_WINDOW_ID", &window_id);
builder.env("LOGNAME", pw.name);
builder.env("USER", pw.name);
builder.env("HOME", pw.dir);
- if let Some(window_id) = window_id {
- builder.env("WINDOWID", format!("{}", window_id));
- }
+ // Set Window ID for clients relying on X11 hacks.
+ builder.env("WINDOWID", window_id);
unsafe {
builder.pre_exec(move || {
diff --git a/alacritty_terminal/src/tty/windows/mod.rs b/alacritty_terminal/src/tty/windows/mod.rs
index aa21ce14..57925f4c 100644
--- a/alacritty_terminal/src/tty/windows/mod.rs
+++ b/alacritty_terminal/src/tty/windows/mod.rs
@@ -27,7 +27,7 @@ pub struct Pty {
child_watcher: ChildExitWatcher,
}
-pub fn new(config: &PtyConfig, window_size: WindowSize, _window_id: Option<usize>) -> Result<Pty> {
+pub fn new(config: &PtyConfig, window_size: WindowSize, _window_id: u64) -> Result<Pty> {
conpty::new(config, window_size)
.ok_or_else(|| Error::new(ErrorKind::Other, "failed to spawn conpty"))
}