-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.go
66 lines (58 loc) · 1.61 KB
/
debug.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package termemu
import (
"flag"
"fmt"
"io"
"os"
)
var (
debugOutput io.Writer = os.Stderr
debugFile = flag.String("debugFile", "", "File to send debug info to")
debugInitCalled = false
debugCursor = flag.Bool("debugCursor", false, "Print cursor debugging")
debugCharSet = flag.Bool("debugCharSet", false, "Print character set debugging")
debugErase = flag.Bool("debugErase", false, "Print erase debugging")
debugScroll = flag.Bool("debugScroll", false, "Print scroll debugging")
debugTxt = flag.Bool("debugTxt", false, "Print all text written to screen")
debugCmd = flag.Bool("debugCmd", false, "Print all commands")
debugTodo = flag.Bool("debugTodo", true, "Print TODO commands")
debugErrors = flag.Bool("debugErrors", true, "Print Errors")
debugWait = flag.Bool("debugWait", false, "Pause on every debug command")
)
func initDebug() {
debugInitCalled = true
if *debugFile != "" {
f, err := os.OpenFile(*debugFile, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
panic(err)
}
debugOutput = f
}
}
func debugPause(debugFlag *bool) {
if *debugWait && (debugFlag == debugTxt || debugFlag == debugScroll) {
b := []byte{0}
os.Stdin.Read(b)
if b[0] == 'q' {
os.Exit(1)
}
}
}
func debugPrintln(debugFlag *bool, args ...interface{}) {
if !debugInitCalled {
initDebug()
}
if *debugFlag {
fmt.Fprintln(debugOutput, args...)
debugPause(debugFlag)
}
}
func debugPrintf(debugFlag *bool, f string, args ...interface{}) {
if !debugInitCalled {
initDebug()
}
if *debugFlag {
fmt.Fprintf(debugOutput, f, args...)
debugPause(debugFlag)
}
}