mirror of
https://github.com/walles/moar.git
synced 2024-12-02 09:15:46 +03:00
Don't highlight extensionless files
This commit is contained in:
parent
1103ebf5bc
commit
a66f8b41ba
25
m/reader.go
25
m/reader.go
@ -8,6 +8,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
@ -55,6 +56,7 @@ func _ReadStream(stream io.Reader, reader *Reader, fromFilter *exec.Cmd) {
|
|||||||
// FIXME: Can Wait()ing here stall? Should we release the lock while Wait()ing?
|
// FIXME: Can Wait()ing here stall? Should we release the lock while Wait()ing?
|
||||||
err := fromFilter.Wait()
|
err := fromFilter.Wait()
|
||||||
if reader.err == nil {
|
if reader.err == nil {
|
||||||
|
// FIXME: Add filter stderr contents to the error reported here
|
||||||
reader.err = err
|
reader.err = err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,6 +156,18 @@ func NewReaderFromCommand(filename string, filterCommand ...string) (*Reader, er
|
|||||||
return reader, nil
|
return reader, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _CanHighlight(filename string) bool {
|
||||||
|
ext := filepath.Ext(filename)
|
||||||
|
if len(ext) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Check file extension vs "highlight --list-scripts=langs" before
|
||||||
|
// calling highlight, otherwise files with unsupported extensions (like
|
||||||
|
// .log) get messed upp.
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// NewReaderFromFilename creates a new file reader
|
// NewReaderFromFilename creates a new file reader
|
||||||
func NewReaderFromFilename(filename string) (*Reader, error) {
|
func NewReaderFromFilename(filename string) (*Reader, error) {
|
||||||
if strings.HasSuffix(filename, ".gz") {
|
if strings.HasSuffix(filename, ".gz") {
|
||||||
@ -168,12 +182,11 @@ func NewReaderFromFilename(filename string) (*Reader, error) {
|
|||||||
|
|
||||||
// Highlight input file using highlight:
|
// Highlight input file using highlight:
|
||||||
// http://www.andre-simon.de/doku/highlight/en/highlight.php
|
// http://www.andre-simon.de/doku/highlight/en/highlight.php
|
||||||
//
|
if _CanHighlight(filename) {
|
||||||
// FIXME: Check file extension vs "highlight --list-scripts=langs" before
|
highlighted, err := NewReaderFromCommand(filename, "highlight", "--out-format=esc", "-i")
|
||||||
// calling highlight, otherwise binary files like /bin/ls get messed up.
|
if err == nil {
|
||||||
highlighted, err := NewReaderFromCommand(filename, "highlight", "--out-format=esc", "-i")
|
return highlighted, err
|
||||||
if err == nil {
|
}
|
||||||
return highlighted, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Warn user if highlight is not installed?
|
// FIXME: Warn user if highlight is not installed?
|
||||||
|
Loading…
Reference in New Issue
Block a user