mirror of
https://github.com/alacritty/alacritty.git
synced 2026-12-01 01:14:32 +03:00
Add terminal config section to control OSCs
Some environments demand certain OSC sequences to be disabled or some escape sequence could require handling which is out of scope of alacritty, but could be done by external script (OSC 777). Added section for now just handles the `OSC 52` sequence and changes its default to be `OnlyCopy`, which is handy for remote copy, but `Paste` is redundant because normal `Paste` hotkey could be used as well. Fixes #3386. Co-authored-by: Christian Duerr <contact@christianduerr.com>
This commit is contained in:
1 parent
f2e543880f
commit
0c94e4ae7b
7 files changed
+60
-4
No files matched your search
@@ -33,6 +33,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
- The default colorscheme is now based on base16 classic dark
|
||||
- IME popup now tries to not obscure the current cursor line
|
||||
- The double click threshold was raised to `400ms`
|
||||
- OSC 52 paste ability is now **disabled by default**; use `terminal.osc52` to adjust it
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
Generated
+1
-1
@@ -72,7 +72,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "alacritty_terminal"
|
||||
version = "0.19.2-dev"
|
||||
version = "0.20.0-dev"
|
||||
dependencies = [
|
||||
"alacritty_config",
|
||||
"alacritty_config_derive",
|
||||
|
||||
@@ -11,7 +11,7 @@ rust-version = "1.65.0"
|
||||
|
||||
[dependencies.alacritty_terminal]
|
||||
path = "../alacritty_terminal"
|
||||
version = "0.19.2-dev"
|
||||
version = "0.20.0-dev"
|
||||
default-features = false
|
||||
|
||||
[dependencies.alacritty_config_derive]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "alacritty_terminal"
|
||||
version = "0.19.2-dev"
|
||||
version = "0.20.0-dev"
|
||||
authors = ["Christian Duerr <contact@christianduerr.com>", "Joe Wilm <joe@jwilm.com>"]
|
||||
license = "Apache-2.0"
|
||||
description = "Library for writing terminal emulators"
|
||||
|
||||
@@ -31,10 +31,35 @@ pub struct Config {
|
||||
/// Cursor configuration.
|
||||
pub cursor: Cursor,
|
||||
|
||||
/// Terminal specific settings.
|
||||
pub terminal: Terminal,
|
||||
|
||||
#[config(flatten)]
|
||||
pub pty_config: PtyConfig,
|
||||
}
|
||||
|
||||
#[derive(ConfigDeserialize, Clone, Debug, PartialEq, Eq, Default)]
|
||||
pub struct Terminal {
|
||||
// OSC 52 handling (clipboard handling).
|
||||
pub osc52: Osc52,
|
||||
}
|
||||
|
||||
#[derive(ConfigDeserialize, Clone, Debug, PartialEq, Eq, Default)]
|
||||
pub enum Osc52 {
|
||||
/// The handling of the escape sequence is disabled.
|
||||
Disabled,
|
||||
/// Only copy sequence is accepted.
|
||||
///
|
||||
/// This option is the default as a compromiss between entirely
|
||||
/// disabling it (the most secure) and allowing `paste` (the less secure).
|
||||
#[default]
|
||||
OnlyCopy,
|
||||
/// Only paste sequence is accepted.
|
||||
OnlyPaste,
|
||||
/// Both are accepted.
|
||||
CopyPaste,
|
||||
}
|
||||
|
||||
#[derive(ConfigDeserialize, Clone, Debug, PartialEq, Eq, Default)]
|
||||
pub struct PtyConfig {
|
||||
/// Path to a shell program to run on startup.
|
||||
|
||||
@@ -12,7 +12,7 @@ use vte::ansi::{Hyperlink as VteHyperlink, Rgb as VteRgb};
|
||||
use crate::ansi::{
|
||||
self, Attr, CharsetIndex, Color, CursorShape, CursorStyle, Handler, NamedColor, StandardCharset,
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::config::{Config, Osc52, Terminal};
|
||||
use crate::event::{Event, EventListener};
|
||||
use crate::grid::{Dimensions, Grid, GridIterator, Scroll};
|
||||
use crate::index::{self, Boundary, Column, Direction, Line, Point, Side};
|
||||
@@ -304,6 +304,9 @@ pub struct Term<T> {
|
||||
|
||||
/// Information about damaged cells.
|
||||
damage: TermDamageState,
|
||||
|
||||
/// Config directly for the terminal.
|
||||
config: Terminal,
|
||||
}
|
||||
|
||||
impl<T> Term<T> {
|
||||
@@ -363,6 +366,7 @@ impl<T> Term<T> {
|
||||
title_stack: Vec::new(),
|
||||
selection: None,
|
||||
damage,
|
||||
config: config.terminal.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,6 +465,8 @@ impl<T> Term<T> {
|
||||
self.grid.update_history(config.scrolling.history() as usize);
|
||||
}
|
||||
|
||||
self.config = config.terminal.clone();
|
||||
|
||||
// Damage everything on config updates.
|
||||
self.mark_fully_damaged();
|
||||
}
|
||||
@@ -1539,6 +1545,11 @@ impl<T: EventListener> Handler for Term<T> {
|
||||
/// Store data into clipboard.
|
||||
#[inline]
|
||||
fn clipboard_store(&mut self, clipboard: u8, base64: &[u8]) {
|
||||
if !matches!(self.config.osc52, Osc52::OnlyCopy | Osc52::CopyPaste) {
|
||||
debug!("Denied osc52 store");
|
||||
return;
|
||||
}
|
||||
|
||||
let clipboard_type = match clipboard {
|
||||
b'c' => ClipboardType::Clipboard,
|
||||
b'p' | b's' => ClipboardType::Selection,
|
||||
@@ -1555,6 +1566,11 @@ impl<T: EventListener> Handler for Term<T> {
|
||||
/// Load data from clipboard.
|
||||
#[inline]
|
||||
fn clipboard_load(&mut self, clipboard: u8, terminator: &str) {
|
||||
if !matches!(self.config.osc52, Osc52::OnlyPaste | Osc52::CopyPaste) {
|
||||
debug!("Denied osc52 load");
|
||||
return;
|
||||
}
|
||||
|
||||
let clipboard_type = match clipboard {
|
||||
b'c' => ClipboardType::Clipboard,
|
||||
b'p' | b's' => ClipboardType::Selection,
|
||||
|
||||
@@ -534,6 +534,20 @@ This section documents the *[cursor]* table of the configuration file.
|
||||
|
||||
Default: _0.15_
|
||||
|
||||
# Terminal
|
||||
|
||||
This section documents the *[terminal]* table of the configuration file.
|
||||
|
||||
*osc52* "Disabled" | "OnlyCopy" | "OnlyPaste" | "CopyPaste"
|
||||
|
||||
Controls the ability to write to the system clipboard with the _OSC 52_
|
||||
escape sequence. While this escape sequence is useful to copy contents
|
||||
from the remote server, allowing any application to read from the clipboard
|
||||
can be easily abused while not providing significant benefits over
|
||||
explicitly pasting text.
|
||||
|
||||
Default: _"OnlyCopy"_
|
||||
|
||||
# Mouse
|
||||
|
||||
This section documents the *[mouse]* table of the configuration file.
|
||||
|
||||
Reference in new issue
Block a user