byline-1.1.1: Library for creating command-line interfaces (colors, menus, etc.)
Copyright This file is part of the package byline. It is subject to thelicense terms in the LICENSE file found in the top-leveldirectory of this distribution and at:https://github.com/pjones/bylineNo part of this package including this file may be copiedmodified propagated or distributed except according to theterms contained in the LICENSE file. BSD-2-Clause None Haskell2010

Byline.Completion

Description

Synopsis

Haskeline makes it very difficult (if not impossible) to implement a completion function that runs in an arbitrary monad. More information can be found in the documentation for CompletionFunc.

# Completion Function

type CompletionFunc m = (Text, Text) -> m (Text, [Completion]) Source #

A completion function modeled after the one used in Haskeline.

Warning: If you're familiar with the Haskeline version of the CompletionFunc type please be sure to read this description carefully since the two behave differently.

The completion function is called when the user presses the tab key. The current input line is split into two parts based on where the cursor is positioned. Text to the left of the cursor will be the first value in the tuple and text to the right of the cursor will be the second value.

The text returned from the completion function is the text from the left of the cursor which wasn't used in the completion. It should also produce a list of possible Completion values.

In Haskeline, some of these text values are reversed. This is not the case in Byline.

A note about IO:

Due to Haskeline, the completion function is forced to return an IO value. It would be better if it could return a value in the base monad instead but it doesn't look like that's possible. Patches welcome.

Since: 1.0.0.0

A type representing a completion match to the user's input.

Since: 1.0.0.0

Constructors

 Completion Fieldsreplacement :: TextText to insert to the right of the cursor.display :: TextText to display when listing all completions.isFinished :: BoolWhether to follow the completed word with a terminating space or close existing quotes.

#### Instances

Instances details
 Source # Instance detailsDefined in Byline.Internal.Completion Methods Source # Instance detailsDefined in Byline.Internal.Completion Methods Source # Instance detailsDefined in Byline.Internal.Completion MethodsshowList :: [Completion] -> ShowS #

# Completion Helpers

data CompLoc Source #

Type to describe where completions are allowed.

Since: 1.1.0.0

Constructors

 CompHead Only complete the first word of input. CompTail Complete any word except the first. CompAny Perform completion anywhere in the input.

Arguments

 :: forall m. Applicative m => CompLoc Where to allow completion. -> [Text] List of completion candidates. -> CompletionFunc m The generated completion function.

Generate a completion function that uses the given list as the completion candidates.

Since: 1.1.0.0

# Setting the Active Completion Function

Add a CompletionFunc to the stack.

Since: 1.0.0.0

popCompletionFunction :: MonadByline m => m () Source #

Remove the top completion function from the stack.

Since: 1.0.0.0