Skip to content

Commit

Permalink
Select lexer with --filename argument (#77)
Browse files Browse the repository at this point in the history
cgit's syntax highlighting filter pipes to STDIN and provides the
filename in argv; the analyzer often fails but we have access to the
original filename, so we add an optional argument to specify the
filename to use for matching a lexer when reading from STDIN; when
[files...] are provided to chroma this is completely ignored
  • Loading branch information
douglas-larocca authored and alecthomas committed Oct 24, 2017
1 parent 93868c5 commit 3d8ce90
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/chroma/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
unbufferedFlag = kingpin.Flag("unbuffered", "Do not buffer output.").Bool()
traceFlag = kingpin.Flag("trace", "Trace lexer states as they are traversed.").Bool()
checkFlag = kingpin.Flag("check", "Do not format, check for tokenization errors instead.").Bool()
filenameFlag = kingpin.Flag("filename", "Filename to use for selecting a lexer when reading from stdin.").String()

lexerFlag = kingpin.Flag("lexer", "Lexer to use when formatting.").PlaceHolder("autodetect").Short('l').Enum(lexers.Names(true)...)
styleFlag = kingpin.Flag("style", "Style to use for formatting.").Short('s').Default("swapoff").Enum(styles.Names()...)
Expand Down Expand Up @@ -167,7 +168,7 @@ command, for Go.
if len(*filesArgs) == 0 {
contents, err := ioutil.ReadAll(os.Stdin)
kingpin.FatalIfError(err, "")
format(w, style, lex("", string(contents)))
format(w, style, lex(*filenameFlag, string(contents)))
} else {
for _, filename := range *filesArgs {
contents, err := ioutil.ReadFile(filename)
Expand Down

0 comments on commit 3d8ce90

Please sign in to comment.