Finished bel, moving on to title
This commit is contained in:
parent
d76cdb01be
commit
c19956373a
4 changed files with 55 additions and 74 deletions
|
@ -3,7 +3,7 @@ mod keymappings;
|
||||||
use alacritty_terminal::{
|
use alacritty_terminal::{
|
||||||
ansi::{ClearMode, Handler},
|
ansi::{ClearMode, Handler},
|
||||||
config::{Config, Program, PtyConfig},
|
config::{Config, Program, PtyConfig},
|
||||||
event::{Event as AlacTermEvent, Notify},
|
event::{Event as AlacTermEvent, EventListener, Notify},
|
||||||
event_loop::{EventLoop, Msg, Notifier},
|
event_loop::{EventLoop, Msg, Notifier},
|
||||||
grid::Scroll,
|
grid::Scroll,
|
||||||
sync::FairMutex,
|
sync::FairMutex,
|
||||||
|
@ -11,16 +11,16 @@ use alacritty_terminal::{
|
||||||
tty::{self, setup_env},
|
tty::{self, setup_env},
|
||||||
Term,
|
Term,
|
||||||
};
|
};
|
||||||
use futures::{channel::mpsc::unbounded, StreamExt};
|
use futures::{
|
||||||
|
channel::mpsc::{unbounded, UnboundedSender},
|
||||||
|
StreamExt,
|
||||||
|
};
|
||||||
use settings::{Settings, Shell};
|
use settings::{Settings, Shell};
|
||||||
use std::{collections::HashMap, path::PathBuf, sync::Arc};
|
use std::{collections::HashMap, path::PathBuf, sync::Arc};
|
||||||
|
|
||||||
use gpui::{keymap::Keystroke, ClipboardItem, CursorStyle, Entity, ModelContext};
|
use gpui::{keymap::Keystroke, ClipboardItem, CursorStyle, Entity, ModelContext};
|
||||||
|
|
||||||
use crate::{
|
use crate::color_translation::{get_color_at_index, to_alac_rgb};
|
||||||
color_translation::{get_color_at_index, to_alac_rgb},
|
|
||||||
ZedListener,
|
|
||||||
};
|
|
||||||
|
|
||||||
use self::keymappings::to_esc_str;
|
use self::keymappings::to_esc_str;
|
||||||
|
|
||||||
|
@ -34,6 +34,17 @@ pub enum Event {
|
||||||
Activate,
|
Activate,
|
||||||
Wakeup,
|
Wakeup,
|
||||||
Bell,
|
Bell,
|
||||||
|
KeyInput,
|
||||||
|
}
|
||||||
|
|
||||||
|
///A translation struct for Alacritty to communicate with us from their event loop
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ZedListener(UnboundedSender<AlacTermEvent>);
|
||||||
|
|
||||||
|
impl EventListener for ZedListener {
|
||||||
|
fn send_event(&self, event: AlacTermEvent) {
|
||||||
|
self.0.unbounded_send(event).ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TerminalConnection {
|
pub struct TerminalConnection {
|
||||||
|
|
|
@ -3,15 +3,10 @@ pub mod connection;
|
||||||
mod modal;
|
mod modal;
|
||||||
pub mod terminal_element;
|
pub mod terminal_element;
|
||||||
|
|
||||||
use alacritty_terminal::{
|
use alacritty_terminal::term::SizeInfo;
|
||||||
event::{Event as AlacTermEvent, EventListener},
|
|
||||||
term::SizeInfo,
|
|
||||||
};
|
|
||||||
|
|
||||||
use connection::{Event, TerminalConnection};
|
use connection::{Event, TerminalConnection};
|
||||||
use dirs::home_dir;
|
use dirs::home_dir;
|
||||||
use editor::Input;
|
|
||||||
use futures::channel::mpsc::UnboundedSender;
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, elements::*, keymap::Keystroke, AppContext, ClipboardItem, Entity, ModelHandle,
|
actions, elements::*, keymap::Keystroke, AppContext, ClipboardItem, Entity, ModelHandle,
|
||||||
MutableAppContext, View, ViewContext,
|
MutableAppContext, View, ViewContext,
|
||||||
|
@ -31,9 +26,6 @@ const DEBUG_TERMINAL_HEIGHT: f32 = 200.;
|
||||||
const DEBUG_CELL_WIDTH: f32 = 5.;
|
const DEBUG_CELL_WIDTH: f32 = 5.;
|
||||||
const DEBUG_LINE_HEIGHT: f32 = 5.;
|
const DEBUG_LINE_HEIGHT: f32 = 5.;
|
||||||
|
|
||||||
//For bel, use a yellow dot. (equivalent to dirty file with conflict)
|
|
||||||
//For title, introduce max title length and
|
|
||||||
|
|
||||||
///Event to transmit the scroll from the element to the view
|
///Event to transmit the scroll from the element to the view
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct ScrollTerminal(pub i32);
|
pub struct ScrollTerminal(pub i32);
|
||||||
|
@ -67,20 +59,9 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||||
cx.add_action(deploy_modal);
|
cx.add_action(deploy_modal);
|
||||||
cx.add_action(Terminal::copy);
|
cx.add_action(Terminal::copy);
|
||||||
cx.add_action(Terminal::paste);
|
cx.add_action(Terminal::paste);
|
||||||
cx.add_action(Terminal::input);
|
|
||||||
cx.add_action(Terminal::clear);
|
cx.add_action(Terminal::clear);
|
||||||
}
|
}
|
||||||
|
|
||||||
///A translation struct for Alacritty to communicate with us from their event loop
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ZedListener(UnboundedSender<AlacTermEvent>);
|
|
||||||
|
|
||||||
impl EventListener for ZedListener {
|
|
||||||
fn send_event(&self, event: AlacTermEvent) {
|
|
||||||
self.0.unbounded_send(event).ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///A terminal view, maintains the PTY's file handles and communicates with the terminal
|
///A terminal view, maintains the PTY's file handles and communicates with the terminal
|
||||||
pub struct Terminal {
|
pub struct Terminal {
|
||||||
connection: ModelHandle<TerminalConnection>,
|
connection: ModelHandle<TerminalConnection>,
|
||||||
|
@ -142,6 +123,10 @@ impl Terminal {
|
||||||
this.has_bell = true;
|
this.has_bell = true;
|
||||||
cx.emit(Event::TitleChanged);
|
cx.emit(Event::TitleChanged);
|
||||||
}
|
}
|
||||||
|
// Event::Input => {
|
||||||
|
// this.has_bell = false;
|
||||||
|
// cx.emit(Event::TitleChanged);
|
||||||
|
// }
|
||||||
_ => cx.emit(*event),
|
_ => cx.emit(*event),
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
@ -154,17 +139,10 @@ impl Terminal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn input(&mut self, Input(text): &Input, cx: &mut ViewContext<Self>) {
|
fn clear_bel(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
self.connection.update(cx, |connection, _| {
|
|
||||||
//TODO: This is probably not encoding UTF8 correctly (see alacritty/src/input.rs:L825-837)
|
|
||||||
connection.write_to_pty(text.clone());
|
|
||||||
});
|
|
||||||
|
|
||||||
if self.has_bell {
|
|
||||||
self.has_bell = false;
|
self.has_bell = false;
|
||||||
cx.emit(Event::TitleChanged);
|
cx.emit(Event::TitleChanged);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn clear(&mut self, _: &Clear, cx: &mut ViewContext<Self>) {
|
fn clear(&mut self, _: &Clear, cx: &mut ViewContext<Self>) {
|
||||||
self.connection
|
self.connection
|
||||||
|
@ -240,8 +218,7 @@ impl View for Terminal {
|
||||||
fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> ElementBox {
|
fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> ElementBox {
|
||||||
let element = {
|
let element = {
|
||||||
let connection_handle = self.connection.clone().downgrade();
|
let connection_handle = self.connection.clone().downgrade();
|
||||||
let view_id = cx.view_id();
|
TerminalEl::new(cx.handle(), connection_handle, self.modal).contained()
|
||||||
TerminalEl::new(view_id, connection_handle, self.modal).contained()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.modal {
|
if self.modal {
|
||||||
|
@ -274,34 +251,14 @@ impl Item for Terminal {
|
||||||
tab_theme: &theme::Tab,
|
tab_theme: &theme::Tab,
|
||||||
cx: &gpui::AppContext,
|
cx: &gpui::AppContext,
|
||||||
) -> ElementBox {
|
) -> ElementBox {
|
||||||
let settings = cx.global::<Settings>();
|
Flex::row()
|
||||||
let search_theme = &settings.theme.search; //TODO properly integrate themes
|
.with_child(
|
||||||
|
|
||||||
let mut flex = Flex::row();
|
|
||||||
|
|
||||||
if self.has_bell {
|
|
||||||
flex.add_child(
|
|
||||||
Svg::new("icons/bolt_12.svg") //TODO: Swap out for a better icon, or at least resize this
|
|
||||||
.with_color(tab_theme.label.text.color)
|
|
||||||
.constrained()
|
|
||||||
.with_width(search_theme.tab_icon_width)
|
|
||||||
.aligned()
|
|
||||||
.boxed(),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
flex.with_child(
|
|
||||||
Label::new(
|
Label::new(
|
||||||
self.connection.read(cx).title.clone(),
|
self.connection.read(cx).title.clone(),
|
||||||
tab_theme.label.clone(),
|
tab_theme.label.clone(),
|
||||||
)
|
)
|
||||||
.aligned()
|
.aligned()
|
||||||
.contained()
|
.contained()
|
||||||
.with_margin_left(if self.has_bell {
|
|
||||||
search_theme.tab_icon_spacing
|
|
||||||
} else {
|
|
||||||
0.
|
|
||||||
})
|
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
.boxed()
|
.boxed()
|
||||||
|
@ -365,6 +322,10 @@ impl Item for Terminal {
|
||||||
self.has_new_content
|
self.has_new_content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn has_conflict(&self, _: &AppContext) -> bool {
|
||||||
|
self.has_bell
|
||||||
|
}
|
||||||
|
|
||||||
fn should_update_tab_on_event(event: &Self::Event) -> bool {
|
fn should_update_tab_on_event(event: &Self::Event) -> bool {
|
||||||
matches!(event, &Event::TitleChanged)
|
matches!(event, &Event::TitleChanged)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ use gpui::{
|
||||||
text_layout::{Line, RunStyle},
|
text_layout::{Line, RunStyle},
|
||||||
Event, FontCache, KeyDownEvent, MouseButton, MouseButtonEvent, MouseMovedEvent, MouseRegion,
|
Event, FontCache, KeyDownEvent, MouseButton, MouseButtonEvent, MouseMovedEvent, MouseRegion,
|
||||||
PaintContext, Quad, ScrollWheelEvent, SizeConstraint, TextLayoutCache, WeakModelHandle,
|
PaintContext, Quad, ScrollWheelEvent, SizeConstraint, TextLayoutCache, WeakModelHandle,
|
||||||
|
WeakViewHandle,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
|
@ -32,7 +33,11 @@ use util::ResultExt;
|
||||||
use std::{cmp::min, ops::Range, sync::Arc};
|
use std::{cmp::min, ops::Range, sync::Arc};
|
||||||
use std::{fmt::Debug, ops::Sub};
|
use std::{fmt::Debug, ops::Sub};
|
||||||
|
|
||||||
use crate::{color_translation::convert_color, connection::TerminalConnection, ZedListener};
|
use crate::{
|
||||||
|
color_translation::convert_color,
|
||||||
|
connection::{TerminalConnection, ZedListener},
|
||||||
|
Terminal,
|
||||||
|
};
|
||||||
|
|
||||||
///Scrolling is unbearably sluggish by default. Alacritty supports a configurable
|
///Scrolling is unbearably sluggish by default. Alacritty supports a configurable
|
||||||
///Scroll multiplier that is set to 3 by default. This will be removed when I
|
///Scroll multiplier that is set to 3 by default. This will be removed when I
|
||||||
|
@ -48,7 +53,7 @@ const DEBUG_GRID: bool = false;
|
||||||
///We need to keep a reference to the view for mouse events, do we need it for any other terminal stuff, or can we move that to connection?
|
///We need to keep a reference to the view for mouse events, do we need it for any other terminal stuff, or can we move that to connection?
|
||||||
pub struct TerminalEl {
|
pub struct TerminalEl {
|
||||||
connection: WeakModelHandle<TerminalConnection>,
|
connection: WeakModelHandle<TerminalConnection>,
|
||||||
view_id: usize,
|
view: WeakViewHandle<Terminal>,
|
||||||
modal: bool,
|
modal: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,12 +105,12 @@ pub struct LayoutState {
|
||||||
|
|
||||||
impl TerminalEl {
|
impl TerminalEl {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
view_id: usize,
|
view: WeakViewHandle<Terminal>,
|
||||||
connection: WeakModelHandle<TerminalConnection>,
|
connection: WeakModelHandle<TerminalConnection>,
|
||||||
modal: bool,
|
modal: bool,
|
||||||
) -> TerminalEl {
|
) -> TerminalEl {
|
||||||
TerminalEl {
|
TerminalEl {
|
||||||
view_id,
|
view,
|
||||||
connection,
|
connection,
|
||||||
modal,
|
modal,
|
||||||
}
|
}
|
||||||
|
@ -238,7 +243,7 @@ impl Element for TerminalEl {
|
||||||
attach_mouse_handlers(
|
attach_mouse_handlers(
|
||||||
origin,
|
origin,
|
||||||
cur_size,
|
cur_size,
|
||||||
self.view_id,
|
self.view.id(),
|
||||||
&layout.terminal,
|
&layout.terminal,
|
||||||
visible_bounds,
|
visible_bounds,
|
||||||
cx,
|
cx,
|
||||||
|
@ -383,6 +388,11 @@ impl Element for TerminalEl {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO Talk to keith about how to catch events emitted from an element.
|
||||||
|
if let Some(view) = self.view.upgrade(cx.app) {
|
||||||
|
view.update(cx.app, |view, cx| view.clear_bel(cx))
|
||||||
|
}
|
||||||
|
|
||||||
self.connection
|
self.connection
|
||||||
.upgrade(cx.app)
|
.upgrade(cx.app)
|
||||||
.map(|connection| {
|
.map(|connection| {
|
||||||
|
|
1
styles/package-lock.json
generated
1
styles/package-lock.json
generated
|
@ -5,7 +5,6 @@
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "styles",
|
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue