1
1
mirror of https://github.com/walles/moar.git synced 2024-11-23 05:53:18 +03:00

Clock bg color detection and log it

This commit is contained in:
Johan Walles 2024-01-13 10:28:30 +01:00
parent f4884b5d2a
commit 711960c606
2 changed files with 12 additions and 9 deletions

View File

@ -110,7 +110,7 @@ func (reader *Reader) readStream(stream io.Reader, originalFileName *string, onD
bufioReader := bufio.NewReader(stream)
completeLine := make([]byte, 0)
t0 := time.Now().UnixNano()
t0 := time.Now()
for {
keepReadingLine := true
eof := false
@ -171,9 +171,8 @@ func (reader *Reader) readStream(stream io.Reader, originalFileName *string, onD
onDone()
}
t1 := time.Now().UnixNano()
dtNanos := t1 - t0
log.Debug("Stream read in ", dtNanos/1_000_000, "ms")
t1 := time.Now()
log.Debug("Stream read in ", t1.Sub(t0))
}
// NewReaderFromStream creates a new stream reader
@ -307,7 +306,7 @@ func countLines(filename string) (uint64, error) {
}()
var count uint64
t0 := time.Now().UnixNano()
t0 := time.Now()
buf := make([]byte, bufio.MaxScanTokenSize)
lastReadEndsInNewline := true
for {
@ -331,12 +330,11 @@ func countLines(filename string) (uint64, error) {
count++
}
t1 := time.Now().UnixNano()
dtNanos := t1 - t0
t1 := time.Now()
if count == 0 {
log.Debug("Counted ", count, " lines in 0ms")
log.Debug("Counted ", count, " lines in ", t1.Sub(t0))
} else {
log.Debug("Counted ", count, " lines in ", dtNanos/1_000_000, "ms at ", dtNanos/int64(count), "ns/line")
log.Debug("Counted ", count, " lines in ", t1.Sub(t0), " at ", (t1.Sub(t0))/time.Duration(count), "/line")
}
return count, nil
}

View File

@ -611,6 +611,8 @@ func decodeStyleOption(styleOption **chroma.Style) chroma.Style {
return **styleOption
}
t0 := time.Now()
// Prep for querying the terminal background color
oldTerminalState, err := term.MakeRaw(int(os.Stdout.Fd()))
if err != nil {
@ -676,6 +678,9 @@ func decodeStyleOption(styleOption **chroma.Style) chroma.Style {
return *styles.Get(defaultDarkTheme)
}
t1 := time.Now()
log.Debug("Terminal background color detection took ", t1.Sub(t0))
color := twin.NewColor24Bit(uint8(red/256), uint8(green/256), uint8(blue/256))
log.Debug("Terminal background color detected: ", color)