diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-08-16 10:39:34 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-08-16 10:39:34 -0700 |
commit | c6ec189a966c100a7992cc633d88efdd176c2a46 (patch) | |
tree | e88d25357a54942c2e4942c021ee266f6bed3fa2 /src | |
parent | cf4b40162d10b17cc7e8fade36c6d2ca9903d9dd (diff) | |
download | pandoc-c6ec189a966c100a7992cc633d88efdd176c2a46.tar.gz |
Revision to binary format output to stdout:
We now allow default output to stdout when it can be
determined that the output is being piped. (On Windows,
as mentioned before, this can't be determined.)
Using '-o -' forces output to stdout regardless.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/App.hs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs index c7f8bbb89..367a1f550 100644 --- a/src/Text/Pandoc/App.hs +++ b/src/Text/Pandoc/App.hs @@ -91,6 +91,10 @@ import Text.Pandoc.Shared (headerShift, isURI, openURL, import qualified Text.Pandoc.UTF8 as UTF8 import Text.Pandoc.XML (toEntities) import Text.Printf +#ifndef _WINDOWS +import System.Posix.IO (stdOutput) +import System.Posix.Terminal (queryTerminal) +#endif data LineEnding = LF | CRLF | Native deriving (Show, Generic) @@ -243,10 +247,17 @@ convertWithOpts opts = do -- We don't want to send output to the terminal if the user -- does 'pandoc -t docx input.txt'; though we allow them to - -- force this with '-o -'. - when (not (isTextFormat format) && optOutputFile opts == Nothing) $ + -- force this with '-o -'. On posix systems, we detect + -- when stdout is being piped and allow output to stdout + -- in that case, but on Windows we can't. +#ifdef _WINDOWS + let istty = True +#else + istty <- queryTerminal stdOutput +#endif + when (not (isTextFormat format) && istty && optOutputFile opts == Nothing) $ E.throwIO $ PandocAppError $ - "Cannot write " ++ format ++ " output to stdout.\n" ++ + "Cannot write " ++ format ++ " output to terminal.\n" ++ "Specify an output file using the -o option, or " ++ "use '-o -' to force output to stdout." |