1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-09 11:37:19 +03:00

add strip-ansi-escape utility to wezterm package

I've been meaning to do this for a while: the intended purpose
is to use this to filter ansi escape sequences out of the prompt
in the shell pre-command hook.
This commit is contained in:
Wez Furlong 2020-05-17 21:51:07 -07:00
parent 77fafd512b
commit 845d990304
4 changed files with 53 additions and 0 deletions

View File

@ -4,6 +4,7 @@ name = "wezterm"
version = "0.1.0"
edition = "2018"
build = "build.rs"
default-run = "wezterm"
[build-dependencies]
vergen = "3"
@ -11,6 +12,10 @@ vergen = "3"
[target.'cfg(windows)'.build-dependencies]
embed-resource = "1.3"
[[bin]]
name = "strip-ansi-escapes"
path = "src/bin/strip-ansi-escapes.rs"
[dependencies]
allsorts = "0.1"
async-task = "1.2"

View File

@ -4,6 +4,7 @@ rm -rf AppDir *.AppImage *.zsync
mkdir AppDir
install -Dsm755 -t AppDir/usr/bin target/release/wezterm
install -Dsm755 -t AppDir/usr/bin target/release/strip-ansi-escapes
install -Dm644 assets/icon/terminal.png AppDir/usr/share/icons/hicolor/128x128/apps/org.wezfurlong.wezterm.png
install -Dm644 -t AppDir/usr/share/wezterm/colors assets/colors/*
install -Dm644 assets/wezterm.desktop AppDir/usr/share/applications/org.wezfurlong.wezterm.desktop

View File

@ -27,6 +27,7 @@ case $OSTYPE in
mkdir $zipdir
cp -r assets/macos/WezTerm.app $zipdir/
cp $TARGET_DIR/release/wezterm $zipdir/WezTerm.app
cp $TARGET_DIR/release/strip-ansi-escapes $zipdir/WezTerm.app
cp -r assets/colors $zipdir/WezTerm.app/Contents/Resources/
zip -r $zipname $zipdir
;;
@ -40,6 +41,7 @@ case $OSTYPE in
rm -rf $zipdir $zipname
mkdir $zipdir
cp $TARGET_DIR/release/wezterm.exe \
$TARGET_DIR/release/strip-ansi-escapes.exe \
$TARGET_DIR/release/wezterm.pdb \
assets/windows/conhost/conpty.dll \
assets/windows/conhost/OpenConsole.exe \
@ -76,6 +78,7 @@ set -x
cd ${HERE}
mkdir -p %{buildroot}/usr/bin %{buildroot}/usr/share/wezterm/colors %{buildroot}/usr/share/applications
install -Dsm755 target/release/wezterm %{buildroot}/usr/bin
install -Dsm755 target/release/strip-ansi-escapes %{buildroot}/usr/bin
install -Dm644 assets/icon/terminal.png %{buildroot}/usr/share/icons/hicolor/128x128/apps/org.wezfurlong.wezterm.png
install -Dm644 -t %{buildroot}/usr/share/wezterm/colors assets/colors/*
install -Dm644 assets/wezterm.desktop %{buildroot}/usr/share/applications/org.wezfurlong.wezterm.desktop
@ -83,6 +86,7 @@ install -Dm644 assets/wezterm.appdata.xml %{buildroot}/usr/share/metainfo/org.we
%files
/usr/bin/wezterm
/usr/bin/strip-ansi-escapes
/usr/share/icons/hicolor/128x128/apps/org.wezfurlong.wezterm.png
/usr/share/wezterm/colors/*
/usr/share/applications/org.wezfurlong.wezterm.desktop
@ -110,6 +114,7 @@ Description: Wez's Terminal Emulator.
Depends: libc6, libegl-mesa0, libxcb-icccm4, libxcb-ewmh2, libxcb-keysyms1, libxcb-xkb1, libxkbcommon0, libxkbcommon-x11-0, libfontconfig1, xdg-utils, libxcb-render0, libxcb-shape0, libx11-6, libegl1
EOF
install -Dsm755 -t pkg/debian/usr/bin target/release/wezterm
install -Dsm755 -t pkg/debian/usr/bin target/release/strip-ansi-escapes
install -Dm644 assets/icon/terminal.png pkg/debian/usr/share/icons/hicolor/128x128/apps/org.wezfurlong.wezterm.png
install -Dm644 -t pkg/debian/usr/share/wezterm/colors assets/colors/*
install -Dm644 assets/wezterm.desktop pkg/debian/usr/share/applications/org.wezfurlong.wezterm.desktop

View File

@ -0,0 +1,42 @@
use std::io::{Read, Result};
use structopt::StructOpt;
use termwiz::escape::parser::Parser;
use termwiz::escape::{Action, ControlCode};
#[derive(Debug, StructOpt)]
#[structopt(
global_setting = structopt::clap::AppSettings::ColoredHelp,
)]
/// This is a little utility that strips escape sequences from
/// stdin and prints the result on stdout.
/// It preserves only printable characters and CL, LF and HT.
///
/// This utility is part of WezTerm.
///
/// https://github.com/wez/wezterm
struct Opt {}
fn main() -> Result<()> {
let _ = Opt::from_args();
let mut buf = [0u8; 4096];
let mut parser = Parser::new();
loop {
let len = std::io::stdin().read(&mut buf)?;
if len == 0 {
return Ok(());
}
parser.parse(&buf[0..len], |action| match action {
Action::Print(c) => print!("{}", c),
Action::Control(c) => match c {
ControlCode::HorizontalTab
| ControlCode::LineFeed
| ControlCode::CarriageReturn => print!("{}", c as u8 as char),
_ => {}
},
_ => {}
});
}
}