-
Notifications
You must be signed in to change notification settings - Fork 38
/
mdrender.sh
executable file
·46 lines (34 loc) · 913 Bytes
/
mdrender.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# You need the "glow" executable on your path to run this script
# Function to render markdown using glow
render_markdown() {
local input="$1"
glow --style auto <<< "$input"
}
input_buffer=""
line_count=0
# Save cursor position and hide it
tput sc
tput civis
# Clear screen once at the beginning
clear
# Read input line by line
while IFS= read -r line || [[ -n "$line" ]]; do
# Increment line count
((line_count++))
# Append the new line to input buffer
input_buffer+="$line"$'\n'
# Move cursor to home position (top-left corner)
tput home
# Render the current buffer
render_markdown "$input_buffer"
# Clear from cursor to end of screen
tput ed
# If we've rendered more than the terminal height, reset the screen
if ((line_count % $(tput lines) == 0)); then
clear
tput home
fi
done
# Show cursor again
tput cnorm