diff --git a/crates/storybook2/src/stories/components.rs b/crates/storybook2/src/stories/components.rs index 51dea1b675a67de56daa8dc6ee60a4ef013ec5eb..4a78644b713d371d1b6bdb2a2874409e9d960b60 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.rs new file mode 100644 index 0000000000000000000000000000000000000000..6a63306ed914de1b5ab525755776c1edfbae0875 --- /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 { + state_type: PhantomData, +} + +impl TerminalStory { + pub fn new() -> Self { + Self { + state_type: PhantomData, + } + } + + fn render(&mut self, cx: &mut ViewContext) -> impl Element { + Story::container(cx) + .child(Story::title_for::<_, Terminal>(cx)) + .child(Story::label(cx, "Default")) + .child(Terminal::new()) + } +} diff --git a/crates/storybook2/src/story_selector.rs b/crates/storybook2/src/story_selector.rs index e3e04b56090344628d4e7c279cda4086ea5e28bb..c66cdc20794dcc8956aa7deb31e216923cb630e3 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.rs index 31073b74bd1a07f77b32bf7f567f5df40df21320..468d4dca99c5f89b4c8c269b24c14b116c6bf143 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.rs new file mode 100644 index 0000000000000000000000000000000000000000..96be31a895dd28312357862c901bdd0adf0d040f --- /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 { + state_type: PhantomData, +} + +impl Terminal { + pub fn new() -> Self { + Self { + state_type: PhantomData, + } + } + + fn render(&mut self, cx: &mut ViewContext) -> impl Element { + 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::>().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.rs index ba390074315e5ee1258cd830a8c85da1d26b8a00..758d6002c1566b1b75542c8a6a573eb17fbf19a0 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 { @@ -46,13 +49,10 @@ impl WorkspaceElement { let theme = payload.downcast_ref::>().unwrap(); vec![ - div() - .w_full() - .fill(gpui3::rgb::(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 WorkspaceElement { width: relative(1.).into(), height: temp_size, }, - |_, _| { - vec![ - div() - .w_full() - .fill(gpui3::rgb::(0x00ff00)) - .into_any(), - // Terminal::new().into_any() - ] - }, + |_, _| vec![Terminal::new().into_any()], Box::new(()), ), ], @@ -88,10 +80,7 @@ impl WorkspaceElement { let theme = payload.downcast_ref::>().unwrap(); vec![ - div() - .w_full() - .fill(gpui3::rgb::(0x0000ff)) - .into_any(), + Terminal::new().into_any(), // EditorPane::new(hello_world_rust_editor_with_status_example( // &theme, // )) @@ -175,36 +164,36 @@ impl WorkspaceElement { .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