Define terminal settings in terminal crate
This commit is contained in:
parent
cee7edabf9
commit
bc5b78198a
13 changed files with 208 additions and 279 deletions
|
@ -16,7 +16,7 @@ use gpui::{
|
|||
use itertools::Itertools;
|
||||
use language::CursorShape;
|
||||
use ordered_float::OrderedFloat;
|
||||
use settings::Settings;
|
||||
use settings::{font_size_for_setting, Settings};
|
||||
use terminal::{
|
||||
alacritty_terminal::{
|
||||
ansi::{Color as AnsiColor, Color::Named, CursorShape as AlacCursorShape, NamedColor},
|
||||
|
@ -25,7 +25,7 @@ use terminal::{
|
|||
term::{cell::Flags, TermMode},
|
||||
},
|
||||
mappings::colors::convert_color,
|
||||
IndexedCell, Terminal, TerminalContent, TerminalSize,
|
||||
IndexedCell, Terminal, TerminalContent, TerminalSettings, TerminalSize,
|
||||
};
|
||||
use theme::TerminalStyle;
|
||||
use util::ResultExt;
|
||||
|
@ -510,47 +510,6 @@ impl TerminalElement {
|
|||
|
||||
scene.push_mouse_region(region);
|
||||
}
|
||||
|
||||
///Configures a text style from the current settings.
|
||||
pub fn make_text_style(font_cache: &FontCache, settings: &Settings) -> TextStyle {
|
||||
let font_family_name = settings
|
||||
.terminal_overrides
|
||||
.font_family
|
||||
.as_ref()
|
||||
.or(settings.terminal_defaults.font_family.as_ref())
|
||||
.unwrap_or(&settings.buffer_font_family_name);
|
||||
let font_features = settings
|
||||
.terminal_overrides
|
||||
.font_features
|
||||
.as_ref()
|
||||
.or(settings.terminal_defaults.font_features.as_ref())
|
||||
.unwrap_or(&settings.buffer_font_features);
|
||||
|
||||
let family_id = font_cache
|
||||
.load_family(&[font_family_name], &font_features)
|
||||
.log_err()
|
||||
.unwrap_or(settings.buffer_font_family);
|
||||
|
||||
let font_size = settings
|
||||
.terminal_overrides
|
||||
.font_size
|
||||
.or(settings.terminal_defaults.font_size)
|
||||
.unwrap_or(settings.buffer_font_size);
|
||||
|
||||
let font_id = font_cache
|
||||
.select_font(family_id, &Default::default())
|
||||
.unwrap();
|
||||
|
||||
TextStyle {
|
||||
color: settings.theme.editor.text_color,
|
||||
font_family_id: family_id,
|
||||
font_family_name: font_cache.family_name(family_id).unwrap(),
|
||||
font_id,
|
||||
font_size,
|
||||
font_properties: Default::default(),
|
||||
underline: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Element<TerminalView> for TerminalElement {
|
||||
|
@ -564,19 +523,50 @@ impl Element<TerminalView> for TerminalElement {
|
|||
cx: &mut LayoutContext<TerminalView>,
|
||||
) -> (gpui::geometry::vector::Vector2F, Self::LayoutState) {
|
||||
let settings = cx.global::<Settings>();
|
||||
let font_cache = cx.font_cache();
|
||||
let terminal_settings = settings::get_setting::<TerminalSettings>(None, cx);
|
||||
|
||||
//Setup layout information
|
||||
let terminal_theme = settings.theme.terminal.clone(); //TODO: Try to minimize this clone.
|
||||
let link_style = settings.theme.editor.link_definition;
|
||||
let tooltip_style = settings.theme.tooltip.clone();
|
||||
|
||||
let text_style = TerminalElement::make_text_style(font_cache, settings);
|
||||
let font_cache = cx.font_cache();
|
||||
let font_size = font_size_for_setting(
|
||||
terminal_settings
|
||||
.font_size
|
||||
.unwrap_or(settings.buffer_font_size),
|
||||
cx,
|
||||
);
|
||||
let font_family_name = terminal_settings
|
||||
.font_family
|
||||
.as_ref()
|
||||
.unwrap_or(&settings.buffer_font_family_name);
|
||||
let font_features = terminal_settings
|
||||
.font_features
|
||||
.as_ref()
|
||||
.unwrap_or(&settings.buffer_font_features);
|
||||
let family_id = font_cache
|
||||
.load_family(&[font_family_name], &font_features)
|
||||
.log_err()
|
||||
.unwrap_or(settings.buffer_font_family);
|
||||
let font_id = font_cache
|
||||
.select_font(family_id, &Default::default())
|
||||
.unwrap();
|
||||
|
||||
let text_style = TextStyle {
|
||||
color: settings.theme.editor.text_color,
|
||||
font_family_id: family_id,
|
||||
font_family_name: font_cache.family_name(family_id).unwrap(),
|
||||
font_id,
|
||||
font_size,
|
||||
font_properties: Default::default(),
|
||||
underline: Default::default(),
|
||||
};
|
||||
let selection_color = settings.theme.editor.selection.selection;
|
||||
let match_color = settings.theme.search.match_background;
|
||||
let gutter;
|
||||
let dimensions = {
|
||||
let line_height = text_style.font_size * settings.terminal_line_height();
|
||||
let line_height = text_style.font_size * terminal_settings.line_height.value();
|
||||
let cell_width = font_cache.em_advance(text_style.font_id, text_style.font_size);
|
||||
gutter = cell_width;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ mod persistence;
|
|||
pub mod terminal_button;
|
||||
pub mod terminal_element;
|
||||
|
||||
use crate::{persistence::TERMINAL_DB, terminal_element::TerminalElement};
|
||||
use context_menu::{ContextMenu, ContextMenuItem};
|
||||
use dirs::home_dir;
|
||||
use gpui::{
|
||||
|
@ -16,7 +17,6 @@ use gpui::{
|
|||
};
|
||||
use project::{LocalWorktree, Project};
|
||||
use serde::Deserialize;
|
||||
use settings::{Settings, TerminalBlink, WorkingDirectory};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use smol::Timer;
|
||||
use std::{
|
||||
|
@ -30,7 +30,7 @@ use terminal::{
|
|||
index::Point,
|
||||
term::{search::RegexSearch, TermMode},
|
||||
},
|
||||
Event, Terminal,
|
||||
Event, Terminal, TerminalBlink, WorkingDirectory,
|
||||
};
|
||||
use util::ResultExt;
|
||||
use workspace::{
|
||||
|
@ -41,7 +41,7 @@ use workspace::{
|
|||
Pane, ToolbarItemLocation, Workspace, WorkspaceId,
|
||||
};
|
||||
|
||||
use crate::{persistence::TERMINAL_DB, terminal_element::TerminalElement};
|
||||
pub use terminal::TerminalSettings;
|
||||
|
||||
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
|
||||
|
||||
|
@ -63,6 +63,8 @@ actions!(
|
|||
impl_actions!(terminal, [SendText, SendKeystroke]);
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
terminal::init(cx);
|
||||
|
||||
cx.add_action(TerminalView::deploy);
|
||||
|
||||
register_deserializable_item::<TerminalView>(cx);
|
||||
|
@ -101,9 +103,9 @@ impl TerminalView {
|
|||
_: &workspace::NewTerminal,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) {
|
||||
let strategy = cx.global::<Settings>().terminal_strategy();
|
||||
|
||||
let working_directory = get_working_directory(workspace, cx, strategy);
|
||||
let strategy = settings::get_setting::<TerminalSettings>(None, cx);
|
||||
let working_directory =
|
||||
get_working_directory(workspace, cx, strategy.working_directory.clone());
|
||||
|
||||
let window_id = cx.window_id();
|
||||
let terminal = workspace
|
||||
|
@ -215,10 +217,7 @@ impl TerminalView {
|
|||
self.terminal.update(cx, |term, cx| {
|
||||
term.try_keystroke(
|
||||
&Keystroke::parse("ctrl-cmd-space").unwrap(),
|
||||
cx.global::<Settings>()
|
||||
.terminal_overrides
|
||||
.option_as_meta
|
||||
.unwrap_or(false),
|
||||
settings::get_setting::<TerminalSettings>(None, cx).option_as_meta,
|
||||
)
|
||||
});
|
||||
}
|
||||
|
@ -244,16 +243,7 @@ impl TerminalView {
|
|||
return true;
|
||||
}
|
||||
|
||||
let setting = {
|
||||
let settings = cx.global::<Settings>();
|
||||
settings
|
||||
.terminal_overrides
|
||||
.blinking
|
||||
.clone()
|
||||
.unwrap_or(TerminalBlink::TerminalControlled)
|
||||
};
|
||||
|
||||
match setting {
|
||||
match settings::get_setting::<TerminalSettings>(None, cx).blinking {
|
||||
//If the user requested to never blink, don't blink it.
|
||||
TerminalBlink::Off => true,
|
||||
//If the terminal is controlling it, check terminal mode
|
||||
|
@ -346,10 +336,7 @@ impl TerminalView {
|
|||
self.terminal.update(cx, |term, cx| {
|
||||
term.try_keystroke(
|
||||
&keystroke,
|
||||
cx.global::<Settings>()
|
||||
.terminal_overrides
|
||||
.option_as_meta
|
||||
.unwrap_or(false),
|
||||
settings::get_setting::<TerminalSettings>(None, cx).option_as_meta,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -412,10 +399,7 @@ impl View for TerminalView {
|
|||
self.terminal.update(cx, |term, cx| {
|
||||
term.try_keystroke(
|
||||
&event.keystroke,
|
||||
cx.global::<Settings>()
|
||||
.terminal_overrides
|
||||
.option_as_meta
|
||||
.unwrap_or(false),
|
||||
settings::get_setting::<TerminalSettings>(None, cx).option_as_meta,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
@ -617,7 +601,9 @@ impl Item for TerminalView {
|
|||
.flatten()
|
||||
.or_else(|| {
|
||||
cx.read(|cx| {
|
||||
let strategy = cx.global::<Settings>().terminal_strategy();
|
||||
let strategy = settings::get_setting::<TerminalSettings>(None, cx)
|
||||
.working_directory
|
||||
.clone();
|
||||
workspace
|
||||
.upgrade(cx)
|
||||
.map(|workspace| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue