From e710be9af6e9f16bf63921d204c1d38272d4bd3f Mon Sep 17 00:00:00 2001 From: Sebastian Wiesner Date: Mon, 16 Oct 2023 19:58:44 +0200 Subject: [PATCH] Add support for VSCode integrated terminal --- CHANGELOG.md | 181 +++++++++++++++++--- README.md | 2 + mdcat.1.adoc | 12 +- pulldown-cmark-mdcat/src/terminal/detect.rs | 26 +++ 4 files changed, 196 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50b2e80b..62edf464 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # Changelog + All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). @@ -8,18 +9,26 @@ Use `cargo release` to create a new release. ## [Unreleased] +### Added + +- Support images in VSCode integrated terminal, 1.80 or newer (see [GH-266]). + +[GH-266]: https://github.com/swsnr/mdcat/pull/266 + ## [2.0.4] – 2023-10-03 ### Changed + - Update all dependencies. - Bump MSRV to 1.72. ## [2.0.3] – 2023-04-24 ### Changed + - mdcat now uses the kitty protocol to render images on WezTerm (see [GH-258]). - mdcat now downscales images to the column limit if rendering with the kitty protocol (see [GH-258]). - Previously mdcat scaled down to the window size, which looked strange if a given `--columns` was much smaller than the window size. + Previously mdcat scaled down to the window size, which looked strange if a given `--columns` was much smaller than the window size. [GH-258]: https://github.com/swsnr/mdcat/pull/258 @@ -32,14 +41,15 @@ Use `cargo release` to create a new release. ### Fixed - Fix SVG rendering: - - Correctly enable SVG rendering and image processing features by default in `mdcat` (see [GH-256]). - - Ignore `charset` and other mime type parameters when checking for `image/svg+xml` (see [GH-256]). + - Correctly enable SVG rendering and image processing features by default in `mdcat` (see [GH-256]). + - Ignore `charset` and other mime type parameters when checking for `image/svg+xml` (see [GH-256]). [GH-256]: https://github.com/swsnr/mdcat/pull/256 ## [2.0.1] – 2023-04-16 ### Fixed + - Properly reset line wrapping state in list items (see [GH-254]). - Flush trailing spaces before starting a link to avoid link styling over an initial whitespace (see [GH-255]). @@ -49,23 +59,26 @@ Use `cargo release` to create a new release. ## [2.0.0] – 2023-04-15 ### Added + - mdcat now fills paragraph text to the column limit, i.e. fills up short lines and wraps long lines (see [GH-4]). - mdcat now allows to control color and style via a new `theme` field in `pulldown_cmark_mdcat::Settings` of type `pulldown_cmark_mdcat::Theme` (see [GH-48]). - `pulldown_cmark_mdcat::Theme::default()` provides the standard mdcat 1.x colors and style. + `pulldown_cmark_mdcat::Theme::default()` provides the standard mdcat 1.x colors and style. - mdcat now exposes resource handling via the new `pulldown_cmark_mdcat::resources::ResourceUrlHandler` trait (see [GH-247]). - `pulldown_cmark_mdcat` allows to disable SVG support and thus avoid the `resvg` dependency by disabling the `svg` feature (see [GH-249]). - `pulldown_cmark_mdcat` allows to disable image processing support and thus avoid the `image` dependency by disabling the `image-processing` feature (see [GH-250]). ### Changed + - Update all dependencies. - `mdcat::Settings` now holds a reference to a syntax set, so the syntax set can now be shared among multiple different settings. - Explicitly set minimum rust version in `Cargo.toml`, and document MSRV policy. - Move all core rendering functions into a new crate `pulldown-cmark-mdcat`; `mdcat` itself only contains the argument parsing and handling now (see [GH-248]). - If you were using `mdcat` as a library before, you likely want to use `pulldown-cmark-mdcat` now. + If you were using `mdcat` as a library before, you likely want to use `pulldown-cmark-mdcat` now. - Move HTTP resource handling into new crate `mdcat-http-reqwest`, in order to isolate the rather heavy `reqwest` dependency (see [GH-248]). - Increase timeouts for HTTP resources to avoid aborting too early. ### Removed + - `mdcat::Settings.resource_access` and the corresponding `ResourceAccess` enum (see [GH-247]). [GH-4]: https://github.com/swsnr/mdcat/issues/4 @@ -78,6 +91,7 @@ Use `cargo release` to create a new release. ## [1.1.1] – 2023-03-18 ### Fixed + - No longer elide tracing info below warn level in release builds (see [GH-242]). This allows downstream consumers to keep tracing info included in their release builds. @@ -86,6 +100,7 @@ Use `cargo release` to create a new release. ## [1.1.0] – 2023-02-27 ### Changed + - Update all dependencies. This removes a transitive dependency on a vulnerable version of `remove_dir_all`, see [GHSA-mc8h-8q98-g5hr]. - No longer sniff mime type from contents to identify SVG images. @@ -93,6 +108,7 @@ Use `cargo release` to create a new release. - Render SVG images using the pure Rust `resvg` crate instead of `rsvg-convert`; mdcat no longer requires the latter tool at runtime (see [GH-240]). ### Fixed + - Use `less -r` instead of `less -R` in `mdless` if both `$PAGER` and `$MDCAT_PAGER` are unset (see [GH-238]). - Time out external resources if no data was read for 100ms. Previously mdcat waited for 1s before timing out (see [GH-241]). @@ -101,20 +117,20 @@ Use `cargo release` to create a new release. [GH-239]: https://github.com/swsnr/mdcat/pull/239 [GH-240]: https://github.com/swsnr/mdcat/pull/240 [GH-241]: https://github.com/swsnr/mdcat/pull/241 - [GHSA-mc8h-8q98-g5hr]: https://github.com/advisories/GHSA-mc8h-8q98-g5hr ## [1.0.0] – 2023-01-07 ### Added + - Add `--detect-terminal` to print the name of the detected terminal program (see [GH-232]). - Add `--ansi` to skip terminal detection and use ANSI-formatting only (see [GH-232]). ### Changed - Replace `ureq` with `reqwest` (see [GH-229]). - This implies that the default build now creates a binary linked against the system standard SSL library, i.e. openssl under Linux. - A fully static build now requires `--no-default-features --features static` for `cargo build`. + This implies that the default build now creates a binary linked against the system standard SSL library, i.e. openssl under Linux. + A fully static build now requires `--no-default-features --features static` for `cargo build`. - Terminal detection always checks `$TERM` first and trusts its value if it denotes a specific terminal emulator (see [GH-232]). - Update all dependencies. @@ -129,6 +145,7 @@ Use `cargo release` to create a new release. ## [0.30.3] – 2022-12-01 ### Fixed + - Fix release workflow to restore release artifacts (see [GH-218]). [GH-218]: https://github.com/swsnr/mdcat/pull/218 @@ -136,20 +153,24 @@ Use `cargo release` to create a new release. ## [0.30.2] – 2022-12-01 ### Changed + - Update Github URL to . - Update dependencies. ## [0.30.1] – 2022-11-29 ### Fixed + - Fix workflow syntax error to restore release artifacts. ## [0.30.0] – 2022-11-29 ### Added + - Generate completions for `mdless` (see [GH-216]). ### Fixed + - Include generated shell completions in release artifacts. - Fix completions for mdcat (see [GH-214] and [GH-216]) @@ -159,11 +180,13 @@ Use `cargo release` to create a new release. ## [0.29.0] – 2022-10-21 ### Changed + - Move repository back to . - Restore release binaries. - Update dependencies, in particular clap to 4.0.15. ### Removed + - Support for `tree_magic_mini` for mime-type detection; mdcat now only uses the `file` tool (see [GH-204]). [GH-204]: https://github.com/swsnr/mdcat/pull/204 @@ -171,11 +194,13 @@ Use `cargo release` to create a new release. ## [0.28.0] – 2022-07-31 ### Changed + - Update all dependencies, in particular syntect to 5.0.0 and pulldown-cmark to 0.9.2. ## [0.27.1] – 2022-04-17 ### Fixed + - Build error on Windows (see [#201]). [#201]: https://codeberg.org/flausch/mdcat/pulls/201 @@ -183,13 +208,16 @@ Use `cargo release` to create a new release. ## [0.27.0] – 2022-04-10 ### Added + - Add extensive tracing output, to aid debugging (see [#147]). ### Changed + - mdcat no longer invokes `file` to detect SVG images, but now requires the presence of a system-wide magic database (see [#154]). Disable default features to restore the previous behaviour to invoke `file` to detect mimetypes. ### Fixed + - File completion with zsh (see [#198]). [#147]: https://codeberg.org/flausch/mdcat/issues/147 @@ -199,36 +227,43 @@ Use `cargo release` to create a new release. ## [0.26.1] – 2022-02-12 ### Changed + - Moved repository to . ## [0.26.0] – 2022-02-12 ### Changed + - Always output links as OSC-8 hyperlinks unless `--dump` is given. In particular, mdcat now prints hyperlinks if invoked as `mdless` or with `-p`, as recent `less` versions support OCS-8 hyperlinks (see [#191]). [#191]: https://github.com/swsnr/mdcat/issues/191 ### Removed + - mdcat no longer attempts to detect OSC8 link support of the underlying terminal. ## [0.25.1] – 2022-01-17 ### Changed + - Update pulldown-cmark to 0.9.1 which fixes a minor parsing issue. ## [0.25.0] – 2021-12-23 ### Changed + - Update pulldown-cmark to 0.9. - Buffer writes to terminal and pager, to reduce the amount of syscalls. ## [0.24.2] – 2021-11-19 ### Added + - Support for `$TERM=foot*` (see [#193]). ### Fixed + - Fix compiler error with newer `anyhow` versions (see [#192]). [#192]: https://github.com/swsnr/mdcat/pull/192 @@ -237,12 +272,14 @@ Use `cargo release` to create a new release. ## [0.24.1] – 2021-10-30 ### Fixed + - Fix semi-broken release. - Document support for foot in manpage. ## [0.24.0] – 2021-10-30 ### Added + - Support for [foot](https://codeberg.org/dnkl/foot/) (see [#190]). [#190]: https://github.com/swsnr/mdcat/pull/190 @@ -250,6 +287,7 @@ Use `cargo release` to create a new release. ## [0.23.2] – 2021-07-18 ### Changed + - WezTerm is now detected by `TERM` and `TERM_PROGRAM` environment variables (see [#186]). [#186]: https://github.com/swsnr/mdcat/pull/186 @@ -257,6 +295,7 @@ Use `cargo release` to create a new release. ## [0.23.1] – 2021-07-14 ### Changed + - Use `TERM_PROGRAM` for determining WezTerm terminal (see [#185]). [#185]: https://github.com/swsnr/mdcat/pull/185 @@ -264,6 +303,7 @@ Use `cargo release` to create a new release. ## [0.23.0] – 2021-07-04 ### Added + - Support for [WezTerm](https://wezfurlong.org/wezterm/) (see [#182]). - Add PowerShell completions (see [#183] and [#184]). @@ -274,13 +314,17 @@ Use `cargo release` to create a new release. ## [0.22.4] – 2021-04-15 ### Changed + - Update dependencies ## [0.22.3] – 2021-02-22 + ### Added + - Refuse to read more than 100MiB from external resources, e.g. images; mdcat cannot display images of that size reasonably anyway (see [#176]). ### Fixed + - Fix type error on FreeBSD (see [#177]). [#176]: https://github.com/swsnr/mdcat/pull/176 @@ -289,11 +333,13 @@ Use `cargo release` to create a new release. ## [0.22.2] – 2021-01-01 ### Changed + - Replace `reqwest` with `ureq` to fetch images via HTTP/HTTPS (see [#168] and [#169]); - the latter has considerably less dependencies and builds faster. - It also builds statically out of the box, hence the static musl builds no longer require `curl` to fetch images. + the latter has considerably less dependencies and builds faster. + It also builds statically out of the box, hence the static musl builds no longer require `curl` to fetch images. ### Removed + - The `reqwest` cargo feature (see [#168] and [#169]). [#168]: https://github.com/swsnr/mdcat/issues/168 @@ -304,22 +350,24 @@ Use `cargo release` to create a new release. ### Fixed - Include manpage source in Windows packages. - Currently the manpage doesn't build on Windows CI. + Currently the manpage doesn't build on Windows CI. ## [0.22.0] – 2020-10-17 ### Added + - Enable OSC8 hyperlinks in Kitty (see [#165]). - Kitty supports hyperlinks since [version 0.19][kitty-0.19], see [Kitty #68]. - Note that `mdcat` *unconditionally* prints hyperlinks if it detects a kitty terminal. - It makes no attempt to detect whether the Kitty version is compatible or the [`allow_hyperlinks`] setting is enabled. + Kitty supports hyperlinks since [version 0.19][kitty-0.19], see [Kitty #68]. + Note that `mdcat` _unconditionally_ prints hyperlinks if it detects a kitty terminal. + It makes no attempt to detect whether the Kitty version is compatible or the [`allow_hyperlinks`] setting is enabled. - `mdcat --version` (but not `mdcat -V`) now informs whether HTTP/HTTPS support is builtin or requires `curl`. - mdcat now includes a manpage (see [#167]). ### Changed + - `mdcat` now asks the controlling terminal for the terminal size and thus correctly detects the terminal size even if standard input, standard output and standard error are all redirected (see [#166]). - `mdcat` no longer requires `kitty icat` to detect the size of kitty windows (see [#166]). - Consequently mdcat can now show images on Kitty terminals even over SSH. + Consequently mdcat can now show images on Kitty terminals even over SSH. - `mdcat --help` no longer uses colours, and always wraps at 80 characters now. [kitty-0.19]: https://sw.kovidgoyal.net/kitty/changelog.html#id2 @@ -332,6 +380,7 @@ Use `cargo release` to create a new release. ## [0.21.1] – 2020-09-01 ### Fixed + - Update pulldown cmark to correctly ignore footnote refs (see [#155]). [#155]: https://github.com/swsnr/mdcat/issues/155 @@ -339,34 +388,40 @@ Use `cargo release` to create a new release. ## [0.21.0] – 2020-08-12 ### Added + - Add `--paginate` flag to paginate the output of mdcat (see [#152]); with this flag mdcat sends it output to `less -R` or any alternative pager set in `$MDCAT_PAGER` or `$PAGER`. This flag also disables all terminal-specific formatting as the pager likely won't support it. - Paginate output by default if invoked as `mdless`, that is, if `mdcat` is hard-linked to `mdless`. ### Fixed + - Render email autolinks (i.e. ``) as `mailto:` links. [#152]: https://github.com/swsnr/mdcat/issues/152 ## [0.20.0] – 2020-07-05 + ### Added + - `mdcat::TerminalCapabilities` now exposes constructors for specific terminal emulators. - Render reference link definitions as inline links if possible (see [#149]). - This mainly affects image links inside inline links which get rendered as reference links. + This mainly affects image links inside inline links which get rendered as reference links. - `mdcat::Environment` now contains all environment information required to render properly, namely the local hostname and the base URL. ### Changed + - `mdcat::push_tty` now takes an `mdcat::Environment` instead of `base_dir`. - `base_dir` is now part of `mdcat::Environment`. + `base_dir` is now part of `mdcat::Environment`. - Image links now use purple foreground text (see [#140] and [#149]). - Image links render as inline links if the terminal does not support inline images and the image is not inside another link (see [#141]). - `mdcat::TerminalCapabilities` now uses `Option` to denote missing capabilities. ### Fixed + - Always treat links targets as URLs, never as paths. - On ITerm2 only use the last segment of image URLs as filename for inline images (see [#149]). - Previously mdcat used the full URL based on a misunderstanding of the [Inline Images Protocol]. + Previously mdcat used the full URL based on a misunderstanding of the [Inline Images Protocol]. [#140]: https://github.com/swsnr/mdcat/issues/140 [#141]: https://github.com/swsnr/mdcat/issues/141 @@ -374,38 +429,52 @@ Use `cargo release` to create a new release. [Inline Images Protocol]: https://iterm2.com/documentation-images.html ## [0.19.0] – 2020-06-19 + ### Added + - Release packages now include generated shell completions for Bash, Zsh and Fish. ### Changed + - Blockquotes no longer have green foreground text (see [#144]). [#144]: https://github.com/swsnr/mdcat/issues/144 ## [0.18.4] – 2020-06-14 + ### Fixed + - Fix typo in release workflow. - Update all dependencies to no longer depend on yanked crate versions. ## [0.18.3] – 2020-06-14 + ### Fixed + - Properly ignore alt text of inline images (see [#148]). [#148]: https://github.com/swsnr/mdcat/issues/148 ## [0.18.2] – 2020-05-31 + ### Fixed + - Properly upload binaries for releases. ## [0.18.1] – 2020-05-31 + ### Fixed + - Fix typo in release workflow. ## [0.18.0] – 2020-05-31 + ### Added + - Add `mdcat::Error` as type alias to `std::io::Error`. ### Changed + - New simpler rendering algorithm (see #[142]) which solves numerous rendering issues (see below). - Handle internal errors with [anyhow] to add more context to errors (see @@ -414,6 +483,7 @@ Use `cargo release` to create a new release. fails unless it can’t write output. ### Fixed + - Respect `--local-only` and resource access policy; this got lost in some refactoring (see [#146]). - Consistent margins and newlines around paragraphs, HTML blocks and inside list @@ -429,7 +499,9 @@ Use `cargo release` to create a new release. [#146]: https://github.com/swsnr/mdcat/issues/146 ## [0.17.1] – 2020-05-24 + ### Fixed + - Correctly scale down large images on [kitty] (see [#124] and [#133] by [@fspillner]). @@ -437,11 +509,14 @@ Use `cargo release` to create a new release. [#133]: https://github.com/swsnr/mdcat/pull/133 ## [0.17.0] – 2020-05-20 + ### Changed + - `mdcat` is now distributed under the [MPL 2](http://mozilla.org/MPL/2.0/) license; some source files remain Apache 2.0 due to 3rd party rights (see [#138]). ### Fixed + - Do not fail with broken pipe error when rending large images (see [#134] by [@fspillner]). @@ -449,40 +524,50 @@ Use `cargo release` to create a new release. [#138]: https://github.com/swsnr/mdcat/issues/138 ## [0.16.1] – 2020-05-15 + ### Changed + - `mdcat::push_tty` now takes a `mdcat::Settings` struct which groups all external settings. ### Fixed + - Ignore broken pipes; `mdcat | head` no longer errors when `head` closes stdout of mdcat early (see [#136]). [#136]: https://github.com/swsnr/mdcat/issues/136 ## [0.16.0] – 2020-04-11 + ### Changed + - Upgrade to syntect 4.1 and enable its pure Rust regex backend to simplify - building (see [#131]). This crate now builds without Clang which fixes + building (see [#131]). This crate now builds without Clang which fixes Clang-related build issues (see [#90]) [#90]: https://github.com/swsnr/mdcat/issues/90 [#131]: https://github.com/swsnr/mdcat/pull/131 ## [0.15.1] – 2020-02-15 + ### Changed + - Update pulldown-cmark to 0.7. ## [0.15.0] – 2020-01-11 + ### Added + - Release builds now perform full link-time optimization to create a smaller - binary. We do recommend to also `strip` the `mdcat` binary. + binary. We do recommend to also `strip` the `mdcat` binary. - Render SVG images in [kitty] (see [#114]). - Update to reqwest 0.10. - Process file list as input (see [#54] and [#115], by [@norman-abramovitz]): - - Add `--fail` flag to exit on the first error when processing a file list; - the default behaviour is to continue with the next file in case of error. + - Add `--fail` flag to exit on the first error when processing a file list; + the default behaviour is to continue with the next file in case of error. ### Changed + - Replace `remote_resources` feature with `reqwest` feature to use reqwest for retrieving remote resources, and fall back to the `curl` command if `reqwest` is disabled. @@ -493,16 +578,20 @@ Use `cargo release` to create a new release. [@norman-abramovitz]: https://github.com/norman-abramovitz ## [0.14.0] – 2019-12-18 + ### Added + - Render images in [kitty] (see [#65] and [#104] by [@fspillner]). ### Changed + - Update pulldown-cmark to 0.6 which supports CommonMark 0.29 and improves parser speed and correctness. - Enable SIMD in pulldown-cmark to squeeze out the last bit of performance. - Remove all features except `remote_resources` to reduce build complexity. ### Removed + - No longer depend on `immeta`. [kitty]: https://sw.kovidgoyal.net/kitty/ @@ -512,9 +601,11 @@ Use `cargo release` to create a new release. [@fspillner]: https://github.com/fspillner ## [0.13.0] – 2019-03-30 + ### Added + - Render task lists nicely (see [#72]). -- Render strike-through text (see [#71]). Some terminals do not support this +- Render strike-through text (see [#71]). Some terminals do not support this feature, and mdcat does not have a fallback currently (see [#73]). [#73]: https://github.com/swsnr/mdcat/issues/73 @@ -522,13 +613,17 @@ Use `cargo release` to create a new release. [#71]: https://github.com/swsnr/mdcat/issues/71 ## [0.12.1] – 2018-12-24 + ### Fixed + - Do not add newline after inline text with styles disabled (see [#49]). [#49]: https://github.com/swsnr/mdcat/issues/49 ## [0.12.0] – 2018-12-20 + ### Added + - Add `TerminalCapability` struct as replacement for `mdcat::Terminal` trait to remove dynamic dispatch and allow for more accurate and less complicated conditional compilation of terminal support for different platforms (see @@ -537,14 +632,17 @@ Use `cargo release` to create a new release. [#46]). ### Changed + - Drop support for Rust 1.29 and older. - Do not test specific Rust on versions on Travis CI any longer; Rust stable becomes the lowest supported Rust version. ### Removed + - `mdcat::Terminal` trait and implementations (see [#45]). ### Fixed + - Set hostname to local hostname for inline links to `file://` URLs, which should properly resolve `file://` URLs over SSH (see [OSC 8 file URLs], [#42] and [#44]). @@ -556,7 +654,9 @@ Use `cargo release` to create a new release. [#46]: https://github.com/swsnr/mdcat/issues/46 ## [0.11.0] – 2018-10-25 + ### Changed + - Always print colours regardless of whether stdout if a tty or not. - Replace `--colour` option with a `--no-colour` flag to turn off styled output. - `mdcat::push_tty` no longer takes ownership of the `terminal` argument (see @@ -567,11 +667,15 @@ Use `cargo release` to create a new release. [#41]: https://github.com/swsnr/mdcat/issues/41 ## [0.10.1] – 2018-09-09 + ### Fixed + - Properly package musl binary on Travis CI; restores Linux binary in releases. ## [0.10.0] – 2018-09-09 + ### Added + - Support colours on Windows 10 console (see [#36]). - Support musl target on Linux (see [#37] and [#38]). - Published Linux binary statically links musl now, and has no runtime @@ -583,23 +687,31 @@ Use `cargo release` to create a new release. [#38]: https://github.com/swsnr/mdcat/pull/38 ## [0.9.2] – 2018-08-26 + ### Fixed + - Do not falsely ignore deployments from Travis CI for Linux and macOS. ## [0.9.1] – 2018-08-26 + ### Added + - Publish binaries for Linux, macOS and Windows (see [#28]). ### Fixed + - Correctly build macOS and Linux binaries on Travis CI. [#28]: https://github.com/swsnr/mdcat/issues/28 ## [0.9.0] – 2018-08-26 + ### Added + - `mdcat` builds on Windows now (see [#33] and [#34]). ### Changed + - Refactor internal terminal representation, replacing the terminal enum with a new `Terminal` trait and dynamic dispatch (see [#35]). - Allow to disable specific terminal backends (see [#35]). @@ -610,7 +722,9 @@ Use `cargo release` to create a new release. [#35]: https://github.com/swsnr/mdcat/pull/35 ## [0.8.0] – 2018-02-15 + ### Added + - Render SVG images in iTerm2 with `rsvg-convert` (requires `librsvg`). - Expose `TerminalWrite` in `mdcat` crate (see [#20] by [@Byron]). @@ -618,7 +732,9 @@ Use `cargo release` to create a new release. [@Byron]: https://github.com/Byron ## [0.7.0] – 2018-02-08 + ### Added + - Show images from HTTP and HTTPS URLs inline in iTerm2. - Add `--local` flag to render only local images inline; for remote images, eg, HTTP URLs, show only the image title and the URL. @@ -627,12 +743,15 @@ Use `cargo release` to create a new release. - Show `--help` with colours. ### Changed + - Adhere to Semantic Versioning, but stay pre-1.0 so anything still goes. [#18]: https://github.com/swsnr/mdcat/issues/18 ## [0.6.0] – 2018-02-02 + ### Added + - Show inline images in [Terminology] (see [#16] by [@vinipsmaker]). [Terminology]: http://terminolo.gy @@ -640,12 +759,15 @@ Use `cargo release` to create a new release. [@vinipsmaker]: https://github.com/vinipsmaker ### Changed + - Improve `--help` output: Hide some redundant options, add a bug reporting URL and explain the purpose of `mdcat`. - Reduce dependencies and thus build time ## [0.5.0] – 2018-01-27 + ### Added + - Show links inline in iTerm2 and terminals based on VTE 0.50 or newer (see [#8], [#14] and [#15]). @@ -654,9 +776,11 @@ Use `cargo release` to create a new release. [#15]: https://github.com/swsnr/mdcat/issues/15 ### Changed + - Improve `--help` output. ### Fixed + - Remove redundant default value from `--colour` help text (see [#10], by [@wezm]). - Replace light black with green; the former doesn't work with Solarized Dark. @@ -664,27 +788,36 @@ Use `cargo release` to create a new release. [@wezm]: https://github.com/wezm ## [0.4.0] – 2018-01-21 + ### Changed + - Use 8-bit ANSI colours for syntax highlighting to fit all kinds of terminal colour themes. ### Fixed + - Remove excess space at the end of code blocks ### Removed + - Remove `--light` switch which became redundant due to better syntax highlighting. ## [0.3.0] – 2018-01-19 + ### Added + - Print image links - Show images inline on iTerm. ### Changed + - Rename to `mdcat`; I have no plans to add paging to this tool. ## [0.2.0] – 2018-01-16 + ### Added + - Highlight code blocks with Solarized color theme (light or dark). - Naively show inline and block HTML. - Set iTerm marks for headings. @@ -692,12 +825,14 @@ Use `cargo release` to create a new release. - Add `--colour` flag to enable or disable coloured output. ## [0.1.1] – 2018-01-14 + ### Fixed - Fix Travis CI badge on crates.io. - Fix license layout in README. ## [0.1.0] – 2018-01-14 + ### Added - Support inline formatting. diff --git a/README.md b/README.md index fbafffc5..5d3a70cf 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ Then it | [iTerm2] | ✓ | ✓ | ✓³ | ✓ | | [kitty] | ✓ | ✓ | ✓³ | | | [WezTerm] | ✓ | ✓ | ✓³ | | +| [VSCode] | ✓ | ✓ | ✓³ | | 1) mdcat requires that the terminal supports strikethrough formatting and [inline links][osc8]. It will not render strikethrough text and links correctly on terminals that don't support these (e.g. the Linux text console) @@ -54,6 +55,7 @@ Not supported: [kitty]: https://sw.kovidgoyal.net/kitty/ [resvg]: https://github.com/RazrFalcon/resvg [SVG support]: https://github.com/RazrFalcon/resvg#svg-support +[VSCode]: https://code.visualstudio.com/ ## Usage diff --git a/mdcat.1.adoc b/mdcat.1.adoc index eeb22b9d..e43f05bd 100644 --- a/mdcat.1.adoc +++ b/mdcat.1.adoc @@ -38,6 +38,8 @@ To enable formatting extensions such as inline images, `mdcat` needs to detect t 2. `$TERM_PROGRAM` 3. `$TERMINOLOGY` +For some terminals `mdcat` also checks `$TERM_PROGRAM_VERSION` to determine whether the terminal supports the expected feature set. + See section <> below for a detailed description of each environment variable. === Pagination @@ -50,7 +52,7 @@ In particular this disables all image support which relies on proprietary escape === Image support -In iTerm2, kitty, Terminology and WezTerm mdcat prints inline images. +In iTerm2, kitty, Terminology, WezTerm, and VSCode (1.80 or newer) mdcat prints inline images. mdcat supports most standard pixel formats by default. mdcat silently ignores images larger than 100 MiB, under the assumption that images of that size cannot reasonably be rendered in a terminal. @@ -59,7 +61,7 @@ mdcat silently ignores images larger than 100 MiB, under the assumption that ima In Terminology mdcat also renders SVG images, using the built-in support of Terminology. -In iTerm2, kitty and WezTerm mdcat renders SVG images into pixel graphics using the https://github.com/RazrFalcon/resvg[resvg] library. +In iTerm2, kitty, VSCode, and WezTerm mdcat renders SVG images into pixel graphics using the https://github.com/RazrFalcon/resvg[resvg] library. Currently this library only supports SVG 1, and only the static subset thereof; see https://github.com/RazrFalcon/resvg#svg-support[SVG support] for details. While this is sufficient for most simple SVG images, complex SVG images may fail to render or render incompletely. @@ -147,9 +149,14 @@ TERM_PROGRAM:: + * `iTerm.app`: iTerm2 * `WezTerm`: WezTerm + * `vscode`: VSCode integrated terminal, but only if `$TERM_PROGRAM_VERSION` indicates a sufficient version to support all required features.. + For all other values `mdcat` proceeds to check `$TERMINOLOGY`. +TERM_PROGRAM_VERSION:: + + If `$TERM_PROGRAM` is `vscode`, `mdcat` checks this variable to determine whether VSCode has a sufficient version to support all required features. + TERMINOLOGY:: If this variable is `1`, mdcat assumes that the terminal is Terminology. @@ -227,6 +234,7 @@ https://iterm2.com/documentation-escape-codes.html[Marks]. * https://github.com/kovidgoyal/kitty[kitty]: Inline images (https://sw.kovidgoyal.net/kitty/graphics-protocol.html[kitty Graphics protocol]). * http://terminolo.gy[Terminology]: Inline images (terminology protocol). * https://wezfurlong.org/wezterm/[WezTerm]: Inline images (kitty graphics protocol, see above). +* https://code.visualstudio.com/[VSCode] 1.80 or newer, integrated terminal: Inline images (iTerm2 protocol, see above) == Bugs diff --git a/pulldown-cmark-mdcat/src/terminal/detect.rs b/pulldown-cmark-mdcat/src/terminal/detect.rs index 23961576..c4249420 100644 --- a/pulldown-cmark-mdcat/src/terminal/detect.rs +++ b/pulldown-cmark-mdcat/src/terminal/detect.rs @@ -42,6 +42,10 @@ pub enum TerminalProgram { /// /// See for more information. WezTerm, + /// The built-in terminal in VSCode. + /// + /// Since version 1.80 it supports images with the iTerm2 protocol. + VSCode, } impl Display for TerminalProgram { @@ -53,11 +57,24 @@ impl Display for TerminalProgram { TerminalProgram::Terminology => "Terminology", TerminalProgram::Kitty => "kitty", TerminalProgram::WezTerm => "WezTerm", + TerminalProgram::VSCode => "vscode", }; write!(f, "{name}") } } +/// Extract major and minor version from `$TERM_PROGRAM_VERSION`. +/// +/// Return `None` if the variable doesn't exist, or has invalid contents, such as +/// non-numeric parts, insufficient parts for a major.minor version, etc. +fn get_term_program_major_minor_version() -> Option<(u16, u16)> { + let value = std::env::var("TERM_PROGRAM_VERSION").ok()?; + let mut parts = value.split('.').take(2); + let major = parts.next()?.parse().ok()?; + let minor = parts.next()?.parse().ok()?; + Some((major, minor)) +} + impl TerminalProgram { fn detect_term() -> Option { match std::env::var("TERM").ok().as_deref() { @@ -71,6 +88,12 @@ impl TerminalProgram { match std::env::var("TERM_PROGRAM").ok().as_deref() { Some("WezTerm") => Some(Self::WezTerm), Some("iTerm.app") => Some(Self::ITerm2), + Some("vscode") + if get_term_program_major_minor_version() + .map_or(false, |version| (1, 80) <= version) => + { + Some(Self::VSCode) + } _ => None, } } @@ -130,6 +153,9 @@ impl TerminalProgram { .with_image_capability(ImageCapability::Kitty(self::kitty::KittyGraphicsProtocol)), TerminalProgram::WezTerm => ansi .with_image_capability(ImageCapability::Kitty(self::kitty::KittyGraphicsProtocol)), + TerminalProgram::VSCode => { + ansi.with_image_capability(ImageCapability::ITerm2(ITerm2Protocol)) + } } } }