From 7c7357f8461720335ab5c794ddaf5a15345f9324 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Thu, 10 Dec 2020 21:21:44 +0000 Subject: [PATCH 1/1] Move back to using tput for hiding the cursor (it works more reliably), also turn off echo so that keypresses don't do silly things in the rendering --- day13/screen.sh | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/day13/screen.sh b/day13/screen.sh index e447c2a..d3bbe6d 100644 --- a/day13/screen.sh +++ b/day13/screen.sh @@ -1,9 +1,27 @@ __arcade_score=0 clear_screen() { + # first reset then clear + echo -en '\033c' echo -en '\033[2J' } +echo_off() { + stty -echo +} + +echo_on() { + stty echo +} + +hide_cursor() { + tput civis +} + +show_cursor() { + tput cvvid +} + move_cursor() { local x=$1 local y=$2 @@ -42,14 +60,6 @@ draw_tile() { esac } -hide_cursor() { - echo -en '\033[25l' -} - -show_cursor() { - echo -en '\033[25h' -} - draw_score_board() { local value=${1:-0} local scoreboard_y=20 @@ -78,6 +88,7 @@ update_score_board() { arcade_screen_init() { clear_screen + echo_off hide_cursor draw_score_board } @@ -94,7 +105,7 @@ arcade_screen_update() { arcade_screen_finish() { move_cursor 0 23 show_cursor - echo high score: $__arcade_score + echo_on } arcade_screen() { @@ -103,10 +114,7 @@ arcade_screen() { local -A blocks # first, clear the screen and hide the cursor - clear_screen - hide_cursor - - draw_score_board + arcade_screen_init while read x; do read y -- 2.39.5