-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.go
More file actions
40 lines (35 loc) · 700 Bytes
/
Copy pathconsole.go
File metadata and controls
40 lines (35 loc) · 700 Bytes
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
package ipcheck
import (
"fmt"
"os"
"strings"
"sync"
)
var (
printMu sync.Mutex
lastWasRefresh bool
)
func consoleRefresh(format string, args ...any) {
printMu.Lock()
defer printMu.Unlock()
fmt.Fprintf(os.Stdout, "\r%s\033[K", fmt.Sprintf(format, args...))
lastWasRefresh = true
}
func consolePrint(args ...any) {
printMu.Lock()
defer printMu.Unlock()
if lastWasRefresh {
fmt.Fprint(os.Stdout, "\r\033[K")
lastWasRefresh = false
}
text := strings.TrimSuffix(fmt.Sprintln(args...), "\n")
fmt.Fprintln(os.Stdout, text)
}
func consoleKeepRefreshLine() {
printMu.Lock()
defer printMu.Unlock()
if lastWasRefresh {
fmt.Fprintln(os.Stdout)
lastWasRefresh = false
}
}