vgrep- A pager for grep

Safe HaskellNone




Event handling

An event handler is a function

handleEvent :: MonadState s m => e -> s -> Next (m Redraw)

where e is the event type and s is the state of the handler. The Next type determines the type of action to be performed. The state s is passed as a parameter so the handler can decide which type of action to perform, while not being able to modify the state.

Event handlers form a Monoid where the first handler that triggers will perform the action:

(handleSome <> handleOther) event state

is identical to

case handleSome event state of
    Skip -> handleOther event state
    action -> action

data Next a Source #

The type of action to be performed on an event.



Do not handle the event (fall-through to other event handlers)

Continue a

Handle the event by performing an action

Interrupt Interrupt

Interrupt the application


Functor Next Source # 


fmap :: (a -> b) -> Next a -> Next b #

(<$) :: a -> Next b -> Next a #

Monoid (Next a) Source #

The first event handler that triggers (i. e. does not return Skip) handles the event.


mempty :: Next a #

mappend :: Next a -> Next a -> Next a #

mconcat :: [Next a] -> Next a #

data Redraw Source #



Indicates that the state has been changed visibly, so the screen should be refreshed.


The state has not changed or the change would not be visible, so refreshing the screen is not required.

data Interrupt Source #


Suspend (forall m. MonadIO m => Environment -> m ())

Suspend the application and run the action, e. g. invoking an external process, then resume the application.


Shut down.

Dispatching Events

dispatch :: (e -> Maybe a) -> e -> Next a Source #

If the lookup returns Just action, then handle it with Continue action', otherwise Skip this event handler.

dispatchMap :: Ord e => Map e a -> e -> Next a Source #

Special case of dispatch where actions are looked up from a map.


module Data.Map