#!/bin/bash # Compile a pattern generator and dump output to stdout. # # Requires ImageMagick and terminal with sixel support. Terminals that # support sixel include xterm when launched with "xterm -ti vt340", # and also Cygwin's mintty. if [[ $# -ne 1 ]]; then echo "$0 " exit 1 fi if ! [[ -r $1 ]]; then echo "$1 is not readable" exit 1 fi # Build target and sizing utility. target=${1%.c}.exe make -j -s terminal_size.exe $target || exit 1 # Set output image size. terminal_width=$(./terminal_size.exe ws_xpixel) terminal_height=$(./terminal_size.exe ws_ypixel) if [[ $terminal_width -gt 0 ]] && [[ $terminal_height -gt 0 ]]; then # Successfully gotten terminal size in pixels. Now try adding some margins. columns=$(./terminal_size.exe ws_col) rows=$(./terminal_size.exe ws_row) font_width=$(( $terminal_width / $columns )) font_height=$(( $terminal_height / $rows )) width=$(( $font_width * ($columns - 1) )) height=$(( $font_height * ($rows - 2) )) else # Couldn't get terminal size in pixels, assume a specific font size # and go with that. font_width=8 font_height=18 terminal_width=$(( $(tput cols) * $font_width )) terminal_height=$(( $(tput lines) * $font_height )) width=$(( $terminal_width / $(tput cols) * ($(tput cols) - 1) )) height=$(( $terminal_height / $(tput lines) * ($(tput lines) - 2) )) fi # Run and feed output through ImageMagick. ./$target $width $height 2>/dev/null | convert ppm:- six:-