Skip to content

Commit 197ebfa

Browse files
authored
Merge pull request #7 from ArkieCoder/kittysupport
more kitty support
2 parents 40a1e5e + a559ece commit 197ebfa

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

install.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Detects dependencies and installs the Ruby Primer app.
55

66
REQUIRED_RUBY_VERSION="3.2"
7-
REQUIRED_UTILITIES=("pandoc" "xelatex" "convert")
7+
REQUIRED_UTILITIES=("pandoc" "xelatex" "convert" "viu")
88
FONT_NAME="IBM Plex Serif Light"
99

1010
# Colors for output
@@ -112,19 +112,19 @@ if [ ${#missing_utils[@]} -ne 0 ]; then
112112
echo -e "${YELLOW}Missing utilities: ${missing_utils[*]}${NC}"
113113
case "$PACKAGE_MANAGER" in
114114
brew)
115-
echo "Install with: brew install pandoc mactex imagemagick"
115+
echo "Install with: brew install pandoc mactex imagemagick viu"
116116
echo "Note: Ensure IBM Plex Serif Light font is available (included in mactex or install separately)."
117117
;;
118118
apt)
119-
echo "Install with: sudo apt update && sudo apt install pandoc texlive-latex-base texlive-fonts-recommended texlive-xelatex imagemagick"
119+
echo "Install with: sudo apt update && sudo apt install pandoc texlive-latex-base texlive-fonts-recommended imagemagick && cargo install viu"
120120
echo "Note: Ensure IBM Plex Serif Light font is installed (may require additional font packages)."
121121
;;
122122
yum)
123-
echo "Install with: sudo yum install pandoc texlive texlive-fonts ImageMagick"
123+
echo "Install with: sudo yum install pandoc texlive texlive-fonts ImageMagick && cargo install viu"
124124
echo "Note: Ensure IBM Plex Serif Light font is installed."
125125
;;
126126
*)
127-
echo "Please install pandoc, xelatex, and imagemagick manually."
127+
echo "Please install pandoc, xelatex, imagemagick, and viu manually (viu via 'cargo install viu')."
128128
echo "Note: Ensure IBM Plex Serif Light font is available for xelatex."
129129
;;
130130
esac

lib/stringformat.rb

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,23 @@ def iterm2?
5050
if kitty?
5151
# Convert PDF to PNG for Kitty
5252
png_file = tmp_file.path.sub('.md', '.png')
53-
system("convert -density 600 #{pdf_file} #{png_file} >/dev/null 2>&1")
53+
system("convert -density 130 #{pdf_file} #{png_file} >/dev/null 2>&1")
5454
if File.exist?(png_file)
55-
png_data = File.read(png_file)
56-
base64_data = Base64.strict_encode64(png_data)
57-
# Clean up
58-
tmp_file.unlink
59-
File.unlink(pdf_file)
60-
File.unlink(png_file)
61-
# Return Kitty inline image sequence
62-
"\e_Gf=100,a=T,t=d;#{base64_data}\e\\"
55+
width = (cols * 0.75).to_i
56+
viu_output = `viu -w #{width} #{png_file} 2>/dev/null`
57+
if $?.success? && !viu_output.empty?
58+
# Clean up
59+
tmp_file.unlink
60+
File.unlink(pdf_file)
61+
File.unlink(png_file)
62+
viu_output
63+
else
64+
# Fallback if viu fails
65+
tmp_file.unlink
66+
File.unlink(pdf_file)
67+
File.unlink(png_file)
68+
self
69+
end
6370
else
6471
# Fallback if PNG conversion fails
6572
tmp_file.unlink

0 commit comments

Comments
 (0)