From b6c5de4fb2b16147e285af54416f9494028b1274 Mon Sep 17 00:00:00 2001 From: Andy Kluger Date: Tue, 19 Nov 2024 18:40:40 -0500 Subject: [PATCH] Add gat highlighting backend (optional) --- NEWS.rst | 1 + doc/src/deps.md | 1 + zpy.plugin.zsh | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/NEWS.rst b/NEWS.rst index 10cb3cf..0ad119f 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -10,6 +10,7 @@ Changed - Use reverse-list layout for fzf/skim instead of reverse - pypc: don't add '.' to any dependency list +- Add optional syntax highlighter backend: gat 0.3.11 ====== diff --git a/doc/src/deps.md b/doc/src/deps.md index bcd11ed..99ee163 100644 --- a/doc/src/deps.md +++ b/doc/src/deps.md @@ -55,6 +55,7 @@ with optional additions for more colorful output, alternative json parsers, and - [uv](https://github.com/astral-sh/uv/) -- for faster performance, leaner venvs, and more operational feedback - [highlight](https://repology.org/project/highlight/versions) + *or* [gat](https://github.com/koki-develop/gat/) *or* [bat](https://repology.org/project/bat/versions) *or* [rich-cli](https://github.com/Textualize/rich-cli) -- for pretty syntax highlighting; rich-cli adds fancy tables diff --git a/zpy.plugin.zsh b/zpy.plugin.zsh index 3861567..8ef7a39 100644 --- a/zpy.plugin.zsh +++ b/zpy.plugin.zsh @@ -108,13 +108,16 @@ ZPY_PROCS=${${$(nproc 2>/dev/null):-$(sysctl -n hw.logicalcpu 2>/dev/null)}:-4} # the first of the next. This is true of at least highlight 3.58. # The method below bypasses both issues consistently - # across all known versions of highlight, and still outperforms bat: + # across all known versions of highlight, and still outperforms the rest: local content=$(<&0) if [[ $content ]] { local themes=(aiseered blacknblue bluegreen ekvoli navy) HIGHLIGHT_OPTIONS=${HIGHLIGHT_OPTIONS:-"-s $themes[RANDOM % $#themes + 1]"} \ highlight -O truecolor --stdout --force -S $1 <<<$content } + } elif (( $+commands[gat] )) { # recommended themes: base16-snazzy, doom-one, gruvbox, onedark, vulcan + GAT_THEME=${GAT_THEME:-doom-one} \ + gat --force-color -l $1 } elif (( $+commands[bat] )) { # recommended themes: ansi, zenburn BAT_THEME=${BAT_THEME:-ansi} \ bat --color always --paging never -p -l $1