Skip to content

Commit 5931168

Browse files
committed
Re #178 Better document current behaviour of functions reading stdin
1 parent aefddf5 commit 5931168

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

ansi-terminal/src/System/Console/ANSI.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,8 @@ getReportedCursorPosition = Internal.getReportedCursorPosition
742742
-- as mintty, that are not based on the Windows' Console API. (Command Prompt
743743
-- and PowerShell are based on the Console API.)
744744
--
745+
-- This operation may fail with an error if 'stdin' has been redirected.
746+
--
745747
-- @since 0.10.3
746748
getCursorPosition :: IO (Maybe (Int, Int))
747749
getCursorPosition = hGetCursorPosition stdout
@@ -760,6 +762,8 @@ getCursorPosition = hGetCursorPosition stdout
760762
-- as mintty, that are not based on the Windows' Console API. (Command Prompt
761763
-- and PowerShell are based on the Console API.)
762764
--
765+
-- This operation may fail with an error if 'stdin' has been redirected.
766+
--
763767
-- @since 0.10.1
764768
hGetCursorPosition :: Handle -> IO (Maybe (Int, Int))
765769
hGetCursorPosition h = fmap to0base <$> getCursorPosition'
@@ -864,6 +868,8 @@ getReportedLayerColor = Internal.getReportedLayerColor
864868
--
865869
-- Underlining is not supported.
866870
--
871+
-- This operation may fail with an error if 'stdin' has been redirected.
872+
--
867873
-- @since 0.11.4
868874
getLayerColor :: ConsoleLayer -> IO (Maybe(RGB Word16))
869875
getLayerColor = hGetLayerColor stdout
@@ -882,6 +888,8 @@ getLayerColor = hGetLayerColor stdout
882888
--
883889
-- Underlining is not supported.
884890
--
891+
-- This operation may fail with an error if 'stdin' has been redirected.
892+
--
885893
-- @since 0.11.4
886894
hGetLayerColor :: Handle -> ConsoleLayer -> IO (Maybe (RGB Word16))
887895
hGetLayerColor h layer = do
@@ -976,6 +984,8 @@ layerColor layer = do
976984
-- as mintty, that are not based on Windows' Console API. (Command Prompt and
977985
-- PowerShell are based on the Console API.)
978986
--
987+
-- This operation may fail with an error if 'stdin' has been redirected.
988+
--
979989
-- For a different approach, one that does not use control character sequences
980990
-- and works when 'stdin' is redirected, see the
981991
-- <https://hackage.haskell.org/package/terminal-size terminal-size> package.
@@ -999,6 +1009,8 @@ getTerminalSize = hGetTerminalSize stdout
9991009
-- as mintty, that are not based on the Windows' Console API. (Command Prompt
10001010
-- and PowerShell are based on the Console API.)
10011011
--
1012+
-- This operation may fail with an error if 'stdin' has been redirected.
1013+
--
10021014
-- For a different approach, one that does not use control character sequences
10031015
-- and works when 'stdin' is redirected, see the
10041016
-- <https://hackage.haskell.org/package/terminal-size terminal-size> package.

ansi-terminal/unix/System/Console/ANSI/Internal.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ hSupportsANSIColor h = (|| isEmacsTerm) <$> hSupportsANSI h
9292
-- This approach is taken because the use of C function setenv() in one thread
9393
-- can cause other threads calling C function getenv() to crash. On Unix-like
9494
-- operating systems, System.Environment.lookupEnv is implemented using C
95-
-- function getenv().
95+
-- function getenv().
9696
isNotDumb :: Bool
9797
isNotDumb = unsafePerformIO (lookupEnv "TERM") /= Just "dumb"
9898

@@ -102,7 +102,7 @@ isNotDumb = unsafePerformIO (lookupEnv "TERM") /= Just "dumb"
102102
-- INSIDE_EMACS environment variable exists, that will not change. This approach
103103
-- is taken because the use of C function setenv() in one thread can cause other
104104
-- threads calling C function getenv() to crash. On Unix-like operating systems,
105-
-- System.Environment.lookupEnv is implemented using C function getenv().
105+
-- System.Environment.lookupEnv is implemented using C function getenv().
106106
insideEmacs :: Bool
107107
insideEmacs = isJust $ unsafePerformIO (lookupEnv "INSIDE_EMACS")
108108

0 commit comments

Comments
 (0)