-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
The documentation for getTerminalSize
says
ansi-terminal/ansi-terminal/src/System/Console/ANSI.hs
Lines 957 to 961 in 16d8d3b
-- There is no \'ANSI\' control character sequence that reports the terminal | |
-- size. So, it attempts to set the cursor position beyond the bottom right | |
-- corner of the terminal and then use 'getCursorPosition' to query the console | |
-- input stream. It works only on terminals that support each step and if data | |
-- can be emitted to 'stdin'. (Use 'System.IO.hIsTerminalDevice' to test if |
My understanding of this was that if the preconditions do not hold (either terminal does not support cursor movement or stdin
is not available), getTerminalSize :: IO (Maybe (Int, Int))
will return Nothing
. I was surprised to learn that this is not the case.
Namely, running main = getTerminalSize >>= print
with redirected stdin
fails with an IO exception:
$ ./GetTerminalSize.hs < /dev/null
GetTerminalSize.hs: Uncaught exception ghc-internal:GHC.Internal.IO.Exception.IOException:
<stdin>: hWaitForInput: end of file
HasCallStack backtrace:
ioException, called at libraries/ghc-internal/src/GHC/Internal/IO/Handle/Internals.hs:353:11 in ghc-internal:GHC.Internal.IO.Handle.Internals
Is it intended? Not the end of the world, but I feel like getTerminalSize
could have caught the exception and return Nothing
instead of passing the bucket to a caller.
Metadata
Metadata
Assignees
Labels
No labels