Skip to content

Commit

Permalink
Fix code examples in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilgrem committed Jan 13, 2024
1 parent 40e2464 commit 0149574
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
33 changes: 20 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,28 @@ but for a taste of how the library works try the following code:

``` haskell
import System.Console.ANSI
import System.IO (stdout)

main :: IO ()
main = do
setCursorPosition 5 0
setTitle "ANSI Terminal Short Example"

setSGR [ SetConsoleIntensity BoldIntensity
, SetColor Foreground Vivid Red
]
putStr "Hello"

setSGR [ SetConsoleIntensity NormalIntensity
, SetColor Foreground Vivid White
, SetColor Background Dull Blue
]
putStrLn "World!"
stdoutSupportsANSI <- hNowSupportsANSI stdout
if stdoutSupportsANSI
then do
setCursorPosition 5 0
setTitle "ANSI Terminal Short Example"

setSGR [ SetConsoleIntensity BoldIntensity
, SetColor Foreground Vivid Red
]
putStr "Hello"

setSGR [ SetConsoleIntensity NormalIntensity
, SetColor Foreground Vivid White
, SetColor Background Dull Blue
]
putStrLn "World!"
else
putStrLn "Standard output does not support 'ANSI' escape codes."
```

![](https://raw.githubusercontent.com/feuerbach/ansi-terminal/master/example.png)
Expand Down
3 changes: 2 additions & 1 deletion ansi-terminal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ but for a taste of how the library works try the following code:
import System.Console.ANSI
import System.IO (stdout)

main :: IO ()
main = do
stdoutSupportsANSI <- hNowSupportsANSI stdout
if stdoutSupportsANSI
then
then do
setCursorPosition 5 0
setTitle "ANSI Terminal Short Example"

Expand Down
4 changes: 2 additions & 2 deletions ansi-terminal/src/System/Console/ANSI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ A simple example is below:
> main = do
> stdoutSupportsANSI <- hNowSupportsANSI stdout
> if stdoutSupportsANSI
> then
> then do
> setSGR [SetColor Foreground Vivid Red]
> setSGR [SetColor Background Vivid Blue]
> putStrLn "Red-On-Blue"
Expand All @@ -158,7 +158,7 @@ Another example is below:
> main = do
> stdoutSupportsANSI <- hNowSupportsANSI stdout
> if stdoutSupportsANSI
> then
> then do
> setSGR [SetColor Foreground Dull Blue]
> putStr "Enter your name: "
> setSGR [SetColor Foreground Dull Yellow]
Expand Down

0 comments on commit 0149574

Please sign in to comment.