feat: add Mintty (Git Bash) image preview support (#103)

This commit is contained in:
三咲雅 · Misaki Masa 2023-09-02 12:55:24 +08:00 committed by GitHub
parent 66aecd5402
commit 25ba265407
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 12 deletions

View file

@ -147,17 +147,18 @@ If you want to use your own config, copy the [config folder](./config/preset) to
## Image Preview ## Image Preview
| Platform | Protocol | Support | | Platform | Protocol | Support |
| ------------- | -------------------------------------------------------------------------------- | --------------------- | | ----------------- | -------------------------------------------------------------------------------- | --------------------- |
| Kitty | [Terminal graphics protocol](https://sw.kovidgoyal.net/kitty/graphics-protocol/) | ✅ Built-in | | Kitty | [Terminal graphics protocol](https://sw.kovidgoyal.net/kitty/graphics-protocol/) | ✅ Built-in |
| WezTerm | [Terminal graphics protocol](https://sw.kovidgoyal.net/kitty/graphics-protocol/) | ✅ Built-in | | WezTerm | [Terminal graphics protocol](https://sw.kovidgoyal.net/kitty/graphics-protocol/) | ✅ Built-in |
| Konsole | [Terminal graphics protocol](https://sw.kovidgoyal.net/kitty/graphics-protocol/) | ✅ Built-in | | Konsole | [Terminal graphics protocol](https://sw.kovidgoyal.net/kitty/graphics-protocol/) | ✅ Built-in |
| iTerm2 | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in | | iTerm2 | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| Hyper | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in | | Mintty (Git Bash) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |
| foot | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in | | Hyper | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in |
| Black Box | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in | | foot | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in |
| X11 / Wayland | Window system protocol | ☑️ Überzug++ required | | Black Box | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in |
| Fallback | [Chafa](https://hpjansson.org/chafa/) | ☑️ Überzug++ required | | X11 / Wayland | Window system protocol | ☑️ Überzug++ required |
| Fallback | [Chafa](https://hpjansson.org/chafa/) | ☑️ Überzug++ required |
Yazi automatically selects the appropriate preview method for you, based on the priority from top to bottom. Yazi automatically selects the appropriate preview method for you, based on the priority from top to bottom.
That's relying on the `$TERM`, `$TERM_PROGRAM`, and `$XDG_SESSION_TYPE` variables, make sure you don't overwrite them by mistake! That's relying on the `$TERM`, `$TERM_PROGRAM`, and `$XDG_SESSION_TYPE` variables, make sure you don't overwrite them by mistake!

View file

@ -31,6 +31,7 @@ impl Default for PreviewAdaptor {
"BlackBox" => return Self::Sixel, "BlackBox" => return Self::Sixel,
"vscode" => return Self::Sixel, "vscode" => return Self::Sixel,
"Hyper" => return Self::Sixel, "Hyper" => return Self::Sixel,
"mintty" => return Self::Iterm2,
_ => {} _ => {}
} }
match env::var("XDG_SESSION_TYPE").unwrap_or_default().as_str() { match env::var("XDG_SESSION_TYPE").unwrap_or_default().as_str() {

View file

@ -1 +1 @@
{"language":"en","flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp"," Überzug"," Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord"],"version":"0.2"} {"language":"en","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp"," Überzug"," Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs"],"version":"0.2","flagWords":[]}

View file

@ -24,8 +24,16 @@ impl Term {
{ {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
use std::{thread, time::Duration};
use crossterm::cursor::{Hide, Show}; use crossterm::cursor::{Hide, Show};
queue!(&mut stdout, SavePosition, MoveTo(x, y), Show)?; queue!(&mut stdout, SavePosition, MoveTo(x, y), Show)?;
// I really don't want to add this,
// but on Windows the cursor position will not synchronize in time occasionally
stdout.flush()?;
thread::sleep(Duration::from_millis(1));
let result = cb(&mut stdout); let result = cb(&mut stdout);
queue!(&mut stdout, Hide, RestorePosition)?; queue!(&mut stdout, Hide, RestorePosition)?;
stdout.flush()?; stdout.flush()?;