Finished bel, moving on to title

Mikayla Maki created

Change summary

crates/terminal/src/connection.rs       | 23 +++++-
crates/terminal/src/terminal.rs         | 85 +++++++-------------------
crates/terminal/src/terminal_element.rs | 20 ++++-
styles/package-lock.json                |  1 
4 files changed, 55 insertions(+), 74 deletions(-)

Detailed changes

crates/terminal/src/connection.rs 🔗

@@ -3,7 +3,7 @@ mod keymappings;
 use alacritty_terminal::{
     ansi::{ClearMode, Handler},
     config::{Config, Program, PtyConfig},
-    event::{Event as AlacTermEvent, Notify},
+    event::{Event as AlacTermEvent, EventListener, Notify},
     event_loop::{EventLoop, Msg, Notifier},
     grid::Scroll,
     sync::FairMutex,
@@ -11,16 +11,16 @@ use alacritty_terminal::{
     tty::{self, setup_env},
     Term,
 };
-use futures::{channel::mpsc::unbounded, StreamExt};
+use futures::{
+    channel::mpsc::{unbounded, UnboundedSender},
+    StreamExt,
+};
 use settings::{Settings, Shell};
 use std::{collections::HashMap, path::PathBuf, sync::Arc};
 
 use gpui::{keymap::Keystroke, ClipboardItem, CursorStyle, Entity, ModelContext};
 
-use crate::{
-    color_translation::{get_color_at_index, to_alac_rgb},
-    ZedListener,
-};
+use crate::color_translation::{get_color_at_index, to_alac_rgb};
 
 use self::keymappings::to_esc_str;
 
@@ -34,6 +34,17 @@ pub enum Event {
     Activate,
     Wakeup,
     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 {

crates/terminal/src/terminal.rs 🔗

@@ -3,15 +3,10 @@ pub mod connection;
 mod modal;
 pub mod terminal_element;
 
-use alacritty_terminal::{
-    event::{Event as AlacTermEvent, EventListener},
-    term::SizeInfo,
-};
+use alacritty_terminal::term::SizeInfo;
 
 use connection::{Event, TerminalConnection};
 use dirs::home_dir;
-use editor::Input;
-use futures::channel::mpsc::UnboundedSender;
 use gpui::{
     actions, elements::*, keymap::Keystroke, AppContext, ClipboardItem, Entity, ModelHandle,
     MutableAppContext, View, ViewContext,
@@ -31,9 +26,6 @@ const DEBUG_TERMINAL_HEIGHT: f32 = 200.;
 const DEBUG_CELL_WIDTH: 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
 #[derive(Clone, Debug, PartialEq)]
 pub struct ScrollTerminal(pub i32);
@@ -67,20 +59,9 @@ pub fn init(cx: &mut MutableAppContext) {
     cx.add_action(deploy_modal);
     cx.add_action(Terminal::copy);
     cx.add_action(Terminal::paste);
-    cx.add_action(Terminal::input);
     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
 pub struct Terminal {
     connection: ModelHandle<TerminalConnection>,
@@ -142,6 +123,10 @@ impl Terminal {
                 this.has_bell = true;
                 cx.emit(Event::TitleChanged);
             }
+            // Event::Input => {
+            //     this.has_bell = false;
+            //     cx.emit(Event::TitleChanged);
+            // }
             _ => cx.emit(*event),
         })
         .detach();
@@ -154,16 +139,9 @@ impl Terminal {
         }
     }
 
-    fn input(&mut self, Input(text): &Input, 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;
-            cx.emit(Event::TitleChanged);
-        }
+    fn clear_bel(&mut self, cx: &mut ViewContext<Self>) {
+        self.has_bell = false;
+        cx.emit(Event::TitleChanged);
     }
 
     fn clear(&mut self, _: &Clear, cx: &mut ViewContext<Self>) {
@@ -240,8 +218,7 @@ impl View for Terminal {
     fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> ElementBox {
         let element = {
             let connection_handle = self.connection.clone().downgrade();
-            let view_id = cx.view_id();
-            TerminalEl::new(view_id, connection_handle, self.modal).contained()
+            TerminalEl::new(cx.handle(), connection_handle, self.modal).contained()
         };
 
         if self.modal {
@@ -274,37 +251,17 @@ impl Item for Terminal {
         tab_theme: &theme::Tab,
         cx: &gpui::AppContext,
     ) -> ElementBox {
-        let settings = cx.global::<Settings>();
-        let search_theme = &settings.theme.search; //TODO properly integrate themes
-
-        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(
-                self.connection.read(cx).title.clone(),
-                tab_theme.label.clone(),
+        Flex::row()
+            .with_child(
+                Label::new(
+                    self.connection.read(cx).title.clone(),
+                    tab_theme.label.clone(),
+                )
+                .aligned()
+                .contained()
+                .boxed(),
             )
-            .aligned()
-            .contained()
-            .with_margin_left(if self.has_bell {
-                search_theme.tab_icon_spacing
-            } else {
-                0.
-            })
-            .boxed(),
-        )
-        .boxed()
+            .boxed()
     }
 
     fn clone_on_split(&self, cx: &mut ViewContext<Self>) -> Option<Self> {
@@ -365,6 +322,10 @@ impl Item for Terminal {
         self.has_new_content
     }
 
+    fn has_conflict(&self, _: &AppContext) -> bool {
+        self.has_bell
+    }
+
     fn should_update_tab_on_event(event: &Self::Event) -> bool {
         matches!(event, &Event::TitleChanged)
     }

crates/terminal/src/terminal_element.rs 🔗

@@ -22,6 +22,7 @@ use gpui::{
     text_layout::{Line, RunStyle},
     Event, FontCache, KeyDownEvent, MouseButton, MouseButtonEvent, MouseMovedEvent, MouseRegion,
     PaintContext, Quad, ScrollWheelEvent, SizeConstraint, TextLayoutCache, WeakModelHandle,
+    WeakViewHandle,
 };
 use itertools::Itertools;
 use ordered_float::OrderedFloat;
@@ -32,7 +33,11 @@ use util::ResultExt;
 use std::{cmp::min, ops::Range, sync::Arc};
 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
 ///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?
 pub struct TerminalEl {
     connection: WeakModelHandle<TerminalConnection>,
-    view_id: usize,
+    view: WeakViewHandle<Terminal>,
     modal: bool,
 }
 
@@ -100,12 +105,12 @@ pub struct LayoutState {
 
 impl TerminalEl {
     pub fn new(
-        view_id: usize,
+        view: WeakViewHandle<Terminal>,
         connection: WeakModelHandle<TerminalConnection>,
         modal: bool,
     ) -> TerminalEl {
         TerminalEl {
-            view_id,
+            view,
             connection,
             modal,
         }
@@ -238,7 +243,7 @@ impl Element for TerminalEl {
             attach_mouse_handlers(
                 origin,
                 cur_size,
-                self.view_id,
+                self.view.id(),
                 &layout.terminal,
                 visible_bounds,
                 cx,
@@ -383,6 +388,11 @@ impl Element for TerminalEl {
                     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
                     .upgrade(cx.app)
                     .map(|connection| {

styles/package-lock.json 🔗

@@ -5,7 +5,6 @@
   "requires": true,
   "packages": {
     "": {
-      "name": "styles",
       "version": "1.0.0",
       "license": "ISC",
       "dependencies": {