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