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

System.IO.Echo.Internal

Description

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

Unlike System.IO.Echo, this module exports internal functionality which, if used improperly, can lead to runtime errors. Make sure to read the documentation beforehand!

Synopsis

# Safe 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)


Return the terminal's current input EchoState.

Set the terminal's input EchoState.

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

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

# Alternative (safe) interface

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.

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

# Unsafe STTY internals

data EchoState Source #

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

Constructors

 MinTTY STTYSettings The argument to (or value returned from) an invocation of the stty command-line utility. Most POSIX-like shells have stty, including MinTTY on Windows. Since neither hGetEcho nor hSetEcho work on MinTTY, when getInputEchoState runs on MinTTY, it returns a value built with this constructor.However, native Windows consoles like cmd.exe or PowerShell do not have stty, so if you construct an EchoState with this constructor manually, take care not to use it with a native Windows console. DefaultTTY Bool A simple on (True) or off (False) toggle. This is returned by hGetEcho and given as an argument to hSetEcho, which work on most consoles, with the notable exception of MinTTY on Windows. If you construct an EchoState with this constructor manually, take care not to use it with MinTTY.

Instances

 Source # Methods Source # Methods Source # MethodsshowList :: [EchoState] -> ShowS #

Settings used to configure the stty command-line utility.

Return all of stty's current settings in a non-human-readable format.

This function is not very useful on its own. Its greater purpose is to provide a compact STTYSettings that can be fed back into setInputEchoState.

Create an stty process and wait for it to complete. This is useful for changing stty's settings, after which stty does not output anything.

setInputEchoSTTY = void . sttyRaw


Create an stty process, wait for it to complete, and return its output.

# MinTTY

Is the current process attached to a MinTTY console (e.g., Cygwin or MSYS)?