#!/usr/bin/env bash # # try.sh - demonstrate IOCCC submission 2025/marcille # Make sure CC is set so that when we do make CC="$CC" it isn't empty. # Doing it this way allows us to have the user specify a different compiler # in an easy way. [[ -z "$CC" ]] && CC="cc" # Build the program. make CC="$CC" all >/dev/null || exit 1 # Try to detect terminal size and Sixel support using control sequences. stty -echo # Send "report size of text area" command. Reply might look like # "\e[8;25;80t", which says height is 25 and width is 80. # # The default is 80x25 if we can't detect the terminal size automatically. # Most terminals supports this control sequence for getting terminal size # so autodetect usually works, one notable exception is GNU screen. IFS=";?c" read -a REPLY -s -t 1 -d "t" -p $'\e[18t' >&2 width=80 height=25 if [[ "${REPLY[1]}" -gt "10" ]] && [[ "${REPLY[2]}" -gt "10" ]]; then width=${REPLY[2]} height=${REPLY[1]} fi # Reduce height by one line so that user can see the second prompt. height=$(($height-1)) # Send "send device attributes" command. Reply might look like "\e[4;6c", # which indicates that it's a "VT132 with Advanced Video and Graphics", # which means Sixel is available. IFS=";?c" read -a REPLY -s -t 1 -d "c" -p $'\e[c' >&2 has_sixel=0 for code in "${REPLY[@]}"; do if [[ "$code" == "4" ]]; then has_sixel=1 break fi done stty echo # Clear screen after compilation so that only the submission is shown. clear # First demo will be the dungeon output. read -r -n 1 -p "Press any key to run: ./prog $width $height | sed -e 's/\\S/#/g' " ./prog "$width" "$height" | sed -e 's/\S/#/g' # Second demo is Sixel output if terminal supports Sixels, or a command to # convert output to PNG otherwise. if [[ "$has_sixel" == "1" ]]; then read -r -n 1 -p "Press any key to run: ./prog $width $height " ./prog "$width" "$height" else read -r -n 1 -p "Press any key to run: ./prog $width $height | convert sixel:- walking_mushroom.png " ./prog "$width" "$height" | convert sixel:- walking_mushroom.png fi