Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ansi-terminal/src/System/Console/ANSI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ import Data.Colour.SRGB ( RGB (..) )
import Data.Word ( Word16 )
import System.IO
( BufferMode (..), Handle, hFlush, hGetBuffering, hGetEcho, hPutStr
, hReady, hSetBuffering, hSetEcho, stdin, stdout
, hReady, hSetBuffering, hSetEcho, stdin, stdout, hIsTerminalDevice
)
import Text.ParserCombinators.ReadP
( ReadP, (<++), char, many1, readP_to_S, satisfy, string )
Expand Down Expand Up @@ -761,7 +761,11 @@ getCursorPosition = hGetCursorPosition stdout
--
-- @since 0.10.1
hGetCursorPosition :: Handle -> IO (Maybe (Int, Int))
hGetCursorPosition h = fmap to0base <$> getCursorPosition'
hGetCursorPosition h = do
isTerminalStdin <- hIsTerminalDevice stdin
if isTerminalStdin
then fmap to0base <$> getCursorPosition'
else pure Nothing
where
to0base (row, col) = (row - 1, col - 1)
getCursorPosition' = do
Expand Down
Loading