Skip to content

Commit

Permalink
Hide cursor during program run
Browse files Browse the repository at this point in the history
  • Loading branch information
naftalibeder committed Aug 17, 2024
1 parent bc59247 commit 1e219ea
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"os"
"os/signal"
"strings"
"testing"
"time"
Expand All @@ -23,7 +24,9 @@ const (
)

const (
headerColWd = 5
headerColWd = 5
hideCursorCode = "\033[?25l"
showCursorCode = "\033[?25h"
)

var (
Expand All @@ -38,8 +41,19 @@ func Start() {
return
}

fmt.Print(hideCursorCode)

termFD = int(os.Stdin.Fd())
output = map[int][][]string{}

c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for range c {
fmt.Print(showCursorCode)
os.Exit(1)
}
}()
}

func Update(phase int, entry [][]string) {
Expand Down Expand Up @@ -136,13 +150,12 @@ func write(rows [][]string, retreat bool) {
}
addRowDivider()

// Print and clean up.
if retreat {
fmt.Fprintf(writer, "\033[%dA", lineCt)
}

writer.Flush()

if retreat {
fmt.Printf("\033[%dA", lineCt)
}
}

func GetElapsedStr(start time.Time) string {
Expand Down

0 comments on commit 1e219ea

Please sign in to comment.