web: the library checks for wasm32 (carried)
This commit is contained in:
1 parent
fe467d2bfe
commit
a03df0987c
44 files changed
+141
-104
No files matched your search
+15
-7
@@ -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<usize>, Pen)>) {
|
||||
(printed.text, printed.spans)
|
||||
}
|
||||
|
||||
/// Plain text sets no colors with OSC 4, 10 or 11.
|
||||
struct Unset;
|
||||
|
||||
impl Index<usize> for Unset {
|
||||
type Output = Option<Rgb>;
|
||||
|
||||
fn index(&self, _: usize) -> &Option<Rgb> {
|
||||
&None
|
||||
}
|
||||
}
|
||||
|
||||
impl Pen {
|
||||
fn style(&self, ink: &Ink, rule: gpui::Pixels) -> HighlightStyle {
|
||||
let set = Colors::default();
|
||||
let set = Unset;
|
||||
let paint =
|
||||
|color: Option<Color>, 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::*;
|
||||
|
||||
|
||||
+15
-9
@@ -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<usize, Output = Option<Rgb>> {}
|
||||
|
||||
impl<T: Index<usize, Output = Option<Rgb>>> 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::*;
|
||||
|
||||
@@ -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};
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user