wybor-0.1.0: Console line fuzzy search

Safe HaskellNone

Wybor

Contents

Synopsis

Documentation

select :: Wybor a -> IO (Either TTYException (Maybe a))Source

Select an item from Wybor once

The user can interrupt the process with C-d and then you get Nothing. Exceptions result in Left _

selections :: MonadResource m => Wybor a -> Source m aSource

Continuously select items from Wybor

Exceptions (see TTYException) aren't caught

data Wybor a Source

The description of the alternative choices, see HasWybor

Instances

fromAssoc :: NonEmpty (Text, a) -> Wybor aSource

Construct Wybor from the nonempty list of key-value pairs

fromTexts :: NonEmpty Text -> Wybor TextSource

Construct Wybor from the nonempty list of strings

The strings are used both as keys and values

fromIO :: IO (Maybe (Maybe (NonEmpty (Text, a)))) -> Wybor aSource

Construct Wybor from the IO action that streams choices

It's useful when the list of alternatives is populated over time from multiple sources (for instance, from HTTP responses)

The interface is tailored for the use with closeable queues from the stm-chans package:

>>> q <- newTMQueueIO
>>> ... {- a bunch of threads populating and eventually closing the queue -}
>>> c <- 'select' ('fromIO' (atomically (tryReadTMQueue q)))
>>> print c

That is, if the IO action returns Nothing the queue will never be read from again and it can return Just Nothing when there's nothing to add to the choices __yet__

It's still possible to use non-fancy queues:

>>> q <- newTQueueIO
>>> ... {- a bunch of threads populating the queue -}
>>> c <- 'select' ('fromIO' (fmap Just (atomically (tryReadTQueue q))))
>>> print c

If choices are static, you will be served better by fromAssoc and fromTexts

class HasWybor t a | t -> a whereSource

A bunch of lenses to pick and configure Wybor

Methods

wybor :: Lens' t (Wybor a)Source

visible :: Lens' t IntSource

How many alternative choices to show at once? (default: 10)

height :: Lens' t IntSource

How many lines every alternative takes on the screen? (default: 1)

initial :: Lens' t TextSource

prefix :: Lens' t TextSource

Prompt prefix (default: >>> )

focused :: Lens' t (Text -> Text)Source

Decoration applied to the focused item (swaps foreground and background colors by default)

Note: should not introduce any printable symbols

normal :: Lens' t (Text -> Text)Source

Decoration applied to other items (is id by default)

Note: should not introduce any printable symbols

Instances

HasWybor (Wybor a) a 

newtype TTYException Source

Exceptions thrown while manipulating /dev/tty device

A bunch of helpers to use with focused and normal

reset :: TextSource

Sets all attributes off

bold :: TextSource

Set bold font style

regular :: TextSource

Set regular font style

underlining :: Underlining -> TextSource

Set underlining style

swap :: TextSource

Swap foreground and background colors

unswap :: TextSource

Unswap foreground and background colors

fgcolor :: ColorIntensity -> Color -> TextSource

Set foreground color

bgcolor :: ColorIntensity -> Color -> TextSource

Set background color

data Color

ANSI colors: come in various intensities, which are controlled by ColorIntensity

Constructors

Black 
Red 
Green 
Yellow 
Blue 
Magenta 
Cyan 
White