1
1
mirror of https://github.com/walles/moar.git synced 2024-10-26 13:00:40 +03:00

Condition some log messages on --debug flag

With this change, to get some log messages (about unsupported keys
mostly), you have to pass --debug on the command line.

Fixes #20
This commit is contained in:
Johan Walles 2019-12-06 19:36:31 +01:00
parent 64015a0f90
commit ad767671eb
6 changed files with 28 additions and 12 deletions

1
go.mod
View File

@ -6,6 +6,7 @@ require (
github.com/gdamore/tcell v1.1.2
github.com/google/go-cmp v0.3.0 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/sirupsen/logrus v1.4.2
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5
gotest.tools v2.2.0+incompatible
)

9
go.sum
View File

@ -1,16 +1,23 @@
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell v1.1.2 h1:Afe8cU6SECC06UmvaJ55Jr3Eh0tz/ywLjqWYqjGZp3s=
github.com/gdamore/tcell v1.1.2/go.mod h1:h3kq4HO9l2On+V9ed8w8ewqQEmGCSSHOgQ+2h8uzurE=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4=
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@ -18,6 +25,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:qgOY6WgZOaTkIIMiVjBQcw93ERBE4m30iBm00nkL0i8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=

View File

@ -2,7 +2,7 @@ package m
import (
"fmt"
"log"
log "github.com/sirupsen/logrus"
"os"
"regexp"
"strconv"
@ -298,7 +298,7 @@ func _UpdateStyle(style tcell.Style, escapeSequence string) tcell.Style {
var color *tcell.Color
index, color, err = consumeCompositeColor(numbers, index-1)
if err != nil {
log.Printf("Foreground: %s", err.Error())
log.Warnf("Foreground: %s", err.Error())
return style
}
style = style.Foreground(*color)
@ -327,7 +327,7 @@ func _UpdateStyle(style tcell.Style, escapeSequence string) tcell.Style {
var color *tcell.Color
index, color, err = consumeCompositeColor(numbers, index-1)
if err != nil {
log.Printf("Background: %s", err.Error())
log.Warnf("Background: %s", err.Error())
return style
}
style = style.Background(*color)
@ -335,7 +335,7 @@ func _UpdateStyle(style tcell.Style, escapeSequence string) tcell.Style {
style = style.Background(tcell.ColorDefault)
default:
log.Printf("Unrecognized ANSI SGR code <%s>", number)
log.Warnf("Unrecognized ANSI SGR code <%s>", number)
}
}

View File

@ -2,7 +2,7 @@ package m
import (
"bufio"
"log"
log "github.com/sirupsen/logrus"
"os"
"strings"
"testing"

View File

@ -2,7 +2,7 @@ package m
import (
"fmt"
"log"
log "github.com/sirupsen/logrus"
"os"
"regexp"
"strconv"
@ -503,7 +503,7 @@ func (p *Pager) _OnSearchKey(key tcell.Key) {
p.mode = _Viewing
default:
log.Printf("Unhandled search key event %v", key)
log.Debugf("Unhandled search key event %v", key)
}
}
@ -578,7 +578,7 @@ func (p *Pager) _OnKey(key tcell.Key) {
p.firstLineOneBased -= (height - 1)
default:
log.Printf("Unhandled key event %v", key)
log.Debugf("Unhandled key event %v", key)
}
}
@ -655,7 +655,7 @@ func (p *Pager) _OnRune(char rune) {
p._ScrollToPreviousSearchHit()
default:
log.Printf("Unhandled rune keypress '%s'", string(char))
log.Debugf("Unhandled rune keypress '%s'", string(char))
}
}
@ -765,7 +765,7 @@ func (p *Pager) StartPaging(screen tcell.Screen) {
}
default:
log.Printf("Unhandled event type: %v", ev)
log.Warnf("Unhandled event type: %v", ev)
}
// FIXME: If more events are ready, skip this redraw, that
@ -775,6 +775,6 @@ func (p *Pager) StartPaging(screen tcell.Screen) {
}
if p.reader.err != nil {
log.Printf("Reader reported an error: %s", p.reader.err.Error())
log.Warnf("Reader reported an error: %s", p.reader.err.Error())
}
}

View File

@ -3,8 +3,8 @@ package main
import (
"flag"
"fmt"
log "github.com/sirupsen/logrus"
"io"
"log"
"os"
"os/exec"
"path/filepath"
@ -92,6 +92,7 @@ func main() {
_PrintUsage(os.Stdout)
}
printVersion := flag.Bool("version", false, "Prints the moar version number")
debug := flag.Bool("debug", false, "Print debug logs after exiting")
// FIXME: Support --no-highlight
@ -101,6 +102,11 @@ func main() {
os.Exit(0)
}
log.SetLevel(log.InfoLevel)
if *debug {
log.SetLevel(log.DebugLevel)
}
stdinIsRedirected := !terminal.IsTerminal(int(os.Stdin.Fd()))
stdoutIsRedirected := !terminal.IsTerminal(int(os.Stdout.Fd()))
if stdinIsRedirected && stdoutIsRedirected {