Projects STRLCPY alacritty Commits 3af19401
🤬
  • Fix CreateNewWindow CLI fallback

    The existing behavior for the new CreateNewWindow actions was to always
    pass in their own options, which would discard the existing options
    configured on the terminal's PTY config.
    
    To fix this the behavior for CreateNewWindow is now the same as for the
    initial window creation, the config values are overwritten conditionally
    based on their individual presence in the CLI options.
    
    However all temporary CLI options set on the "master" Alacritty
    instance are discarded by all future windows.
    
    Fixes #5659.
  • Loading...
  • Christian Duerr committed with GitHub 2 years ago
    3af19401
    1 parent 6d1a63ef
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    alacritty/src/cli.rs
    skipped 99 lines
    100 100   
    101 101   /// Override configuration file with options from the CLI.
    102 102   pub fn override_config(&self, config: &mut UiConfig) {
    103  - if let Some(working_directory) = &self.terminal_options.working_directory {
    104  - if working_directory.is_dir() {
    105  - config.terminal_config.pty_config.working_directory =
    106  - Some(working_directory.to_owned());
    107  - } else {
    108  - error!("Invalid working directory: {:?}", working_directory);
    109  - }
    110  - }
    111  - 
    112  - if let Some(command) = self.terminal_options.command() {
    113  - config.terminal_config.pty_config.shell = Some(command);
    114  - }
    115  - 
    116  - config.terminal_config.pty_config.hold = self.terminal_options.hold;
    117  - 
    118 103   if let Some(title) = self.title.clone() {
    119 104   config.window.title = title
    120 105   }
    skipped 97 lines
    218 203  }
    219 204   
    220 205  impl TerminalOptions {
    221  - pub fn new() -> Self {
    222  - Default::default()
    223  - }
    224  - 
    225  - pub fn is_empty(&self) -> bool {
    226  - self.working_directory.is_none() && !self.hold && self.command.is_empty()
    227  - }
    228  - 
    229 206   /// Shell override passed through the CLI.
    230 207   pub fn command(&self) -> Option<Program> {
    231 208   let (program, args) = self.command.split_first()?;
    232 209   Some(Program::WithArgs { program: program.clone(), args: args.to_vec() })
    233 210   }
     211 + 
     212 + /// Override the [`PtyConfig`]'s fields with the [`TerminalOptions`].
     213 + pub fn override_pty_config(&self, pty_config: &mut PtyConfig) {
     214 + if let Some(working_directory) = &self.working_directory {
     215 + if working_directory.is_dir() {
     216 + pty_config.working_directory = Some(working_directory.to_owned());
     217 + } else {
     218 + error!("Invalid working directory: {:?}", working_directory);
     219 + }
     220 + }
     221 + 
     222 + if let Some(command) = self.command() {
     223 + pty_config.shell = Some(command);
     224 + }
     225 + 
     226 + pty_config.hold |= self.hold;
     227 + }
    234 228  }
    235 229   
    236 230  impl From<TerminalOptions> for PtyConfig {
    237 231   fn from(mut options: TerminalOptions) -> Self {
    238  - let working_directory = options.working_directory.take();
    239  - let shell = options.command();
    240  - let hold = options.hold;
    241  - PtyConfig { shell, working_directory, hold }
     232 + PtyConfig {
     233 + working_directory: options.working_directory.take(),
     234 + shell: options.command(),
     235 + hold: options.hold,
     236 + }
    242 237   }
    243 238  }
    244 239   
    skipped 157 lines
  • ■ ■ ■ ■ ■
    alacritty/src/display/hint.rs
    skipped 77 lines
    78 78   if hint.post_processing {
    79 79   matches
    80 80   .drain(..)
    81  - .map(|rm| HintPostProcessor::new(term, regex, rm).collect::<Vec<_>>())
    82  - .flatten()
     81 + .flat_map(|rm| HintPostProcessor::new(term, regex, rm).collect::<Vec<_>>())
    83 82   .collect()
    84 83   } else {
    85 84   matches.0
    skipped 406 lines
  • ■ ■ ■ ■ ■ ■
    alacritty/src/event.rs
    skipped 33 lines
    34 34  use alacritty_terminal::term::search::{Match, RegexSearch};
    35 35  use alacritty_terminal::term::{ClipboardType, SizeInfo, Term, TermMode};
    36 36   
    37  -use crate::cli::{Options as CliOptions, TerminalOptions as TerminalCliOptions};
     37 +use crate::cli::{Options as CliOptions, TerminalOptions};
    38 38  use crate::clipboard::Clipboard;
    39 39  use crate::config::ui_config::{HintAction, HintInternalAction};
    40 40  use crate::config::{self, UiConfig};
    skipped 47 lines
    88 88   ConfigReload(PathBuf),
    89 89   Message(Message),
    90 90   Scroll(Scroll),
    91  - CreateWindow(Option<TerminalCliOptions>),
     91 + CreateWindow(TerminalOptions),
    92 92   BlinkCursor,
    93 93   SearchNext,
    94 94  }
    skipped 284 lines
    379 379   
    380 380   #[cfg(not(windows))]
    381 381   fn create_new_window(&mut self) {
    382  - let cwd = foreground_process_path(self.master_fd, self.shell_pid);
    383  - let options = if let Ok(working_directory) = cwd {
    384  - let mut options = TerminalCliOptions::new();
     382 + let mut options = TerminalOptions::default();
     383 + if let Ok(working_directory) = foreground_process_path(self.master_fd, self.shell_pid) {
    385 384   options.working_directory = Some(working_directory);
    386  - Some(options)
    387  - } else {
    388  - None
    389  - };
     385 + }
    390 386   
    391 387   let _ = self.event_proxy.send_event(Event::new(EventType::CreateWindow(options), None));
    392 388   }
    393 389   
    394 390   #[cfg(windows)]
    395 391   fn create_new_window(&mut self) {
    396  - let _ = self.event_proxy.send_event(Event::new(EventType::CreateWindow(None), None));
     392 + let _ = self
     393 + .event_proxy
     394 + .send_event(Event::new(EventType::CreateWindow(TerminalOptions::default()), None));
    397 395   }
    398 396   
    399 397   fn spawn_daemon<I, S>(&self, program: &str, args: I)
    skipped 353 lines
    753 751   }
    754 752   } else if self.terminal().mode().contains(TermMode::BRACKETED_PASTE) {
    755 753   self.write_to_pty(&b"\x1b[200~"[..]);
    756  - self.write_to_pty(text.replace("\x1b", "").into_bytes());
     754 + self.write_to_pty(text.replace('\x1b', "").into_bytes());
    757 755   self.write_to_pty(&b"\x1b[201~"[..]);
    758 756   } else {
    759 757   // In non-bracketed (ie: normal) mode, terminal applications cannot distinguish
    skipped 2 lines
    762 760   // pasting... since that's neither practical nor sensible (and probably an impossible
    763 761   // task to solve in a general way), we'll just replace line breaks (windows and unix
    764 762   // style) with a single carriage return (\r, which is what the Enter key produces).
    765  - self.write_to_pty(text.replace("\r\n", "\r").replace("\n", "\r").into_bytes());
     763 + self.write_to_pty(text.replace("\r\n", "\r").replace('\n', "\r").into_bytes());
    766 764   }
    767 765   }
    768 766   
    skipped 438 lines
    1207 1205   pub fn create_window(
    1208 1206   &mut self,
    1209 1207   event_loop: &EventLoopWindowTarget<Event>,
    1210  - options: Option<TerminalCliOptions>,
    1211 1208   proxy: EventLoopProxy<Event>,
     1209 + options: TerminalOptions,
    1212 1210   ) -> Result<(), Box<dyn Error>> {
     1211 + let mut pty_config = self.config.terminal_config.pty_config.clone();
     1212 + options.override_pty_config(&mut pty_config);
     1213 + 
    1213 1214   let window_context = WindowContext::new(
    1214 1215   &self.config,
    1215  - options,
     1216 + &pty_config,
    1216 1217   event_loop,
    1217 1218   proxy,
    1218 1219   #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
    skipped 101 lines
    1320 1321   GlutinEvent::UserEvent(Event {
    1321 1322   payload: EventType::CreateWindow(options), ..
    1322 1323   }) => {
    1323  - if let Err(err) = self.create_window(event_loop, options, proxy.clone()) {
     1324 + if let Err(err) = self.create_window(event_loop, proxy.clone(), options) {
    1324 1325   error!("Could not open window: {:?}", err);
    1325 1326   }
    1326 1327   },
    skipped 80 lines
  • ■ ■ ■ ■ ■ ■
    alacritty/src/input.rs
    skipped 801 lines
    802 802   self.ctx.clear_selection();
    803 803   
    804 804   let utf8_len = c.len_utf8();
    805  - let mut bytes = Vec::with_capacity(utf8_len);
    806  - unsafe {
    807  - bytes.set_len(utf8_len);
    808  - c.encode_utf8(&mut bytes[..]);
    809  - }
     805 + let mut bytes = vec![0; utf8_len];
     806 + c.encode_utf8(&mut bytes[..]);
    810 807   
    811 808   if self.ctx.config().alt_send_esc
    812 809   && *self.ctx.received_count() == 0
    skipped 194 lines
    1007 1004   }
    1008 1005   
    1009 1006   fn terminal_mut(&mut self) -> &mut Term<T> {
    1010  - &mut self.terminal
     1007 + self.terminal
    1011 1008   }
    1012 1009   
    1013 1010   fn size_info(&self) -> SizeInfo {
    skipped 314 lines
  • ■ ■ ■ ■ ■ ■
    alacritty/src/ipc.rs
    skipped 57 lines
    58 58   
    59 59   // Handle IPC events.
    60 60   match message {
    61  - SocketMessage::CreateWindow(terminal_options) => {
    62  - let event = Event::new(EventType::CreateWindow(Some(terminal_options)), None);
     61 + SocketMessage::CreateWindow(options) => {
     62 + let event = Event::new(EventType::CreateWindow(options), None);
    63 63   let _ = event_proxy.send_event(event);
    64 64   },
    65 65   }
    skipped 98 lines
  • ■ ■ ■ ■
    alacritty/src/main.rs
    skipped 177 lines
    178 178   };
    179 179   
    180 180   // Event processor.
     181 + let cli_options = options.terminal_options.clone();
    181 182   let mut processor = Processor::new(config, options, &window_event_loop);
    182 183   
    183 184   // Create the first Alacritty window.
    184 185   let proxy = window_event_loop.create_proxy();
    185  - processor.create_window(&window_event_loop, None, proxy).map_err(|err| err.to_string())?;
     186 + processor
     187 + .create_window(&window_event_loop, proxy, cli_options)
     188 + .map_err(|err| err.to_string())?;
    186 189   
    187 190   info!("Initialisation complete");
    188 191   
    skipped 42 lines
  • ■ ■ ■ ■ ■ ■
    alacritty/src/window_context.rs
    1 1  //! Terminal window context.
    2 2   
    3  -use std::borrow::Cow;
    4 3  use std::error::Error;
    5 4  use std::fs::File;
    6 5  use std::io::Write;
    skipped 13 lines
    20 19  #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
    21 20  use wayland_client::EventQueue;
    22 21   
     22 +use alacritty_terminal::config::PtyConfig;
    23 23  use alacritty_terminal::event::Event as TerminalEvent;
    24 24  use alacritty_terminal::event_loop::{EventLoop as PtyEventLoop, Msg, Notifier};
    25 25  use alacritty_terminal::grid::{Dimensions, Scroll};
    skipped 2 lines
    28 28  use alacritty_terminal::term::{Term, TermMode};
    29 29  use alacritty_terminal::tty;
    30 30   
    31  -use crate::cli::TerminalOptions as TerminalCliOptions;
    32 31  use crate::clipboard::Clipboard;
    33 32  use crate::config::UiConfig;
    34 33  use crate::display::Display;
    skipped 26 lines
    61 60   /// Create a new terminal window context.
    62 61   pub fn new(
    63 62   config: &UiConfig,
    64  - options: Option<TerminalCliOptions>,
     63 + pty_config: &PtyConfig,
    65 64   window_event_loop: &EventLoopWindowTarget<Event>,
    66 65   proxy: EventLoopProxy<Event>,
    67 66   #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
    skipped 30 lines
    98 97   // The PTY forks a process to run the shell on the slave side of the
    99 98   // pseudoterminal. A file descriptor for the master side is retained for
    100 99   // reading/writing to the shell.
    101  - let pty_config = options
    102  - .map(|o| Cow::Owned(o.into()))
    103  - .unwrap_or(Cow::Borrowed(&config.terminal_config.pty_config));
    104  - let pty = tty::new(&pty_config, &display.size_info, display.window.x11_window_id())?;
     100 + let pty = tty::new(pty_config, &display.size_info, display.window.x11_window_id())?;
    105 101   
    106 102   #[cfg(not(windows))]
    107 103   let master_fd = pty.file().as_raw_fd();
    skipped 292 lines
  • ■ ■ ■ ■ ■ ■
    alacritty_terminal/src/ansi.rs
    skipped 696 lines
    697 697  }
    698 698   
    699 699  impl NamedColor {
     700 + #[must_use]
    700 701   pub fn to_bright(self) -> Self {
    701 702   match self {
    702 703   NamedColor::Foreground => NamedColor::BrightForeground,
    skipped 18 lines
    721 722   }
    722 723   }
    723 724   
     725 + #[must_use]
    724 726   pub fn to_dim(self) -> Self {
    725 727   match self {
    726 728   NamedColor::Black => NamedColor::DimBlack,
    skipped 1000 lines
  • ■ ■ ■ ■ ■ ■
    alacritty_terminal/src/index.rs
    skipped 19 lines
    20 20  }
    21 21   
    22 22  impl Direction {
     23 + #[must_use]
    23 24   pub fn opposite(self) -> Self {
    24 25   match self {
    25 26   Side::Right => Side::Left,
    skipped 107 lines
    133 134   
    134 135  impl Line {
    135 136   /// Clamp a line to a grid boundary.
     137 + #[must_use]
    136 138   pub fn grid_clamp<D: Dimensions>(self, dimensions: &D, boundary: Boundary) -> Self {
    137 139   match boundary {
    138 140   Boundary::Cursor => max(Line(0), min(dimensions.bottommost_line(), self)),
    skipped 324 lines
Please wait...
Page is in error, reload to recover