mirror of
https://github.com/walles/moar.git
synced 2024-09-11 12:15:43 +03:00
Don't set up the screen too early
This commit is contained in:
parent
6e8cd95c36
commit
3c03abcef8
@ -531,7 +531,7 @@ func (reader *Reader) createStatusUnlocked(lastLine linenumbers.LineNumber) stri
|
||||
//
|
||||
// Used for making sudo work:
|
||||
// https://github.com/walles/moar/issues/199
|
||||
func (reader *Reader) AwaitFirstLine() {
|
||||
func (reader *Reader) AwaitFirstByte() {
|
||||
<-reader.doneWaitingForFirstByte
|
||||
}
|
||||
|
||||
|
30
moar.go
30
moar.go
@ -661,17 +661,6 @@ func pagerFromArgs(
|
||||
panic("Invariant broken: stdout is not a terminal")
|
||||
}
|
||||
|
||||
screen, err := newScreen(*mouseMode, *terminalColorsCount)
|
||||
if err != nil {
|
||||
// Ref: https://github.com/walles/moar/issues/149
|
||||
log.Debug("Failed to set up screen for paging, pumping to stdout instead: ", err)
|
||||
err := pumpToStdout(flagSet.Args()...)
|
||||
if err != nil {
|
||||
return nil, nil, chroma.Style{}, nil, err
|
||||
}
|
||||
return nil, nil, chroma.Style{}, nil, nil
|
||||
}
|
||||
|
||||
if len(flagSet.Args()) > 1 {
|
||||
fmt.Fprintln(os.Stderr, "ERROR: Expected exactly one filename, or data piped from stdin")
|
||||
fmt.Fprintln(os.Stderr)
|
||||
@ -705,6 +694,22 @@ func pagerFromArgs(
|
||||
}
|
||||
}
|
||||
|
||||
// This makes sudo xyz | moar work
|
||||
reader.AwaitFirstByte()
|
||||
|
||||
// We got the first byte, this means sudo is done (if it was used) and we
|
||||
// can set up the UI
|
||||
screen, err := newScreen(*mouseMode, *terminalColorsCount)
|
||||
if err != nil {
|
||||
// Ref: https://github.com/walles/moar/issues/149
|
||||
log.Debug("Failed to set up screen for paging, pumping to stdout instead: ", err)
|
||||
err := pumpToStdout(flagSet.Args()...)
|
||||
if err != nil {
|
||||
return nil, nil, chroma.Style{}, nil, err
|
||||
}
|
||||
return nil, nil, chroma.Style{}, nil, nil
|
||||
}
|
||||
|
||||
var style chroma.Style
|
||||
if *styleOption == nil {
|
||||
t0 := time.Now()
|
||||
@ -739,11 +744,8 @@ func pagerFromArgs(
|
||||
} else {
|
||||
style = **styleOption
|
||||
}
|
||||
|
||||
reader.SetStyleForHighlighting(style)
|
||||
|
||||
reader.AwaitFirstLine()
|
||||
|
||||
pager := m.NewPager(reader)
|
||||
pager.WrapLongLines = *wrap
|
||||
pager.ShowLineNumbers = !*noLineNumbers
|
||||
|
Loading…
Reference in New Issue
Block a user