#!/bin/bash12# You need the "glow" executable on your path to run this script34# Function to render markdown using glow5render_markdown() {6local input="$1"7glow --style auto <<< "$input"8}910input_buffer=""11line_count=01213# Save cursor position and hide it14tput sc15tput civis1617# Clear screen once at the beginning18clear1920# Read input line by line21while IFS= read -r line || [[ -n "$line" ]]; do22# Increment line count23((line_count++))2425# Append the new line to input buffer26input_buffer+="$line"$'\n'2728# Move cursor to home position (top-left corner)29tput home3031# Render the current buffer32render_markdown "$input_buffer"3334# Clear from cursor to end of screen35tput ed3637# If we've rendered more than the terminal height, reset the screen38if ((line_count % $(tput lines) == 0)); then39clear40tput home41fi42done4344# Show cursor again45tput cnorm464748