diff --git a/README.md b/README.md index 7709f9a..a21c41c 100644 --- a/README.md +++ b/README.md @@ -59,10 +59,11 @@ to skip overwrite confirmations. $ ./smlfmt --force src/smlfmt.mlb ``` -To pass code through `stdin` and `stdout`, use the `--stdio` flag. +Additionally, code can be passed directly through `stdin` and `stdout`. ```bash -$ echo "val x = 5 val y = 6" | ./smlfmt --stdio +$ echo "val x = 5 val y = 6" | ./smlfmt ``` +To force this behaviour, `--stdio` can be used. ### Command-line options @@ -76,6 +77,8 @@ with syntax highlighting (if shown on terminal supporting ANSI colors). `--stdio` reads SML input from `stdin`, and outputs the formatted SML to `stdout`. (This is incompatible with file inputs and the flags above.) +If no incompatible flag is set and `stdin` is not a terminal, this is +the default. `-mlb-path-var ' '` for handling path variables, similar to [MLton's path maps](http://mlton.org/MLBasisPathMap). diff --git a/src/smlfmt.sml b/src/smlfmt.sml index 080a11c..2936ef6 100644 --- a/src/smlfmt.sml +++ b/src/smlfmt.sml @@ -94,6 +94,15 @@ val doCheck = CommandLineArgs.parseFlag "check" val preview = CommandLineArgs.parseFlag "preview" val previewOnly = CommandLineArgs.parseFlag "preview-only" val stdio = CommandLineArgs.parseFlag "stdio" +val stdio = + stdio + orelse + (* if stdin is not a terminal and an incompabible flag is not set, take input from stdin *) + (not (Posix.ProcEnv.isatty Posix.FileSys.stdin) + andalso + not + (doForce orelse preview orelse previewOnly + orelse not (List.null inputfiles))) val showPreview = preview orelse previewOnly fun dbgprintln s =