echo-0.1.4: A cross-platform, cross-console way to handle echoing terminal input

Copyright | (C) 2016-2017 Ryan Scott
License | BSD-style (see the file LICENSE)
Maintainer | Ryan Scott
Stability | Provisional
Portability | Portable
Safe Haskell | Safe
Language | Haskell2010

System.IO.Echo

Contents

- Public interface
- Alternative interface

Description

Exports functions that handle whether or not terminal input is handled in a way that should be portable across different platforms and consoles.

Synopsis

- withoutInputEcho :: IO a -> IO a
- bracketInputEcho :: IO a -> IO a
- getInputEchoState :: IO EchoState
- setInputEchoState :: EchoState -> IO ()
- data EchoState
- echoOff :: EchoState
- echoOn :: EchoState
- getInputEcho :: IO Bool
- setInputEcho :: Bool -> IO ()

# Public interface

withoutInputEcho :: IO a -> IO a Source #

Perform a computation with the terminal's input echoing disabled. Before running the computation, the terminal's input `EchoState` is saved, and the saved `EchoState` is restored after the computation finishes.

    withoutInputEcho action = bracketInputEcho (setInputEchoState echoOff >> action)

bracketInputEcho :: IO a -> IO a Source #

Save the terminal's current input `EchoState`, perform a computation, restore the saved `EchoState`, and then return the result of the computation.

    bracketInputEcho action = bracket getInputEchoState setInputEchoState (const action)

getInputEchoState :: IO EchoState Source #

Return the terminal's current input `EchoState`.

setInputEchoState :: EchoState -> IO () Source #

Set the terminal's input `EchoState`.

data EchoState Source #

A representation of the terminal input's current echoing state. Example values include `echoOff` and `echoOn`.

#### Instances

Instances details

Show EchoState Source # |
Instance details Defined in System.IO.Echo.Internal Methods showsPrec :: Int -> EchoState -> ShowS Source # show :: EchoState -> String Source # showList :: [EchoState] -> ShowS Source #
Eq EchoState Source # |
Instance details Defined in System.IO.Echo.Internal Methods (==) :: EchoState -> EchoState -> Bool Source # (/=) :: EchoState -> EchoState -> Bool Source #
Ord EchoState Source # |

Instance details

Defined in System.IO.Echo.Internal

Methods

compare :: EchoState -> EchoState -> Ordering Source #

(<) :: EchoState -> EchoState -> Bool Source #

(<=) :: EchoState -> EchoState -> Bool Source #

(>) :: EchoState -> EchoState -> Bool Source #

(>=) :: EchoState -> EchoState -> Bool Source #

max :: EchoState -> EchoState -> EchoState Source #

min :: EchoState -> EchoState -> EchoState Source #

echoOff :: EchoState Source #

Indicates that the terminal's input echoing is (or should be) off.

echoOn :: EchoState Source #

Indicates that the terminal's input echoing is (or should be) on.

# Alternative interface

getInputEcho :: IO Bool Source #

Return whether the terminal's echoing is on (`True`) or off (`False`).

Note that while this works on MinTTY, it is not as efficient as `getInputEchoState`, as it involves a somewhat expensive substring computation.

setInputEcho :: Bool -> IO () Source #

Set the terminal's echoing on (`True`) or off (`False`).