Fork me on GitHub

Files

mon@razerRamon:~/tmp/haskell/howtoscript$ ll
total 24K
-rw-rw-r-- 1 mon mon 445 Jul 6 13:02 Logic.hs
-rwxrwxr-x 1 mon mon 457 Jul 6 14:12 Script.hs*
mon@razerRamon:~/tmp/haskell/howtoscript$

Haskell Code Snippet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module Logic (dimensions) where

{- Dependency to a Hackage pkg: https://hackage.haskell.org/package/terminfo -}
import qualified System.Console.Terminfo.Base as Term
import System.Console.Terminfo.Cursor

dimensions :: IO (Int,Int)
dimensions =
do
term <- Term.setupTermFromEnv

let (Just height) = Term.getCapability term termLines
let (Just width) = Term.getCapability term termColumns

return (height,width)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env stack
{- stack
--resolver lts-8.21
--install-ghc
script
--package terminfo
--
-Wall -Werror
-}


module Main (main) where

{- Import local file which has a dependency to a Hackage pkg:
https://hackage.haskell.org/package/terminfo
-}

import qualified Logic as Terminal

main :: IO ()
main =
do
(height,width) <- Terminal.dimensions

putStrLn ("Term height: " ++ (show height) ++ " & width: " ++ (show width))

Haskell Code output:

mon@razerRamon:~/tmp/haskell/howtoscript$ ./Script.hs 
Term height: 57 & width: 199
mon@razerRamon:~/tmp/haskell/howtoscript$

References:

comments powered by Disqus