From 1b8763d0cfeadb60791c2cfe7e5d84619f4c8d50 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Tue, 6 Dec 2022 11:28:56 -0800 Subject: [PATCH] WIP - move terminal to project as pre-prep for collaboration --- Cargo.lock | 28 +++++++++++- crates/project/Cargo.toml | 1 + crates/project/src/project.rs | 12 +++++ crates/terminal/Cargo.toml | 20 ++------- crates/terminal/src/persistence.rs | 14 +++--- crates/terminal/src/terminal.rs | 4 -- crates/terminal_view/Cargo.toml | 44 +++++++++++++++++++ crates/{terminal => terminal_view}/README.md | 0 .../scripts/print256color.sh | 0 .../scripts/truecolor.sh | 0 .../src/terminal_container_view.rs | 0 .../src/terminal_element.rs | 0 .../src/terminal_view.rs | 0 crates/zed/Cargo.toml | 2 +- 14 files changed, 95 insertions(+), 30 deletions(-) create mode 100644 crates/terminal_view/Cargo.toml rename crates/{terminal => terminal_view}/README.md (100%) rename crates/{terminal => terminal_view}/scripts/print256color.sh (100%) rename crates/{terminal => terminal_view}/scripts/truecolor.sh (100%) rename crates/{terminal => terminal_view}/src/terminal_container_view.rs (100%) rename crates/{terminal => terminal_view}/src/terminal_element.rs (100%) rename crates/{terminal => terminal_view}/src/terminal_view.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 7d7dc42bea..1868959a09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4463,6 +4463,7 @@ dependencies = [ "smol", "sum_tree", "tempdir", + "terminal", "text", "thiserror", "toml", @@ -6257,6 +6258,31 @@ dependencies = [ [[package]] name = "terminal" version = "0.1.0" +dependencies = [ + "alacritty_terminal", + "anyhow", + "db", + "dirs 4.0.0", + "futures 0.3.25", + "gpui", + "itertools", + "lazy_static", + "libc", + "mio-extras", + "ordered-float", + "procinfo", + "serde", + "settings", + "shellexpand", + "smallvec", + "smol", + "theme", + "thiserror", +] + +[[package]] +name = "terminal_view" +version = "0.1.0" dependencies = [ "alacritty_terminal", "anyhow", @@ -8166,7 +8192,7 @@ dependencies = [ "smol", "sum_tree", "tempdir", - "terminal", + "terminal_view", "text", "theme", "theme_selector", diff --git a/crates/project/Cargo.toml b/crates/project/Cargo.toml index 76c60f9556..dd4d2be5b6 100644 --- a/crates/project/Cargo.toml +++ b/crates/project/Cargo.toml @@ -32,6 +32,7 @@ lsp = { path = "../lsp" } rpc = { path = "../rpc" } settings = { path = "../settings" } sum_tree = { path = "../sum_tree" } +terminal = { path = "../terminal" } util = { path = "../util" } aho-corasick = "0.7" anyhow = "1.0.57" diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 512ac702d0..e61f0fe0b7 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -60,6 +60,7 @@ use std::{ atomic::{AtomicUsize, Ordering::SeqCst}, Arc, }, + thread::panicking, time::Instant, }; use thiserror::Error; @@ -1193,6 +1194,17 @@ impl Project { !self.is_local() } + pub fn create_terminal_connection( + &mut self, + cx: &mut ModelContext, + ) -> Result> { + if self.is_remote() { + return Err(anyhow!( + "creating terminals as a guest is not supported yet" + )); + } + } + pub fn create_buffer( &mut self, text: &str, diff --git a/crates/terminal/Cargo.toml b/crates/terminal/Cargo.toml index 5593ee92d4..2948eaec69 100644 --- a/crates/terminal/Cargo.toml +++ b/crates/terminal/Cargo.toml @@ -7,17 +7,12 @@ edition = "2021" path = "src/terminal.rs" doctest = false + [dependencies] -context_menu = { path = "../context_menu" } -editor = { path = "../editor" } -language = { path = "../language" } gpui = { path = "../gpui" } -project = { path = "../project" } settings = { path = "../settings" } -theme = { path = "../theme" } -util = { path = "../util" } -workspace = { path = "../workspace" } db = { path = "../db" } +theme = { path = "../theme" } alacritty_terminal = { git = "https://github.com/zed-industries/alacritty", rev = "a51dbe25d67e84d6ed4261e640d3954fbdd9be45" } procinfo = { git = "https://github.com/zed-industries/wezterm", rev = "5cd757e5f2eb039ed0c6bb6512223e69d5efc64d", default-features = false } smallvec = { version = "1.6", features = ["union"] } @@ -32,13 +27,4 @@ libc = "0.2" anyhow = "1" thiserror = "1.0" lazy_static = "1.4.0" -serde = { version = "1.0", features = ["derive"] } - - - -[dev-dependencies] -gpui = { path = "../gpui", features = ["test-support"] } -client = { path = "../client", features = ["test-support"]} -project = { path = "../project", features = ["test-support"]} -workspace = { path = "../workspace", features = ["test-support"] } -rand = "0.8.5" +serde = { version = "1.0", features = ["derive"] } \ No newline at end of file diff --git a/crates/terminal/src/persistence.rs b/crates/terminal/src/persistence.rs index 1669a3a546..333911ee6d 100644 --- a/crates/terminal/src/persistence.rs +++ b/crates/terminal/src/persistence.rs @@ -2,16 +2,16 @@ use std::path::PathBuf; use db::{define_connection, query, sqlez_macros::sql}; -use workspace::{ItemId, WorkspaceDb, WorkspaceId}; +type ModelId = usize; define_connection! { - pub static ref TERMINAL_CONNECTION: TerminalDb = + pub static ref TERMINAL_CONNECTION: TerminalDb<()> = &[sql!( CREATE TABLE terminals ( workspace_id INTEGER, - item_id INTEGER UNIQUE, + model_id INTEGER UNIQUE, working_directory BLOB, - PRIMARY KEY(workspace_id, item_id), + PRIMARY KEY(workspace_id, model_id), FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id) ON DELETE CASCADE ) STRICT; @@ -23,7 +23,7 @@ impl TerminalDb { pub async fn update_workspace_id( new_id: WorkspaceId, old_id: WorkspaceId, - item_id: ItemId + item_id: ModelId ) -> Result<()> { UPDATE terminals SET workspace_id = ? @@ -33,7 +33,7 @@ impl TerminalDb { query! { pub async fn save_working_directory( - item_id: ItemId, + item_id: ModelId, workspace_id: WorkspaceId, working_directory: PathBuf ) -> Result<()> { @@ -43,7 +43,7 @@ impl TerminalDb { } query! { - pub fn get_working_directory(item_id: ItemId, workspace_id: WorkspaceId) -> Result> { + pub fn get_working_directory(item_id: ModelId, workspace_id: WorkspaceId) -> Result> { SELECT working_directory FROM terminals WHERE item_id = ? AND workspace_id = ? diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 0cbb6d36b1..62df8aca82 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -1,8 +1,5 @@ pub mod mappings; mod persistence; -pub mod terminal_container_view; -pub mod terminal_element; -pub mod terminal_view; use alacritty_terminal::{ ansi::{ClearMode, Handler}, @@ -37,7 +34,6 @@ use persistence::TERMINAL_CONNECTION; use procinfo::LocalProcessInfo; use settings::{AlternateScroll, Settings, Shell, TerminalBlink}; use util::ResultExt; -use workspace::{ItemId, WorkspaceId}; use std::{ cmp::min, diff --git a/crates/terminal_view/Cargo.toml b/crates/terminal_view/Cargo.toml new file mode 100644 index 0000000000..181ed606e0 --- /dev/null +++ b/crates/terminal_view/Cargo.toml @@ -0,0 +1,44 @@ +[package] +name = "terminal_view" +version = "0.1.0" +edition = "2021" + +[lib] +path = "src/terminal_container_view.rs" +doctest = false + +[dependencies] +context_menu = { path = "../context_menu" } +editor = { path = "../editor" } +language = { path = "../language" } +gpui = { path = "../gpui" } +project = { path = "../project" } +settings = { path = "../settings" } +theme = { path = "../theme" } +util = { path = "../util" } +workspace = { path = "../workspace" } +db = { path = "../db" } +alacritty_terminal = { git = "https://github.com/zed-industries/alacritty", rev = "a51dbe25d67e84d6ed4261e640d3954fbdd9be45" } +procinfo = { git = "https://github.com/zed-industries/wezterm", rev = "5cd757e5f2eb039ed0c6bb6512223e69d5efc64d", default-features = false } +smallvec = { version = "1.6", features = ["union"] } +smol = "1.2.5" +mio-extras = "2.0.6" +futures = "0.3" +ordered-float = "2.1.1" +itertools = "0.10" +dirs = "4.0.0" +shellexpand = "2.1.0" +libc = "0.2" +anyhow = "1" +thiserror = "1.0" +lazy_static = "1.4.0" +serde = { version = "1.0", features = ["derive"] } + + + +[dev-dependencies] +gpui = { path = "../gpui", features = ["test-support"] } +client = { path = "../client", features = ["test-support"]} +project = { path = "../project", features = ["test-support"]} +workspace = { path = "../workspace", features = ["test-support"] } +rand = "0.8.5" diff --git a/crates/terminal/README.md b/crates/terminal_view/README.md similarity index 100% rename from crates/terminal/README.md rename to crates/terminal_view/README.md diff --git a/crates/terminal/scripts/print256color.sh b/crates/terminal_view/scripts/print256color.sh similarity index 100% rename from crates/terminal/scripts/print256color.sh rename to crates/terminal_view/scripts/print256color.sh diff --git a/crates/terminal/scripts/truecolor.sh b/crates/terminal_view/scripts/truecolor.sh similarity index 100% rename from crates/terminal/scripts/truecolor.sh rename to crates/terminal_view/scripts/truecolor.sh diff --git a/crates/terminal/src/terminal_container_view.rs b/crates/terminal_view/src/terminal_container_view.rs similarity index 100% rename from crates/terminal/src/terminal_container_view.rs rename to crates/terminal_view/src/terminal_container_view.rs diff --git a/crates/terminal/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rs similarity index 100% rename from crates/terminal/src/terminal_element.rs rename to crates/terminal_view/src/terminal_element.rs diff --git a/crates/terminal/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs similarity index 100% rename from crates/terminal/src/terminal_view.rs rename to crates/terminal_view/src/terminal_view.rs diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 6dfb739f3a..a07c0c899c 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -48,7 +48,7 @@ rpc = { path = "../rpc" } settings = { path = "../settings" } sum_tree = { path = "../sum_tree" } text = { path = "../text" } -terminal = { path = "../terminal" } +terminal_view = { path = "../terminal_view" } theme = { path = "../theme" } theme_selector = { path = "../theme_selector" } theme_testbench = { path = "../theme_testbench" }