Move back to using tput for hiding the cursor (it works more reliably), also turn...
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Thu, 10 Dec 2020 21:21:44 +0000 (21:21 +0000)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Thu, 10 Dec 2020 21:21:44 +0000 (21:21 +0000)
day13/screen.sh

index e447c2a2636b6d34c304e5f0c3e55c56101c1b1c..d3bbe6d8fa92e2300592b26af4cad4af36971036 100644 (file)
@@ -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