mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-25 14:05:41 -05:00
Fix IPC config overriding previous values
Before this patch whenever changing the IPC configuration, all previous configuration options would be discarded. This was the case even when the new option was invalid. This patch ensures that the IPC config is only ever cleared when the `--reset` flag is passed. Invalid IPC config options are logged and discarded. Additionally whenever a new IPC config message is sent, all previous IPC error messages are cleared. Closes #6330.
This commit is contained in:
parent
3a38f0b996
commit
c5ae05e810
3 changed files with 43 additions and 10 deletions
|
@ -15,15 +15,27 @@ use std::{env, process};
|
|||
use glutin::event_loop::EventLoopProxy;
|
||||
use log::{self, Level, LevelFilter};
|
||||
|
||||
use alacritty_terminal::config::LOG_TARGET_CONFIG;
|
||||
|
||||
use crate::cli::Options;
|
||||
use crate::event::{Event, EventType};
|
||||
use crate::message_bar::{Message, MessageType};
|
||||
|
||||
/// Logging target for IPC config error messages.
|
||||
pub const LOG_TARGET_IPC_CONFIG: &str = "alacritty_log_ipc_config";
|
||||
|
||||
/// Name for the environment variable containing the log file's path.
|
||||
const ALACRITTY_LOG_ENV: &str = "ALACRITTY_LOG";
|
||||
|
||||
/// List of targets which will be logged by Alacritty.
|
||||
const ALLOWED_TARGETS: [&str; 4] =
|
||||
["alacritty_terminal", "alacritty_config_derive", "alacritty", "crossfont"];
|
||||
const ALLOWED_TARGETS: &[&str] = &[
|
||||
LOG_TARGET_IPC_CONFIG,
|
||||
LOG_TARGET_CONFIG,
|
||||
"alacritty_config_derive",
|
||||
"alacritty_terminal",
|
||||
"alacritty",
|
||||
"crossfont",
|
||||
];
|
||||
|
||||
pub fn initialize(
|
||||
options: &Options,
|
||||
|
|
|
@ -38,6 +38,7 @@ use crate::config::UiConfig;
|
|||
use crate::display::Display;
|
||||
use crate::event::{ActionContext, Event, EventProxy, EventType, Mouse, SearchState};
|
||||
use crate::input;
|
||||
use crate::logging::LOG_TARGET_IPC_CONFIG;
|
||||
use crate::message_bar::MessageBuffer;
|
||||
use crate::scheduler::Scheduler;
|
||||
|
||||
|
@ -184,10 +185,20 @@ impl WindowContext {
|
|||
if !self.ipc_config.is_empty() {
|
||||
let mut config = (*self.config).clone();
|
||||
|
||||
// Apply each option.
|
||||
for (key, value) in &self.ipc_config {
|
||||
if let Err(err) = config.replace(key, value.clone()) {
|
||||
error!("Unable to override option '{}': {}", key, err);
|
||||
// Apply each option, removing broken ones.
|
||||
let mut i = 0;
|
||||
while i < self.ipc_config.len() {
|
||||
let (key, value) = &self.ipc_config[i];
|
||||
|
||||
match config.replace(key, value.clone()) {
|
||||
Err(err) => {
|
||||
error!(
|
||||
target: LOG_TARGET_IPC_CONFIG,
|
||||
"Unable to override option '{}': {}", key, err
|
||||
);
|
||||
self.ipc_config.swap_remove(i);
|
||||
},
|
||||
Ok(_) => i += 1,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,15 +266,21 @@ impl WindowContext {
|
|||
/// Update the IPC config overrides.
|
||||
#[cfg(unix)]
|
||||
pub fn update_ipc_config(&mut self, config: Rc<UiConfig>, ipc_config: IpcConfig) {
|
||||
self.ipc_config.clear();
|
||||
// Clear previous IPC errors.
|
||||
self.message_buffer.remove_target(LOG_TARGET_IPC_CONFIG);
|
||||
|
||||
if !ipc_config.reset {
|
||||
if ipc_config.reset {
|
||||
self.ipc_config.clear();
|
||||
} else {
|
||||
for option in &ipc_config.options {
|
||||
// Separate config key/value.
|
||||
let (key, value) = match option.split_once('=') {
|
||||
Some(split) => split,
|
||||
None => {
|
||||
error!("'{}': IPC config option missing value", option);
|
||||
error!(
|
||||
target: LOG_TARGET_IPC_CONFIG,
|
||||
"'{}': IPC config option missing value", option
|
||||
);
|
||||
continue;
|
||||
},
|
||||
};
|
||||
|
@ -271,7 +288,10 @@ impl WindowContext {
|
|||
// Try and parse value as yaml.
|
||||
match serde_yaml::from_str(value) {
|
||||
Ok(value) => self.ipc_config.push((key.to_owned(), value)),
|
||||
Err(err) => error!("'{}': Invalid IPC config value: {:?}", option, err),
|
||||
Err(err) => error!(
|
||||
target: LOG_TARGET_IPC_CONFIG,
|
||||
"'{}': Invalid IPC config value: {:?}", option, err
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ use crate::ansi::{CursorShape, CursorStyle};
|
|||
|
||||
pub use crate::config::scrolling::{Scrolling, MAX_SCROLLBACK_LINES};
|
||||
|
||||
/// Logging target for config error messages.
|
||||
pub const LOG_TARGET_CONFIG: &str = "alacritty_config_derive";
|
||||
|
||||
const MIN_BLINK_INTERVAL: u64 = 10;
|
||||
|
|
Loading…
Reference in a new issue