Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add `Terminal` component
Marshall Bowers82577b4acc3f
diff --git a/crates/storybook2/src/stories/components.rs b/crates/storybook2/src/stories/components.rsindex 51dea1b675a..4a78644b713 100644--- a/crates/storybook2/src/stories/components.rs+++ b/crates/storybook2/src/stories/components.rs@@ -3,4 +3,5 @@ pub mod buffer;pub mod panel;pub mod project_panel;pub mod tab;+pub mod terminal;pub mod workspace;diff --git a/crates/storybook2/src/stories/components/terminal.rs b/crates/storybook2/src/stories/components/terminal.rsnew file mode 100644index 00000000000..6a63306ed91--- /dev/null+++ b/crates/storybook2/src/stories/components/terminal.rs@@ -0,0 +1,26 @@+use std::marker::PhantomData;++use ui::prelude::*;+use ui::Terminal;++use crate::story::Story;++#[derive(Element)]+pub struct TerminalStory<S: 'static + Send + Sync + Clone> {+ state_type: PhantomData<S>,+}++impl<S: 'static + Send + Sync + Clone> TerminalStory<S> {+ pub fn new() -> Self {+ Self {+ state_type: PhantomData,+ }+ }++ fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {+ Story::container(cx)+ .child(Story::title_for::<_, Terminal<S>>(cx))+ .child(Story::label(cx, "Default"))+ .child(Terminal::new())+ }+}diff --git a/crates/storybook2/src/story_selector.rs b/crates/storybook2/src/story_selector.rsindex e3e04b56090..c66cdc20794 100644--- a/crates/storybook2/src/story_selector.rs+++ b/crates/storybook2/src/story_selector.rs@@ -39,6 +39,7 @@ pub enum ComponentStory {Panel,ProjectPanel,Tab,+ Terminal,Workspace,}@@ -54,6 +55,7 @@ impl ComponentStory {Self::Panel => components::panel::PanelStory::new().into_any(),Self::ProjectPanel => components::project_panel::ProjectPanelStory::new().into_any(),Self::Tab => components::tab::TabStory::new().into_any(),+ Self::Terminal => components::terminal::TerminalStory::new().into_any(),Self::Workspace => components::workspace::WorkspaceStory::new().into_any(),}}diff --git a/crates/ui2/src/components.rs b/crates/ui2/src/components.rsindex 31073b74bd1..468d4dca99c 100644--- a/crates/ui2/src/components.rs+++ b/crates/ui2/src/components.rs@@ -7,6 +7,7 @@ mod panes;mod project_panel;mod status_bar;mod tab;+mod terminal;mod workspace;pub use assistant_panel::*;@@ -18,4 +19,5 @@ pub use panes::*;pub use project_panel::*;pub use status_bar::*;pub use tab::*;+pub use terminal::*;pub use workspace::*;diff --git a/crates/ui2/src/components/terminal.rs b/crates/ui2/src/components/terminal.rsnew file mode 100644index 00000000000..96be31a895d--- /dev/null+++ b/crates/ui2/src/components/terminal.rs@@ -0,0 +1,89 @@+use std::marker::PhantomData;+use std::sync::Arc;++use gpui3::{relative, rems, Size};++use crate::prelude::*;+use crate::{theme, Icon, IconButton, Pane, Tab};++#[derive(Element)]+pub struct Terminal<S: 'static + Send + Sync + Clone> {+ state_type: PhantomData<S>,+}++impl<S: 'static + Send + Sync + Clone> Terminal<S> {+ pub fn new() -> Self {+ Self {+ state_type: PhantomData,+ }+ }++ fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {+ let theme = theme(cx);++ let can_navigate_back = true;+ let can_navigate_forward = false;++ div()+ .flex()+ .flex_col()+ .w_full()+ .child(+ // Terminal Tabs.+ div()+ .w_full()+ .flex()+ .fill(theme.middle.base.default.background)+ .child(+ div().px_1().flex().flex_none().gap_2().child(+ div()+ .flex()+ .items_center()+ .gap_px()+ .child(+ IconButton::new(Icon::ArrowLeft).state(+ InteractionState::Enabled.if_enabled(can_navigate_back),+ ),+ )+ .child(IconButton::new(Icon::ArrowRight).state(+ InteractionState::Enabled.if_enabled(can_navigate_forward),+ )),+ ),+ )+ .child(+ div().w_0().flex_1().h_full().child(+ div()+ .flex()+ .child(+ Tab::new()+ .title("zed — fish".to_string())+ .icon(Icon::Terminal)+ .close_side(IconSide::Right)+ .current(true),+ )+ .child(+ Tab::new()+ .title("zed — fish".to_string())+ .icon(Icon::Terminal)+ .close_side(IconSide::Right)+ .current(false),+ ),+ ),+ ),+ )+ // Terminal Pane.+ .child(Pane::new(+ ScrollState::default(),+ Size {+ width: relative(1.).into(),+ height: rems(36.).into(),+ },+ |_, payload| {+ let theme = payload.downcast_ref::<Arc<Theme>>().unwrap();++ vec![crate::static_data::terminal_buffer(&theme).into_any()]+ },+ Box::new(theme),+ ))+ }+}diff --git a/crates/ui2/src/components/workspace.rs b/crates/ui2/src/components/workspace.rsindex ba390074315..758d6002c15 100644--- a/crates/ui2/src/components/workspace.rs+++ b/crates/ui2/src/components/workspace.rs@@ -4,8 +4,11 @@ use std::sync::Arc;use chrono::DateTime;use gpui3::{relative, rems, Size};-use crate::{prelude::*, Pane, PaneGroup, SplitDirection};-use crate::{theme, v_stack, Panel, PanelAllowedSides, PanelSide, ProjectPanel, StatusBar};+use crate::prelude::*;+use crate::{+ theme, v_stack, Pane, PaneGroup, Panel, PanelAllowedSides, PanelSide, ProjectPanel,+ SplitDirection, StatusBar, Terminal,+};#[derive(Element)]pub struct WorkspaceElement<S: 'static + Send + Sync + Clone> {@@ -46,13 +49,10 @@ impl<S: 'static + Send + Sync + Clone> WorkspaceElement<S> {let theme = payload.downcast_ref::<Arc<Theme>>().unwrap();vec![- div()- .w_full()- .fill(gpui3::rgb::<gpui3::Hsla>(0xff0000))- .into_any(), // EditorPane::new(hello_world_rust_editor_with_status_example(- // &theme,- // ))- // .into_any()+ Terminal::new().into_any(), // EditorPane::new(hello_world_rust_editor_with_status_example(+ // &theme,+ // ))+ // .into_any()]},Box::new(theme.clone()),@@ -63,15 +63,7 @@ impl<S: 'static + Send + Sync + Clone> WorkspaceElement<S> {width: relative(1.).into(),height: temp_size,},- |_, _| {- vec![- div()- .w_full()- .fill(gpui3::rgb::<gpui3::Hsla>(0x00ff00))- .into_any(),- // Terminal::new().into_any()- ]- },+ |_, _| vec![Terminal::new().into_any()],Box::new(()),),],@@ -88,10 +80,7 @@ impl<S: 'static + Send + Sync + Clone> WorkspaceElement<S> {let theme = payload.downcast_ref::<Arc<Theme>>().unwrap();vec![- div()- .w_full()- .fill(gpui3::rgb::<gpui3::Hsla>(0x0000ff))- .into_any(),+ Terminal::new().into_any(),// EditorPane::new(hello_world_rust_editor_with_status_example(// &theme,// ))@@ -175,36 +164,36 @@ impl<S: 'static + Send + Sync + Clone> WorkspaceElement<S> {.side(PanelSide::Right),),// .child(- // Panel::new(- // self.right_panel_scroll_state.clone(),- // |_, payload| {- // vec![ChatPanel::new(ScrollState::default())- // .with_messages(vec![- // ChatMessage::new(- // "osiewicz".to_string(),- // "is this thing on?".to_string(),- // DateTime::parse_from_rfc3339(- // "2023-09-27T15:40:52.707Z",- // )- // .unwrap()- // .naive_local(),- // ),- // ChatMessage::new(- // "maxdeviant".to_string(),- // "Reading you loud and clear!".to_string(),- // DateTime::parse_from_rfc3339(- // "2023-09-28T15:40:52.707Z",- // )- // .unwrap()- // .naive_local(),- // ),- // ])- // .into_any()]- // },- // Box::new(()),- // )- // .side(PanelSide::Right),- // ),+ // Panel::new(+ // self.right_panel_scroll_state.clone(),+ // |_, payload| {+ // vec![ChatPanel::new(ScrollState::default())+ // .with_messages(vec![+ // ChatMessage::new(+ // "osiewicz".to_string(),+ // "is this thing on?".to_string(),+ // DateTime::parse_from_rfc3339(+ // "2023-09-27T15:40:52.707Z",+ // )+ // .unwrap()+ // .naive_local(),+ // ),+ // ChatMessage::new(+ // "maxdeviant".to_string(),+ // "Reading you loud and clear!".to_string(),+ // DateTime::parse_from_rfc3339(+ // "2023-09-28T15:40:52.707Z",+ // )+ // .unwrap()+ // .naive_local(),+ // ),+ // ])+ // .into_any()]+ // },+ // Box::new(()),+ // )+ // .side(PanelSide::Right),+ // ),).child(StatusBar::new())// An example of a toast is below