From a03df0987cd3575344bb2b0bd223b6eba8a76af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Tue, 29 Sep 2026 19:16:41 -0400 Subject: [PATCH] web: the library checks for wasm32 (carried) --- AGENTS.md | 6 +++++- Cargo.lock | 5 +++++ Cargo.toml | 11 ++++++++++- scripts/check.sh | 2 ++ src/charts/glide.rs | 4 +++- src/charts/pie.rs | 3 ++- src/charts/realtime.rs | 3 +-- src/chat/status.rs | 6 ++---- src/chat/stream.rs | 3 ++- src/chat/voice.rs | 3 ++- src/data_display/carousel.rs | 6 ++---- src/feedback/clock.rs | 6 ++---- src/feedback/tests/states.rs | 3 ++- src/feedback/toast.rs | 6 ++---- src/forms/text/edit.rs | 6 ++---- src/layout/collapse.rs | 3 +-- src/layout/scroll.rs | 7 ++----- src/layout/scroll_aids.rs | 6 ++---- src/layout/sidebar.rs | 3 +-- src/lib.rs | 1 + src/lists/select.rs | 6 ++---- src/lists/swipe.rs | 3 ++- src/media/player.rs | 2 +- src/media/record.rs | 3 ++- src/media/tests/devices.rs | 3 ++- src/messaging/call.rs | 3 ++- src/messaging/tests/calls.rs | 3 +-- src/misc/stopwatch.rs | 7 +++++-- src/motion/effects.rs | 3 ++- src/motion/list.rs | 3 ++- src/motion/overlay.rs | 3 ++- src/motion/particles.rs | 6 ++---- src/motion/transition.rs | 3 ++- src/project/pomodoro.rs | 10 +++++----- src/project/tests/mod.rs | 2 +- src/project/tracker.rs | 6 ++---- src/shell/status.rs | 3 ++- src/terminal/ansi.rs | 22 +++++++++++++++------- src/terminal/colors.rs | 24 +++++++++++++++--------- src/terminal/mod.rs | 10 ++++++++++ src/terminal/view.rs | 3 ++- src/theme/mod.rs | 3 ++- src/tooling/events.rs | 11 ++++------- src/tooling/perf.rs | 10 +++++----- 44 files changed, 141 insertions(+), 104 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index f8bd819..443422f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -11,11 +11,12 @@ Ely GPUI Component. A component library for GPUI, in light and dark. - Codes: `qrcode` (QR) and `barcoders` (Code 128, EAN-13), both MIT OR Apache-2.0, default features off. `rqrr` 0.11 ((MIT OR Apache-2.0) AND ISC, default features off) reads QR codes from the host's frames. - macOS extras (tray icon, Dock badge) call AppKit through `cocoa` 0.26 and `objc` 0.2, the crates gpui already links. - Web views: `wry` 0.57 (Apache-2.0 OR MIT, default features off, macOS only) lays a child WKWebView over the window. -- Terminal: `alacritty_terminal` 0.26 (Apache-2.0, default features off) for the grid, its parser and the pseudo-terminal; `futures` carries its events. +- Terminal: `alacritty_terminal` 0.26 (Apache-2.0, default features off, native only) for the grid, its parser and the pseudo-terminal; `futures` carries its events. `vte` 0.15 (Apache-2.0 OR MIT), the parser it re-exports, reads `AnsiText`'s codes alone, so colored output builds for wasm32. - Diffs: `similar` 3.2 (Apache-2.0) for line and word diffs and three-way merges; its `unicode` feature splits words at punctuation. - Markdown: `pulldown-cmark` 0.13 (MIT, default features off) for CommonMark with tables, tasks, strikethrough, footnotes and math. - Pictures: `image` 0.25 (MIT OR Apache-2.0), the crate gpui decodes with, default features off; it turns decoded frames and rims map tiles. - Maps: Natural Earth's 110m countries (public domain). `assets/maps/countries.geojson`, trimmed by `scripts/countries.py` to an ISO code, a name and positions to 0.01°, backs `maps::WorldMap`; the gallery's tiles are cut from the same file, z0 to z3, by `scripts/tiles.py` with Pillow. +- Web: on wasm32, `web-time` 1.1 (MIT OR Apache-2.0) gives the `Instant` gpui's executor returns, std's own natively; jiff takes `js`, rust-embed `debug-embed`, similar `wasm32_web_time`. - Gallery: `examples/gallery`. Website: `frontend/` (Vite 8, pnpm), built after the components: a home page in motion with three.js and smooth scroll, and a components page with categories on the left and the chosen component on the right, after astryx.atmeta.com and gpui-kit.com. Each component runs live from the gallery built for wasm32 through gpui_web, in an iframe, never as a screenshot. It deploys to Cloudflare through `npx wrangler`. ## Commands @@ -23,6 +24,7 @@ Ely GPUI Component. A component library for GPUI, in light and dark. - `cargo run --example gallery` opens the gallery. `-- --page ` starts on a page. - `cargo run --example gallery -- --capture ` writes PNGs of every page, light and dark, top to bottom, then each page's scripted states, including windows the demos open. macOS only. - `cargo run --example gallery -- --narrow 280 --capture ` lays each page, header and body, at that width in a padded card and shoots it without its script, whose aims are measured at full width. Demos that set their own width run past the card. +- `RUSTC_BOOTSTRAP=1 cargo check --lib --target wasm32-unknown-unknown` checks the web build; gpui_web's `wasm_thread` needs the bootstrap, as Zed's web examples do. - `cargo test --lib --features test-support`, `cargo clippy --all-targets --features test-support -- -D warnings`, `cargo fmt --check`. `scripts/check.sh` runs them with the house rules. - `rm -rf target/debug/incremental` and `cargo clean -p ely-gpui-component` after each task item keep the disk lean. Cargo keeps every old build of the crate and its tests under a new hash; by T25 they had filled the disk. - `scripts/icons.sh ...` adds icons. Then add a line to `IconName` in `src/primitives/icon.rs`. @@ -173,6 +175,8 @@ Ely GPUI Component. A component library for GPUI, in light and dark. - A component built on `lists::Tree` fills its box; the host gives it a height. A fixed-width column beside a `flex_1` one takes `flex_none`, or it shrinks. - Editor rows read their text through `CodeEditor::row_text`: a multi-line ghost cuts its line, and the rest follows the ghost's last line. - gpui clears `debug_bounds` each frame: a test sees an element leave as well as appear. +- Time reads `web_time::Instant`: std's compiles for wasm32 and panics in the browser. `scripts/check.sh` refuses std's in `src`. +- What cannot build for wasm32 is absent there through `cfg(not(target_family = "wasm"))`, never faked: the live terminal, `Terminal` and `Launch` with their grid, keys and search. - The system time zone comes from `typography::format::system_zone`, which fails loud; jiff's `TimeZone::system()` falls back to UTC in silence. - A Select with nothing to pick stays shut: disabled, it shows its placeholder; open, it fails (`media::DeviceSelector` says no device was found). - A list opens with its cursor on the current choice: Select on the chosen row, Combobox on its value, MultiSelect on the first one ticked, SelectableList on its first selected row. A selection the owner makes, not the echo of the list's own pick, moves SelectableList's cursor there. diff --git a/Cargo.lock b/Cargo.lock index 5626b31..a1494f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1678,6 +1678,8 @@ dependencies = [ "similar", "smallvec", "unicode-segmentation", + "vte", + "web-time", "wry", ] @@ -3119,10 +3121,12 @@ dependencies = [ "jiff-core", "jiff-static", "jiff-tzdb-platform", + "js-sys", "log", "portable-atomic", "portable-atomic-util", "serde_core", + "wasm-bindgen", "windows-link 0.2.1", ] @@ -5649,6 +5653,7 @@ checksum = "4f66ca1f7aca2474dc10c942eb22feffc897735f54cd1db90138c2fddb490987" dependencies = [ "bstr", "unicode-segmentation", + "web-time", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a370d69..01c9cfe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,6 @@ runtime_shaders = ["gpui_platform/runtime_shaders"] test-support = ["gpui/test-support"] [dependencies] -alacritty_terminal = { version = "0.26", default-features = false } anyhow = "1" barcoders = { version = "2", default-features = false, features = ["std"] } emojis = "0.9" @@ -37,6 +36,16 @@ serde_json = { version = "1", features = ["preserve_order"] } similar = { version = "3.2", default-features = false, features = ["std", "text", "inline", "unicode"] } smallvec = "1" unicode-segmentation = "1" +vte = { version = "0.15", default-features = false, features = ["std", "ansi"] } +web-time = "1.1" + +[target.'cfg(not(target_family = "wasm"))'.dependencies] +alacritty_terminal = { version = "0.26", default-features = false } + +[target.'cfg(target_family = "wasm")'.dependencies] +jiff = { version = "0.2", features = ["js"] } +rust-embed = { version = "8.12", features = ["debug-embed"] } +similar = { version = "3.2", default-features = false, features = ["wasm32_web_time"] } [target.'cfg(target_os = "macos")'.dependencies] block = "0.1" diff --git a/scripts/check.sh b/scripts/check.sh index c394688..86cc867 100755 --- a/scripts/check.sh +++ b/scripts/check.sh @@ -17,4 +17,6 @@ raw=$(awk '/#\[cfg\(test\)\]/{nextfile} /(^|[^.[:alnum:]_])px\(/{print FILENAME" [ -z "$raw" ] || { echo "raw px in components:"; echo "$raw"; fail=1; } deferred=$(grep -rn 'deferred(' src --include='*.rs' | grep -v '^src/primitives/layer.rs' || true) [ -z "$deferred" ] || { echo "gpui deferred outside primitives::raise:"; echo "$deferred"; fail=1; } +instant=$(grep -rnE '(^|[^_[:alnum:]])time::(Instant|\{[^}]*Instant)' src || true) +[ -z "$instant" ] || { echo "std Instant panics in the browser, use web_time::Instant:"; echo "$instant"; fail=1; } exit $fail diff --git a/src/charts/glide.rs b/src/charts/glide.rs index c445f2a..bc65626 100644 --- a/src/charts/glide.rs +++ b/src/charts/glide.rs @@ -1,4 +1,6 @@ -use std::time::{Duration, Instant}; +use std::time::Duration; + +use web_time::Instant; use crate::motion; diff --git a/src/charts/pie.rs b/src/charts/pie.rs index 84748a4..c5fb330 100644 --- a/src/charts/pie.rs +++ b/src/charts/pie.rs @@ -1,6 +1,6 @@ use std::{ f32::consts::{FRAC_PI_2, PI, TAU}, - time::{Duration, Instant}, + time::Duration, }; use gpui::{ @@ -8,6 +8,7 @@ use gpui::{ MouseMoveEvent, ParentElement, PathBuilder, Pixels, Point, Refineable, RenderOnce, SharedString, StatefulInteractiveElement, StyleRefinement, Styled, Window, canvas, div, point, }; +use web_time::Instant; use super::{ axes::anchored, diff --git a/src/charts/realtime.rs b/src/charts/realtime.rs index c1211fa..83dc6e5 100644 --- a/src/charts/realtime.rs +++ b/src/charts/realtime.rs @@ -1,10 +1,9 @@ -use std::time::Instant; - use gpui::{ App, Bounds, ContentMask, Div, ElementId, Entity, InteractiveElement, IntoElement, ParentElement, PathBuilder, Pixels, Refineable, RenderOnce, StyleRefinement, Styled, Window, canvas, div, fill, size, }; +use web_time::Instant; use super::{ axes::beside, diff --git a/src/chat/status.rs b/src/chat/status.rs index 5dc4258..26f22e6 100644 --- a/src/chat/status.rs +++ b/src/chat/status.rs @@ -1,13 +1,11 @@ -use std::{ - rc::Rc, - time::{Duration, Instant}, -}; +use std::{rc::Rc, time::Duration}; use gpui::{ App, ElementId, Entity, FontWeight, InteractiveElement, IntoElement, MouseButton, ParentElement, RenderOnce, SharedString, StatefulInteractiveElement, Styled, Window, div, prelude::*, relative, transparent_black, }; +use web_time::Instant; use super::stream::StreamingText; use crate::{ diff --git a/src/chat/stream.rs b/src/chat/stream.rs index 0df6684..15c0c5e 100644 --- a/src/chat/stream.rs +++ b/src/chat/stream.rs @@ -1,10 +1,11 @@ -use std::time::{Duration, Instant}; +use std::time::Duration; use gpui::{ App, ElementId, HighlightStyle, IntoElement, ParentElement, RenderOnce, SharedString, Styled, StyledText, Window, div, }; use unicode_segmentation::UnicodeSegmentation; +use web_time::Instant; use super::code::CodeBlock; use crate::{ diff --git a/src/chat/voice.rs b/src/chat/voice.rs index 3f0b75c..efea413 100644 --- a/src/chat/voice.rs +++ b/src/chat/voice.rs @@ -1,6 +1,7 @@ -use std::{rc::Rc, time::Instant}; +use std::rc::Rc; use gpui::{App, ElementId, IntoElement, ParentElement, RenderOnce, Styled, Window, div}; +use web_time::Instant; use crate::{ buttons::{ButtonVariant, IconButton}, diff --git a/src/data_display/carousel.rs b/src/data_display/carousel.rs index 57cbec2..91b2af4 100644 --- a/src/data_display/carousel.rs +++ b/src/data_display/carousel.rs @@ -1,13 +1,11 @@ -use std::{ - rc::Rc, - time::{Duration, Instant}, -}; +use std::{rc::Rc, time::Duration}; use gpui::{ AnyElement, App, Div, ElementId, HoverListenerMode, InteractiveElement, IntoElement, MouseButton, ParentElement, RenderOnce, StatefulInteractiveElement, StyleRefinement, Styled, Task, Window, div, prelude::*, relative, }; +use web_time::Instant; use crate::{ motion, diff --git a/src/feedback/clock.rs b/src/feedback/clock.rs index 0f6e4cc..40b00ce 100644 --- a/src/feedback/clock.rs +++ b/src/feedback/clock.rs @@ -1,11 +1,9 @@ -use std::{ - rc::Rc, - time::{Duration, Instant}, -}; +use std::{rc::Rc, time::Duration}; use gpui::{ App, ElementId, IntoElement, ParentElement, RenderOnce, Styled, Task, Window, div, prelude::*, }; +use web_time::Instant; use crate::{ forms::Run, diff --git a/src/feedback/tests/states.rs b/src/feedback/tests/states.rs index 10c214f..557ee9a 100644 --- a/src/feedback/tests/states.rs +++ b/src/feedback/tests/states.rs @@ -1,10 +1,11 @@ -use std::time::{Duration, Instant}; +use std::time::Duration; use anyhow::anyhow; use gpui::{ Context, Entity, FocusHandle, IntoElement, ParentElement, Pixels, Render, Styled, TestAppContext, VisualTestContext, Window, div, px, }; +use web_time::Instant; use super::{press, settle, setup, wait}; use crate::{ diff --git a/src/feedback/toast.rs b/src/feedback/toast.rs index 3f92f42..71d2835 100644 --- a/src/feedback/toast.rs +++ b/src/feedback/toast.rs @@ -1,7 +1,4 @@ -use std::{ - rc::Rc, - time::{Duration, Instant}, -}; +use std::{rc::Rc, time::Duration}; use gpui::{ Anchor, Animation, AnimationExt, AnyElement, App, ClickEvent, Context, ElementId, Entity, @@ -9,6 +6,7 @@ use gpui::{ RenderOnce, SharedString, StatefulInteractiveElement, Styled, Task, Window, anchored, canvas, div, point, prelude::*, relative, }; +use web_time::Instant; use crate::{ buttons::{Button, ButtonVariant, IconButton}, diff --git a/src/forms/text/edit.rs b/src/forms/text/edit.rs index 1de4efc..7cc1181 100644 --- a/src/forms/text/edit.rs +++ b/src/forms/text/edit.rs @@ -1,9 +1,7 @@ -use std::{ - ops::Range, - time::{Duration, Instant}, -}; +use std::{ops::Range, time::Duration}; use unicode_segmentation::UnicodeSegmentation; +use web_time::Instant; pub(crate) fn prev_grapheme(text: &str, offset: usize) -> usize { text.grapheme_indices(true) diff --git a/src/layout/collapse.rs b/src/layout/collapse.rs index bab3a3d..326fa45 100644 --- a/src/layout/collapse.rs +++ b/src/layout/collapse.rs @@ -1,11 +1,10 @@ -use std::time::Instant; - use gpui::{ Animation, AnimationExt, AnyElement, App, ElementId, Entity, FontWeight, InteractiveElement, IntoElement, ParentElement, Pixels, RenderOnce, SharedString, StatefulInteractiveElement, Styled, Window, canvas, div, }; use smallvec::SmallVec; +use web_time::Instant; use crate::{ motion, diff --git a/src/layout/scroll.rs b/src/layout/scroll.rs index 66f830c..4fc6526 100644 --- a/src/layout/scroll.rs +++ b/src/layout/scroll.rs @@ -1,8 +1,4 @@ -use std::{ - cell::Cell, - rc::Rc, - time::{Duration, Instant}, -}; +use std::{cell::Cell, rc::Rc, time::Duration}; use gpui::{ AnyElement, App, Axis, Bounds, Canvas, Div, ElementId, EmptyView, Entity, EntityId, @@ -11,6 +7,7 @@ use gpui::{ div, point, prelude::*, }; use smallvec::SmallVec; +use web_time::Instant; use super::ScrollShadow; use crate::{motion, theme::ActiveTheme}; diff --git a/src/layout/scroll_aids.rs b/src/layout/scroll_aids.rs index be65f0a..e2b1183 100644 --- a/src/layout/scroll_aids.rs +++ b/src/layout/scroll_aids.rs @@ -1,12 +1,10 @@ -use std::{ - rc::Rc, - time::{Duration, Instant}, -}; +use std::{rc::Rc, time::Duration}; use gpui::{ AnyElement, App, ElementId, IntoElement, ParentElement, Pixels, RenderOnce, ScrollHandle, Styled, Window, canvas, div, point, prelude::*, }; +use web_time::Instant; use crate::{ buttons::{ButtonVariant, IconButton}, diff --git a/src/layout/sidebar.rs b/src/layout/sidebar.rs index b841cf1..7f0e5b6 100644 --- a/src/layout/sidebar.rs +++ b/src/layout/sidebar.rs @@ -1,10 +1,9 @@ -use std::time::Instant; - use gpui::{ Animation, AnimationExt, AnyElement, App, ElementId, InteractiveElement, IntoElement, ParentElement, RenderOnce, Styled, Window, div, }; use smallvec::SmallVec; +use web_time::Instant; use crate::{motion, theme::ActiveTheme}; diff --git a/src/lib.rs b/src/lib.rs index e3340a4..0732d4d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,6 +65,7 @@ pub fn init(cx: &mut App) { ]); forms::bind_keys(cx); editor::bind_keys(cx); + #[cfg(not(target_family = "wasm"))] terminal::bind_keys(cx); documents::bind_keys(cx); } diff --git a/src/lists/select.rs b/src/lists/select.rs index 3257d05..8ff4ecd 100644 --- a/src/lists/select.rs +++ b/src/lists/select.rs @@ -1,12 +1,10 @@ -use std::{ - rc::Rc, - time::{Duration, Instant}, -}; +use std::{rc::Rc, time::Duration}; use gpui::{ App, Div, ElementId, InteractiveElement, IntoElement, MouseButton, ParentElement, RenderOnce, ScrollHandle, SharedString, StatefulInteractiveElement, StyleRefinement, Styled, Window, div, }; +use web_time::Instant; use super::ListItem; use crate::primitives::tab_stop; diff --git a/src/lists/swipe.rs b/src/lists/swipe.rs index fb0b3e6..987fd2e 100644 --- a/src/lists/swipe.rs +++ b/src/lists/swipe.rs @@ -1,10 +1,11 @@ -use std::{rc::Rc, time::Instant}; +use std::rc::Rc; use gpui::{ AnyElement, App, ElementId, InteractiveElement, IntoElement, MouseButton, ParentElement, Pixels, RenderOnce, ScrollDelta, SharedString, StatefulInteractiveElement, Styled, TouchPhase, Window, div, prelude::*, }; +use web_time::Instant; use crate::{ data_display::Tone, diff --git a/src/media/player.rs b/src/media/player.rs index 6b7cf71..74b89b7 100644 --- a/src/media/player.rs +++ b/src/media/player.rs @@ -26,7 +26,7 @@ const JUMP: f64 = 10.0; /// When the pointer last moved over the player, and whether a wake is set to hide the controls. struct Watch { - moved: std::time::Instant, + moved: web_time::Instant, waking: bool, } diff --git a/src/media/record.rs b/src/media/record.rs index 23775a0..96af1cc 100644 --- a/src/media/record.rs +++ b/src/media/record.rs @@ -1,9 +1,10 @@ -use std::{rc::Rc, time::Instant}; +use std::rc::Rc; use gpui::{ AnyElement, App, ElementId, IntoElement, ParentElement, RenderOnce, Styled, Window, div, prelude::*, }; +use web_time::Instant; use crate::{ buttons::{Button, ButtonVariant, IconButton, ToggleButton, ToggleItem}, diff --git a/src/media/tests/devices.rs b/src/media/tests/devices.rs index f587cb7..773adf2 100644 --- a/src/media/tests/devices.rs +++ b/src/media/tests/devices.rs @@ -1,10 +1,11 @@ -use std::time::{Duration, Instant}; +use std::time::Duration; use gpui::{ Context, Entity, IntoElement, Modifiers, MouseButton, ParentElement, Render, ScrollDelta, ScrollWheelEvent, SharedString, Styled, TestAppContext, TouchPhase, VisualTestContext, Window, div, point, px, }; +use web_time::Instant; use super::{picture, press, settle, setup, tab_to}; use crate::media::{ diff --git a/src/messaging/call.rs b/src/messaging/call.rs index 4e9081a..9cfcfc2 100644 --- a/src/messaging/call.rs +++ b/src/messaging/call.rs @@ -1,9 +1,10 @@ -use std::{rc::Rc, time::Instant}; +use std::rc::Rc; use gpui::{ App, ElementId, IntoElement, MouseButton, ParentElement, RenderOnce, SharedString, Styled, Window, div, prelude::*, }; +use web_time::Instant; use crate::{ buttons::{Button, ButtonVariant}, diff --git a/src/messaging/tests/calls.rs b/src/messaging/tests/calls.rs index c16a17a..62255bd 100644 --- a/src/messaging/tests/calls.rs +++ b/src/messaging/tests/calls.rs @@ -1,9 +1,8 @@ -use std::time::Instant; - use gpui::{ App, Context, Entity, InteractiveElement, IntoElement, Modifiers, ParentElement, Render, Styled, TestAppContext, Window, div, px, }; +use web_time::Instant; use super::{press, settle, setup, tab_to}; use crate::{ diff --git a/src/misc/stopwatch.rs b/src/misc/stopwatch.rs index 0e943e6..04df170 100644 --- a/src/misc/stopwatch.rs +++ b/src/misc/stopwatch.rs @@ -1,9 +1,10 @@ -use std::time::{Duration, Instant}; +use std::time::Duration; use gpui::{ App, ElementId, FocusHandle, InteractiveElement, IntoElement, ParentElement, RenderOnce, Styled, Task, Window, div, }; +use web_time::Instant; use crate::{ buttons::{Button, ButtonVariant}, @@ -202,7 +203,9 @@ impl RenderOnce for Stopwatch { #[cfg(test)] mod tests { - use std::time::{Duration, Instant}; + use std::time::Duration; + + use web_time::Instant; use super::{Run, tenths}; diff --git a/src/motion/effects.rs b/src/motion/effects.rs index 0937e02..45a6ea6 100644 --- a/src/motion/effects.rs +++ b/src/motion/effects.rs @@ -1,6 +1,6 @@ use std::{ f32::consts::{PI, TAU}, - time::{Duration, Instant}, + time::Duration, }; use gpui::{ @@ -9,6 +9,7 @@ use gpui::{ prelude::*, }; use smallvec::SmallVec; +use web_time::Instant; use super::{NUDGE, SLOW, duration, ease_out_cubic}; use crate::theme::ActiveTheme; diff --git a/src/motion/list.rs b/src/motion/list.rs index 17fe762..8f6b90d 100644 --- a/src/motion/list.rs +++ b/src/motion/list.rs @@ -1,9 +1,10 @@ -use std::{collections::HashMap, rc::Rc, time::Instant}; +use std::{collections::HashMap, rc::Rc}; use gpui::{ AnyElement, App, ElementId, Entity, IntoElement, ParentElement, Pixels, RenderOnce, SharedString, Styled, Window, canvas, div, }; +use web_time::Instant; use super::{BASE, duration, ease_in_out_cubic, ease_out_cubic}; use crate::theme::{ActiveTheme, Elevation}; diff --git a/src/motion/overlay.rs b/src/motion/overlay.rs index abad707..fef0f53 100644 --- a/src/motion/overlay.rs +++ b/src/motion/overlay.rs @@ -1,4 +1,4 @@ -use std::{f32::consts::PI, time::Instant}; +use std::f32::consts::PI; use gpui::{ Animation, AnimationExt, AnyElement, App, Div, ElementId, InteractiveElement, IntoElement, @@ -6,6 +6,7 @@ use gpui::{ prelude::*, radians, }; use smallvec::SmallVec; +use web_time::Instant; use super::{BASE, FAST, NUDGE, Skeleton, Spinner, changes, duration, ease_out_cubic}; use crate::{ diff --git a/src/motion/particles.rs b/src/motion/particles.rs index 6d9fe74..d14fedf 100644 --- a/src/motion/particles.rs +++ b/src/motion/particles.rs @@ -1,7 +1,4 @@ -use std::{ - f32::consts::TAU, - time::{Duration, Instant}, -}; +use std::{f32::consts::TAU, time::Duration}; use gpui::{ Animation, AnimationExt, AnyElement, App, Bounds, Div, ElementId, Hsla, InteractiveElement, @@ -10,6 +7,7 @@ use gpui::{ px, size, }; use smallvec::SmallVec; +use web_time::Instant; use super::{ duration, diff --git a/src/motion/transition.rs b/src/motion/transition.rs index 3fef196..9bb3241 100644 --- a/src/motion/transition.rs +++ b/src/motion/transition.rs @@ -1,10 +1,11 @@ -use std::time::{Duration, Instant}; +use std::time::Duration; use gpui::{ Animation, AnimationExt, AnyElement, App, ElementId, IntoElement, ParentElement, RenderOnce, Styled, Window, div, }; use smallvec::SmallVec; +use web_time::Instant; use super::{BASE, NUDGE, duration, ease_out_cubic}; use crate::theme::ActiveTheme; diff --git a/src/project/pomodoro.rs b/src/project/pomodoro.rs index 7c906a1..5287f49 100644 --- a/src/project/pomodoro.rs +++ b/src/project/pomodoro.rs @@ -1,11 +1,9 @@ -use std::{ - rc::Rc, - time::{Duration, Instant}, -}; +use std::{rc::Rc, time::Duration}; use gpui::{ App, ElementId, Entity, IntoElement, ParentElement, RenderOnce, Styled, Task, Window, div, }; +use web_time::Instant; use crate::{ buttons::{Button, ButtonVariant, IconButton}, @@ -298,7 +296,9 @@ impl RenderOnce for PomodoroTimer { #[cfg(test)] mod tests { - use std::time::{Duration, Instant}; + use std::time::Duration; + + use web_time::Instant; use super::{Cycle, Lengths, Phase}; diff --git a/src/project/tests/mod.rs b/src/project/tests/mod.rs index dffcdce..32db497 100644 --- a/src/project/tests/mod.rs +++ b/src/project/tests/mod.rs @@ -2,10 +2,10 @@ use gpui::{ AnyElement, Context, Entity, IntoElement, KeyBinding, KeyUpEvent, Keystroke, Modifiers, ParentElement, Render, Styled, TestAppContext, VisualTestContext, Window, div, px, }; -use std::time::Instant; use gpui::SharedString; use jiff::civil::date; +use web_time::Instant; use super::{AssigneePicker, IssueId, Person, Priority, Status, StatusSelect, Task, TaskList}; use crate::{documents::Checklist, forms::bind_keys, primitives::FocusNext, theme::Theme}; diff --git a/src/project/tracker.rs b/src/project/tracker.rs index b5c1d12..3434792 100644 --- a/src/project/tracker.rs +++ b/src/project/tracker.rs @@ -1,12 +1,10 @@ -use std::{ - rc::Rc, - time::{Duration, Instant}, -}; +use std::{rc::Rc, time::Duration}; use gpui::{ App, ElementId, InteractiveElement, IntoElement, ParentElement, RenderOnce, SharedString, Styled, Task, Window, div, }; +use web_time::Instant; use crate::{ buttons::{Button, ButtonVariant}, diff --git a/src/shell/status.rs b/src/shell/status.rs index abf25bd..00783a0 100644 --- a/src/shell/status.rs +++ b/src/shell/status.rs @@ -1,9 +1,10 @@ -use std::time::{Duration, Instant}; +use std::time::Duration; use gpui::{ Animation, AnimationExt, AnyElement, App, ElementId, IntoElement, ParentElement, RenderOnce, Styled, Task, Window, div, prelude::*, }; +use web_time::Instant; use crate::{ buttons::{ButtonVariant, IconButton}, diff --git a/src/terminal/ansi.rs b/src/terminal/ansi.rs index 2039e7c..86bffb5 100644 --- a/src/terminal/ansi.rs +++ b/src/terminal/ansi.rs @@ -1,13 +1,10 @@ -use std::ops::Range; +use std::ops::{Index, Range}; -use alacritty_terminal::{ - term::color::Colors, - vte::ansi::{Attr, Color, Handler, Processor}, -}; use gpui::{ App, FontStyle, FontWeight, HighlightStyle, IntoElement, ParentElement, RenderOnce, SharedString, StrikethroughStyle, Styled, StyledText, UnderlineStyle, Window, div, }; +use vte::ansi::{Attr, Color, Handler, Processor, Rgb}; use super::colors::Ink; use crate::theme::{ActiveTheme, TextSize}; @@ -93,9 +90,20 @@ pub(crate) fn printed(source: &str) -> (String, Vec<(Range, Pen)>) { (printed.text, printed.spans) } +/// Plain text sets no colors with OSC 4, 10 or 11. +struct Unset; + +impl Index for Unset { + type Output = Option; + + fn index(&self, _: usize) -> &Option { + &None + } +} + impl Pen { fn style(&self, ink: &Ink, rule: gpui::Pixels) -> HighlightStyle { - let set = Colors::default(); + let set = Unset; let paint = |color: Option, plain| color.map_or(plain, |color| ink.resolve(color, &set)); let (mut fg, mut bg) = (paint(self.fg, ink.fg), paint(self.bg, ink.bg)); @@ -158,7 +166,7 @@ impl RenderOnce for AnsiText { #[cfg(test)] mod tests { - use alacritty_terminal::vte::ansi::NamedColor; + use vte::ansi::NamedColor; use super::*; diff --git a/src/terminal/colors.rs b/src/terminal/colors.rs index 01174b1..d7a0b67 100644 --- a/src/terminal/colors.rs +++ b/src/terminal/colors.rs @@ -1,8 +1,7 @@ -use alacritty_terminal::{ - term::color::Colors, - vte::ansi::{Color, NamedColor, Rgb}, -}; +use std::ops::Index; + use gpui::{Hsla, Rgba}; +use vte::ansi::{Color, NamedColor, Rgb}; use crate::theme::Palette; @@ -24,7 +23,7 @@ impl Ink { } /// A color as painted, after any the program set with OSC 4, 10 or 11. - pub(crate) fn resolve(&self, color: Color, set: &Colors) -> Hsla { + pub(crate) fn resolve(&self, color: Color, set: &impl Set) -> Hsla { match color { Color::Spec(spec) => hsla(spec), Color::Indexed(index) => self.indexed(index as usize, set), @@ -32,8 +31,8 @@ impl Ink { } } - fn named(&self, name: NamedColor, set: &Colors) -> Hsla { - if let Some(spec) = set[name] { + fn named(&self, name: NamedColor, set: &impl Set) -> Hsla { + if let Some(spec) = set[name as usize] { return hsla(spec); } match name { @@ -49,7 +48,7 @@ impl Ink { } } - fn indexed(&self, index: usize, set: &Colors) -> Hsla { + fn indexed(&self, index: usize, set: &impl Set) -> Hsla { if let Some(spec) = set[index] { return hsla(spec); } @@ -76,7 +75,8 @@ impl Ink { } /// Color `index` as an answer to a program's query. - pub(crate) fn query(&self, index: usize, set: &Colors) -> Rgb { + #[cfg(not(target_family = "wasm"))] + pub(crate) fn query(&self, index: usize, set: &impl Set) -> Rgb { let color = match index { 256 => self.named(NamedColor::Foreground, set), 257 => self.named(NamedColor::Background, set), @@ -93,6 +93,11 @@ impl Ink { } } +/// Colors a program set with OSC 4, 10 or 11, by index. +pub(crate) trait Set: Index> {} + +impl>> Set for T {} + fn hsla(spec: Rgb) -> Hsla { let channel = |value: u8| f32::from(value) / 255.0; Rgba { @@ -106,6 +111,7 @@ fn hsla(spec: Rgb) -> Hsla { #[cfg(test)] mod tests { + use alacritty_terminal::term::color::Colors; use gpui::{black, white}; use super::*; diff --git a/src/terminal/mod.rs b/src/terminal/mod.rs index f14735e..4e4a15b 100644 --- a/src/terminal/mod.rs +++ b/src/terminal/mod.rs @@ -1,28 +1,38 @@ mod ansi; mod block; mod colors; +#[cfg(not(target_family = "wasm"))] mod frame; mod history; +#[cfg(not(target_family = "wasm"))] mod input; +#[cfg(not(target_family = "wasm"))] mod keys; mod links; mod logs; +#[cfg(not(target_family = "wasm"))] mod paint; mod processes; +#[cfg(not(target_family = "wasm"))] mod pty; +#[cfg(not(target_family = "wasm"))] mod search; mod shells; #[cfg(all(test, feature = "test-support"))] mod tests; +#[cfg(not(target_family = "wasm"))] mod view; pub use ansi::AnsiText; pub use block::{CommandBlock, CommandState}; pub use history::{CommandHistory, PastCommand}; +#[cfg(not(target_family = "wasm"))] pub(crate) use input::bind_keys; pub use links::{Target, links}; pub use logs::{LogLevel, LogLine, LogViewer}; pub use processes::{Process, ProcessList}; +#[cfg(not(target_family = "wasm"))] pub use pty::Launch; pub use shells::{ShellChoice, ShellSelector, TerminalToolbar}; +#[cfg(not(target_family = "wasm"))] pub use view::{Terminal, TerminalEvent}; diff --git a/src/terminal/view.rs b/src/terminal/view.rs index 086ee06..4f77482 100644 --- a/src/terminal/view.rs +++ b/src/terminal/view.rs @@ -1,4 +1,4 @@ -use std::{borrow::Cow, process::ExitStatus, rc::Rc, sync::Arc, time::Instant}; +use std::{borrow::Cow, process::ExitStatus, rc::Rc, sync::Arc}; use alacritty_terminal::{ event::{Event, Notify, OnResize}, @@ -13,6 +13,7 @@ use gpui::{ App, ClipboardItem, Context, EventEmitter, FocusHandle, Focusable, IntoElement, ParentElement, Pixels, Point, Render, SharedString, Size, Styled, Task, Window, div, font, prelude::*, size, }; +use web_time::Instant; use super::{ colors::Ink, diff --git a/src/theme/mod.rs b/src/theme/mod.rs index cd05b26..f3237b1 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -20,9 +20,10 @@ mod tooling; #[cfg(all(test, feature = "test-support"))] mod tests; -use std::time::{Duration, Instant}; +use std::time::Duration; use gpui::{App, Global, SharedString, WindowAppearance}; +use web_time::Instant; use crate::motion; pub use calendar::CalendarSizes; diff --git a/src/tooling/events.rs b/src/tooling/events.rs index 2121bef..1a3b473 100644 --- a/src/tooling/events.rs +++ b/src/tooling/events.rs @@ -1,9 +1,4 @@ -use std::{ - collections::VecDeque, - fmt, - rc::Rc, - time::{Duration, Instant}, -}; +use std::{collections::VecDeque, fmt, rc::Rc, time::Duration}; use gpui::{ AnyElement, App, DispatchPhase, ElementId, InteractiveElement, IntoElement, KeyContext, @@ -12,6 +7,7 @@ use gpui::{ Window, canvas, div, prelude::FluentBuilder, }; use smallvec::SmallVec; +use web_time::Instant; use crate::{ layout::on_axis, @@ -264,9 +260,10 @@ impl RenderOnce for EventLogger { #[cfg(test)] mod tests { - use std::time::{Duration, Instant}; + use std::time::Duration; use gpui::{Modifiers, MouseButton, point, px}; + use web_time::Instant; use super::{KEPT, Log, Seen}; diff --git a/src/tooling/perf.rs b/src/tooling/perf.rs index ff87871..ed7b7e3 100644 --- a/src/tooling/perf.rs +++ b/src/tooling/perf.rs @@ -1,12 +1,10 @@ -use std::{ - collections::VecDeque, - time::{Duration, Instant}, -}; +use std::{collections::VecDeque, time::Duration}; use gpui::{ App, Bounds, ElementId, FontWeight, InteractiveElement, IntoElement, ParentElement, RenderOnce, Styled, Window, canvas, div, fill, point, size, }; +use web_time::Instant; use crate::{ theme::{ActiveTheme, Radius, TextSize}, @@ -183,7 +181,9 @@ impl RenderOnce for FpsMeter { #[cfg(test)] mod tests { - use std::time::{Duration, Instant}; + use std::time::Duration; + + use web_time::Instant; use super::{Frames, missed};