Define terminal settings in terminal crate
This commit is contained in:
parent
cee7edabf9
commit
bc5b78198a
13 changed files with 208 additions and 279 deletions
|
@ -15,6 +15,7 @@ settings = { path = "../settings" }
|
|||
db = { path = "../db" }
|
||||
theme = { path = "../theme" }
|
||||
util = { path = "../util" }
|
||||
|
||||
alacritty_terminal = { git = "https://github.com/zed-industries/alacritty", rev = "a51dbe25d67e84d6ed4261e640d3954fbdd9be45" }
|
||||
procinfo = { git = "https://github.com/zed-industries/wezterm", rev = "5cd757e5f2eb039ed0c6bb6512223e69d5efc64d", default-features = false }
|
||||
smallvec.workspace = true
|
||||
|
@ -27,6 +28,7 @@ dirs = "4.0.0"
|
|||
shellexpand = "2.1.0"
|
||||
libc = "0.2"
|
||||
anyhow.workspace = true
|
||||
schemars.workspace = true
|
||||
thiserror.workspace = true
|
||||
lazy_static.workspace = true
|
||||
serde.workspace = true
|
||||
|
|
|
@ -31,8 +31,9 @@ use mappings::mouse::{
|
|||
};
|
||||
|
||||
use procinfo::LocalProcessInfo;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use settings::{AlternateScroll, Settings, Shell, TerminalBlink};
|
||||
use settings::Settings;
|
||||
use util::truncate_and_trailoff;
|
||||
|
||||
use std::{
|
||||
|
@ -48,11 +49,12 @@ use std::{
|
|||
use thiserror::Error;
|
||||
|
||||
use gpui::{
|
||||
fonts,
|
||||
geometry::vector::{vec2f, Vector2F},
|
||||
keymap_matcher::Keystroke,
|
||||
platform::{MouseButton, MouseMovedEvent, TouchPhase},
|
||||
scene::{MouseDown, MouseDrag, MouseScrollWheel, MouseUp},
|
||||
ClipboardItem, Entity, ModelContext, Task,
|
||||
AppContext, ClipboardItem, Entity, ModelContext, Task,
|
||||
};
|
||||
|
||||
use crate::mappings::{
|
||||
|
@ -114,6 +116,105 @@ impl EventListener for ZedListener {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
settings::register_setting::<TerminalSettings>(cx);
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct TerminalSettings {
|
||||
pub shell: Shell,
|
||||
pub working_directory: WorkingDirectory,
|
||||
pub font_size: Option<f32>,
|
||||
pub font_family: Option<String>,
|
||||
pub line_height: TerminalLineHeight,
|
||||
pub font_features: Option<fonts::Features>,
|
||||
pub env: HashMap<String, String>,
|
||||
pub blinking: TerminalBlink,
|
||||
pub alternate_scroll: AlternateScroll,
|
||||
pub option_as_meta: bool,
|
||||
pub copy_on_select: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct TerminalSettingsContent {
|
||||
pub shell: Option<Shell>,
|
||||
pub working_directory: Option<WorkingDirectory>,
|
||||
pub font_size: Option<f32>,
|
||||
pub font_family: Option<String>,
|
||||
pub line_height: Option<TerminalLineHeight>,
|
||||
pub font_features: Option<fonts::Features>,
|
||||
pub env: Option<HashMap<String, String>>,
|
||||
pub blinking: Option<TerminalBlink>,
|
||||
pub alternate_scroll: Option<AlternateScroll>,
|
||||
pub option_as_meta: Option<bool>,
|
||||
pub copy_on_select: Option<bool>,
|
||||
}
|
||||
|
||||
impl settings::Setting for TerminalSettings {
|
||||
const KEY: Option<&'static str> = Some("terminal");
|
||||
|
||||
type FileContent = TerminalSettingsContent;
|
||||
|
||||
fn load(
|
||||
default_value: &Self::FileContent,
|
||||
user_values: &[&Self::FileContent],
|
||||
_: &AppContext,
|
||||
) -> Self {
|
||||
Self::load_via_json_merge(default_value, user_values)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, Default)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum TerminalLineHeight {
|
||||
#[default]
|
||||
Comfortable,
|
||||
Standard,
|
||||
Custom(f32),
|
||||
}
|
||||
|
||||
impl TerminalLineHeight {
|
||||
pub fn value(&self) -> f32 {
|
||||
match self {
|
||||
TerminalLineHeight::Comfortable => 1.618,
|
||||
TerminalLineHeight::Standard => 1.3,
|
||||
TerminalLineHeight::Custom(line_height) => *line_height,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum TerminalBlink {
|
||||
Off,
|
||||
TerminalControlled,
|
||||
On,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Shell {
|
||||
System,
|
||||
Program(String),
|
||||
WithArguments { program: String, args: Vec<String> },
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum AlternateScroll {
|
||||
On,
|
||||
Off,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum WorkingDirectory {
|
||||
CurrentProjectDirectory,
|
||||
FirstProjectDirectory,
|
||||
AlwaysHome,
|
||||
Always { directory: String },
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
pub struct TerminalSize {
|
||||
pub cell_width: f32,
|
||||
|
@ -1049,16 +1150,7 @@ impl Terminal {
|
|||
}
|
||||
|
||||
pub fn mouse_up(&mut self, e: &MouseUp, origin: Vector2F, cx: &mut ModelContext<Self>) {
|
||||
let settings = cx.global::<Settings>();
|
||||
let copy_on_select = settings
|
||||
.terminal_overrides
|
||||
.copy_on_select
|
||||
.unwrap_or_else(|| {
|
||||
settings
|
||||
.terminal_defaults
|
||||
.copy_on_select
|
||||
.expect("Should be set in defaults")
|
||||
});
|
||||
let setting = settings::get_setting::<TerminalSettings>(None, cx);
|
||||
|
||||
let position = e.position.sub(origin);
|
||||
if self.mouse_mode(e.shift) {
|
||||
|
@ -1072,7 +1164,7 @@ impl Terminal {
|
|||
self.pty_tx.notify(bytes);
|
||||
}
|
||||
} else {
|
||||
if e.button == MouseButton::Left && copy_on_select {
|
||||
if e.button == MouseButton::Left && setting.copy_on_select {
|
||||
self.copy();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue