Skip to content

Commit

Permalink
Hacky terminal drawing with wrong colors
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Jan 20, 2024
1 parent 4f08ed1 commit 5bc4505
Show file tree
Hide file tree
Showing 8 changed files with 368 additions and 1,269 deletions.
751 changes: 89 additions & 662 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions crates/term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@ color-eyre.workspace = true
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
crossbeam-channel = "0.5"

wezterm-term = { version = "0.1.0", git = "https://github.com/wez/wezterm", rev = "3666303c7b26c6c966b3f136dbb954686d334cc3" }
portable-pty = { version = "0.8.1", git = "https://github.com/wez/wezterm", rev = "3666303c7b26c6c966b3f136dbb954686d334cc3" }
termwiz = { version = "0.22.0", git = "https://github.com/wez/wezterm", rev = "3666303c7b26c6c966b3f136dbb954686d334cc3" }
alacritty_terminal = "0.21.0"
132 changes: 39 additions & 93 deletions crates/term/src/_impl/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,99 +22,45 @@
// terms of the Steamworks API by Valve Corporation, the licensors of this
// Program grant you additional permission to convey the resulting work.

pub trait IntoEgui<T> {
fn into_egui(self) -> T;
}

impl IntoEgui<egui::Color32> for wezterm_term::color::SrgbaTuple {
fn into_egui(self) -> egui::Color32 {
let (r, g, b, a) = self.to_srgb_u8();
egui::Color32::from_rgba_unmultiplied(r, g, b, a)
}
}

pub trait IntoWez<T> {
fn into_wez(self) -> T;
}

pub trait TryIntoWez<T>
where
Self: Sized,
{
fn try_into_wez(self) -> Result<T, Self>;
}

impl TryIntoWez<wezterm_term::KeyCode> for egui::Key {
fn try_into_wez(self) -> Result<wezterm_term::KeyCode, egui::Key> {
Ok(match self {
egui::Key::ArrowDown => wezterm_term::KeyCode::DownArrow,
egui::Key::ArrowLeft => wezterm_term::KeyCode::LeftArrow,
egui::Key::ArrowRight => wezterm_term::KeyCode::RightArrow,
egui::Key::ArrowUp => wezterm_term::KeyCode::UpArrow,
egui::Key::Escape => wezterm_term::KeyCode::Escape,
egui::Key::Tab => wezterm_term::KeyCode::Tab,
egui::Key::Backspace => wezterm_term::KeyCode::Backspace,
egui::Key::Enter => wezterm_term::KeyCode::Enter,
egui::Key::Insert => wezterm_term::KeyCode::Insert,
egui::Key::Delete => wezterm_term::KeyCode::Delete,
egui::Key::Home => wezterm_term::KeyCode::Home,
egui::Key::End => wezterm_term::KeyCode::End,
egui::Key::PageUp => wezterm_term::KeyCode::PageUp,
egui::Key::PageDown => wezterm_term::KeyCode::PageDown,
egui::Key::Num0 => wezterm_term::KeyCode::Numpad0,
egui::Key::Num1 => wezterm_term::KeyCode::Numpad1,
egui::Key::Num2 => wezterm_term::KeyCode::Numpad2,
egui::Key::Num3 => wezterm_term::KeyCode::Numpad3,
egui::Key::Num4 => wezterm_term::KeyCode::Numpad4,
egui::Key::Num5 => wezterm_term::KeyCode::Numpad5,
egui::Key::Num6 => wezterm_term::KeyCode::Numpad6,
egui::Key::Num7 => wezterm_term::KeyCode::Numpad7,
egui::Key::Num8 => wezterm_term::KeyCode::Numpad8,
egui::Key::Num9 => wezterm_term::KeyCode::Numpad9,
egui::Key::F1 => wezterm_term::KeyCode::Function(1),
egui::Key::F2 => wezterm_term::KeyCode::Function(2),
egui::Key::F3 => wezterm_term::KeyCode::Function(3),
egui::Key::F4 => wezterm_term::KeyCode::Function(4),
egui::Key::F5 => wezterm_term::KeyCode::Function(5),
egui::Key::F6 => wezterm_term::KeyCode::Function(6),
egui::Key::F7 => wezterm_term::KeyCode::Function(7),
egui::Key::F8 => wezterm_term::KeyCode::Function(8),
egui::Key::F9 => wezterm_term::KeyCode::Function(9),
egui::Key::F10 => wezterm_term::KeyCode::Function(10),
egui::Key::F11 => wezterm_term::KeyCode::Function(11),
egui::Key::F12 => wezterm_term::KeyCode::Function(12),
egui::Key::F13 => wezterm_term::KeyCode::Function(13),
egui::Key::F14 => wezterm_term::KeyCode::Function(14),
egui::Key::F15 => wezterm_term::KeyCode::Function(15),
egui::Key::F16 => wezterm_term::KeyCode::Function(16),
egui::Key::F17 => wezterm_term::KeyCode::Function(17),
egui::Key::F18 => wezterm_term::KeyCode::Function(18),
egui::Key::F19 => wezterm_term::KeyCode::Function(19),
egui::Key::F20 => wezterm_term::KeyCode::Function(20),
_ => return Err(self),
})
}
}

impl IntoWez<wezterm_term::KeyModifiers> for egui::Modifiers {
fn into_wez(self) -> wezterm_term::KeyModifiers {
let mut keymod = wezterm_term::KeyModifiers::NONE;
keymod.set(wezterm_term::KeyModifiers::ALT, self.alt);
keymod.set(wezterm_term::KeyModifiers::CTRL, self.ctrl);
keymod.set(wezterm_term::KeyModifiers::SHIFT, self.shift);
// keymod.set(wezterm_term::KeyModifiers::SUPER, self.command);

keymod
}
}
use alacritty_terminal::{
term::color::Colors,
vte::ansi::{Color, NamedColor},
};

impl IntoWez<wezterm_term::MouseButton> for egui::PointerButton {
fn into_wez(self) -> wezterm_term::MouseButton {
match self {
egui::PointerButton::Primary => wezterm_term::MouseButton::Left,
egui::PointerButton::Secondary => wezterm_term::MouseButton::Right,
egui::PointerButton::Middle => wezterm_term::MouseButton::Middle,
_ => wezterm_term::MouseButton::None,
}
pub fn color_to_egui(color: Color) -> egui::Color32 {
match color {
Color::Named(named) => match named {
NamedColor::Black => egui::Color32::from_rgb(26, 26, 26),
NamedColor::Red => egui::Color32::from_rgb(128, 0, 0),
NamedColor::Green => egui::Color32::from_rgb(0, 128, 0),
NamedColor::Yellow => egui::Color32::from_rgb(128, 128, 0),
NamedColor::Blue => egui::Color32::from_rgb(0, 0, 128),
NamedColor::Magenta => egui::Color32::from_rgb(128, 0, 128),
NamedColor::Cyan => egui::Color32::from_rgb(0, 128, 128),
NamedColor::White => egui::Color32::from_rgb(128, 128, 128),
NamedColor::BrightBlack => egui::Color32::from_rgb(48, 48, 48),
NamedColor::BrightRed => egui::Color32::from_rgb(255, 0, 0),
NamedColor::BrightGreen => egui::Color32::from_rgb(0, 255, 0),
NamedColor::BrightYellow => egui::Color32::from_rgb(255, 255, 0),
NamedColor::BrightBlue => egui::Color32::from_rgb(0, 0, 255),
NamedColor::BrightMagenta => egui::Color32::from_rgb(255, 0, 255),
NamedColor::BrightCyan => egui::Color32::from_rgb(0, 255, 255),
NamedColor::BrightWhite => egui::Color32::from_rgb(255, 255, 255),
NamedColor::Foreground => egui::Color32::from_rgb(0, 0, 0),
NamedColor::Background => egui::Color32::from_rgb(0, 0, 0),
NamedColor::Cursor => egui::Color32::from_rgb(128, 128, 128),
NamedColor::DimBlack => egui::Color32::from_rgb(0, 0, 0),
NamedColor::DimRed => egui::Color32::from_rgb(96, 0, 0),
NamedColor::DimGreen => egui::Color32::from_rgb(0, 96, 0),
NamedColor::DimYellow => egui::Color32::from_rgb(96, 96, 0),
NamedColor::DimBlue => egui::Color32::from_rgb(0, 0, 96),
NamedColor::DimMagenta => egui::Color32::from_rgb(96, 0, 96),
NamedColor::DimCyan => egui::Color32::from_rgb(0, 96, 96),
NamedColor::DimWhite => egui::Color32::from_rgb(96, 96, 96),
NamedColor::BrightForeground => egui::Color32::from_rgb(0, 0, 0),
NamedColor::DimForeground => egui::Color32::from_rgb(0, 0, 0),
},
Color::Spec(rgb) => egui::Color32::from_rgb(rgb.r, rgb.g, rgb.b),
Color::Indexed(index) => egui::Color32::from_rgb(index, 0, 0),
}
}
Loading

0 comments on commit 5bc4505

Please sign in to comment.