Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
A simple brick app to search among the candidates from a vector of text and get the selection. By default the app doesn't do anything except
return a single selection but more complicated actions can be performed by using the _hooks
which allow abitrary IO actions (due to EventM
being a MonadIO
)
in response to input events. The most convenient function to use the brick app are selected
and related functions. runApp
provides some more flexibility.
Synopsis
- data Searcher a = forall n.KnownNat n => Searcher {
- getSearcher :: SearcherSized n a
- data SearchEvent a = forall n.KnownNat n => SearchEvent (SearchEventSized n a)
- data SearchEnv n a b = SearchEnv {
- _searchFunctions :: SearchFunctions a b
- _send :: forall n m. (KnownNat n, KnownNat m) => Chunks n -> SearchReport -> MatcherSized m a -> MatchSetSized m -> IO ()
- _maxMatches :: Int
- _candidates :: Chunks n
- _query :: MVar (Maybe Text)
- _allMatches :: IOVector (Vector n Bit)
- data EventHooks a = EventHooks {
- keyHook :: Key -> [Modifier] -> EventM Bool a ()
- pasteHook :: ByteString -> EventM Bool a ()
- resizeHook :: Int -> Int -> EventM Bool a ()
- mouseDownHook :: Int -> Int -> Button -> [Modifier] -> EventM Bool a ()
- mouseUpHook :: Int -> Int -> Maybe Button -> EventM Bool a ()
- focusLostHook :: EventM Bool a ()
- focusGainedHook :: EventM Bool a ()
- data AppTheme = AppTheme {
- _prompt :: Text
- _themeAttrs :: [(AttrName, Attr)]
- _borderStyle :: BorderStyle
- type AppSettings n a = AppSettingsG n a (Widget Bool) AppTheme
- data AppSettingsG (n :: Nat) a b t = AppSettings {
- _theme :: t
- _hooks :: ReaderT (SearchEnv n a b) EventHooks (Searcher a)
- _chunkSize :: Proxy n
- _maximumMatches :: Int
- _eventStrategy :: SearchReport -> Bool
- data CaseSensitivity
- searchApp :: KnownNat n => AppSettings n a -> SearchEnv n a (Widget Bool) -> App (Searcher a) (SearchEvent a) Bool
- defSettings :: KnownNat n => AppSettings n a
- fuzzyFunctions :: CaseSensitivity -> SearchFunctions MatchPart b
- orderlessFunctions :: CaseSensitivity -> SearchFunctions Int b
- runApp :: KnownNat n => AppSettings n a -> SearchFunctions a (Widget Bool) -> Chunks n -> IO (Searcher a)
- runAppFromHandle :: KnownNat n => AppSettings n a -> SearchFunctions a (Widget Bool) -> Handle -> IO (Searcher a)
- selected :: KnownNat n => AppSettings n a -> SearchFunctions a (Widget Bool) -> Chunks n -> IO (Maybe Text)
- selectedFromHandle :: KnownNat n => AppSettings n a -> SearchFunctions a (Widget Bool) -> Handle -> IO (Maybe Text)
- selectedFromHandleWith :: KnownNat n => (Text -> Text) -> (Vector Text -> Vector Text) -> AppSettings n a -> SearchFunctions a (Widget Bool) -> Handle -> IO (Maybe Text)
- selectedFromFileNamesSorted :: KnownNat n => AppSettings n a -> SearchFunctions a (Widget Bool) -> Handle -> IO (Maybe Text)
- selectedFromFiles :: KnownNat n => AppSettings n a -> SearchFunctions a (Widget Bool) -> [FindInDirs] -> IO (Maybe Text)
- selectedUsing :: KnownNat n => AppSettings n a -> SearchFunctions a (Widget Bool) -> (a -> Text) -> Vector a -> IO (Maybe a)
- runSearch :: AppSettings 64 a -> SearchFunctions a (Widget Bool) -> IO ()
- makeChunks :: forall n. KnownNat n => Vector Text -> Chunks n
- run :: IO ()
- run' :: [String] -> IO ()
- queryEditor :: forall n a. Lens' (SearcherSized n a) (Editor Text Bool)
- allMatches :: forall n a b. Lens' (SearchEnv n a b) (IOVector (Vector n Bit))
- matches :: forall n a. Lens' (SearcherSized n a) (GenericList Bool MatchSetG (ScoredMatchSized n))
- numMatches :: forall n a. Lens' (SearcherSized n a) Int
- matchedTop :: forall n a. Lens' (SearchEventSized n a) (MatchSetSized n)
- totalMatches :: forall n a a. Lens (SearchStateSized n a) (SearchStateSized n a) Int Int
- term :: forall n a. Lens' (SearchEventSized n a) Text
- candidates :: forall n a b. Lens' (SearchEnv n a b) (Chunks n)
- eventSource :: forall n a. Lens' (SearcherSized n a) (BChan (SearchEvent a))
- makeMatcher :: forall a b. Lens' (SearchFunctions a b) (Text -> Matcher a)
- match :: forall a b n. KnownNat n => SimpleGetter (SearchFunctions a b) (MatcherSized n a -> Text -> Maybe (MatchFull n))
- display :: forall a b n. KnownNat n => SimpleGetter (SearchFunctions a b) ((Bool -> Text -> b) -> MatcherSized n a -> Text -> Vector n Int -> [b])
- prompt :: Lens' AppTheme Text
- themeAttrs :: Lens' AppTheme [(AttrName, Attr)]
- borderStyle :: Lens' AppTheme BorderStyle
- theme :: forall n a b t t. Lens (AppSettingsG n a b t) (AppSettingsG n a b t) t t
- hooks :: forall n a b t a b. Lens (AppSettingsG n a b t) (AppSettingsG n a b t) (ReaderT (SearchEnv n a b) EventHooks (Searcher a)) (ReaderT (SearchEnv n a b) EventHooks (Searcher a))
- defTheme :: AppTheme
- defHooks :: EventHooks a
- handleKeyEvent :: KnownNat n => SearchEnv n a c -> Key -> [Modifier] -> EventM Bool (Searcher b) ()
- handleSearch :: SearchEvent a -> EventM Bool (Searcher a) ()
- searcherWidget :: (KnownNat n, KnownNat m) => SearchEnv n a (Widget Bool) -> Text -> SearcherSized m a -> Widget Bool
- initialSearcher :: SearchEnv n a c -> BChan (SearchEvent a) -> SearcherSized 0 a
- readVectorHandleWith :: (Text -> Text) -> (Vector Text -> Vector Text) -> Handle -> IO (Vector Text)
Types
data SearchEvent a Source #
forall n.KnownNat n => SearchEvent (SearchEventSized n a) |
The constant environment in which the search runs.
SearchEnv | |
|
data EventHooks a Source #
Event hooks are almost direct translations of the events from vty i.e. see Event
.
EventHooks | |
|
AppTheme | |
|
type AppSettings n a = AppSettingsG n a (Widget Bool) AppTheme Source #
data AppSettingsG (n :: Nat) a b t Source #
AppSettings | |
|
data CaseSensitivity #
Instances
The Brick App and Helpers
searchApp :: KnownNat n => AppSettings n a -> SearchEnv n a (Widget Bool) -> App (Searcher a) (SearchEvent a) Bool Source #
Tha app itself. selected
and the related functions are probably more convenient for embedding into a larger program.
defSettings :: KnownNat n => AppSettings n a Source #
Default settings. Uses blue for various highlights and cyan for borders. All the hooks except keyHook which is handleKeyEvent
are trivial.
runApp :: KnownNat n => AppSettings n a -> SearchFunctions a (Widget Bool) -> Chunks n -> IO (Searcher a) Source #
Run app with given settings and return the final Searcher state.
runAppFromHandle :: KnownNat n => AppSettings n a -> SearchFunctions a (Widget Bool) -> Handle -> IO (Searcher a) Source #
Run app with a vector that contains lines read from a handle and return the final Searcher state.
selected :: KnownNat n => AppSettings n a -> SearchFunctions a (Widget Bool) -> Chunks n -> IO (Maybe Text) Source #
Run app and return the text of the selection if there is one else Nothing.
selectedFromHandle :: KnownNat n => AppSettings n a -> SearchFunctions a (Widget Bool) -> Handle -> IO (Maybe Text) Source #
Same as selected
but reads the vector from the supplied handle.
selectedFromHandleWith :: KnownNat n => (Text -> Text) -> (Vector Text -> Vector Text) -> AppSettings n a -> SearchFunctions a (Widget Bool) -> Handle -> IO (Maybe Text) Source #
Same as selectedFromHandle
but allows for transforming the lines read and the final vector with supplied functions. See also readVectorHandleWith
.
selectedFromFileNamesSorted :: KnownNat n => AppSettings n a -> SearchFunctions a (Widget Bool) -> Handle -> IO (Maybe Text) Source #
Another variation on selectedFromHandle
. See fileNamesSorted
for what happens to read vector.
selectedFromFiles :: KnownNat n => AppSettings n a -> SearchFunctions a (Widget Bool) -> [FindInDirs] -> IO (Maybe Text) Source #
Version of selected
for file search using a simple implementation of searching file trees from Talash.Files. Better to use either other
libraries like unix-recursive
or external programs like fd
for more complicated tasks.
selectedUsing :: KnownNat n => AppSettings n a -> SearchFunctions a (Widget Bool) -> (a -> Text) -> Vector a -> IO (Maybe a) Source #
runSearch :: AppSettings 64 a -> SearchFunctions a (Widget Bool) -> IO () Source #
A version of selected
that puts the selected text on the stdout.
Default program
Defualt program for the brick app that reads candidates from stdin and prints the selected text to the stdout. Can be called from the executable with
talash tui
which uses the orderless style. The search style can be set explicitly by calling talash tui fuzzy
or talash tui orderless
Lenses
Searcher
matches :: forall n a. Lens' (SearcherSized n a) (GenericList Bool MatchSetG (ScoredMatchSized n)) Source #
numMatches :: forall n a. Lens' (SearcherSized n a) Int Source #
SearchEvent
matchedTop :: forall n a. Lens' (SearchEventSized n a) (MatchSetSized n) Source #
totalMatches :: forall n a a. Lens (SearchStateSized n a) (SearchStateSized n a) Int Int Source #
SearchEnv
eventSource :: forall n a. Lens' (SearcherSized n a) (BChan (SearchEvent a)) Source #
SearchFunctions
makeMatcher :: forall a b. Lens' (SearchFunctions a b) (Text -> Matcher a) Source #
match :: forall a b n. KnownNat n => SimpleGetter (SearchFunctions a b) (MatcherSized n a -> Text -> Maybe (MatchFull n)) Source #
display :: forall a b n. KnownNat n => SimpleGetter (SearchFunctions a b) ((Bool -> Text -> b) -> MatcherSized n a -> Text -> Vector n Int -> [b]) Source #
AppTheme
SearchSettings
theme :: forall n a b t t. Lens (AppSettingsG n a b t) (AppSettingsG n a b t) t t Source #
hooks :: forall n a b t a b. Lens (AppSettingsG n a b t) (AppSettingsG n a b t) (ReaderT (SearchEnv n a b) EventHooks (Searcher a)) (ReaderT (SearchEnv n a b) EventHooks (Searcher a)) Source #
defHooks :: EventHooks a Source #
Exposed Internals
handleKeyEvent :: KnownNat n => SearchEnv n a c -> Key -> [Modifier] -> EventM Bool (Searcher b) () Source #
Handling of keypresses. The default bindings are
Enter
exits the app with the current selection.
Esc
exits without any selection
Up
, Down
, PageUp
and PageDown
move through the matches.
All others keys are used for editing the query. See handleEditorEvent
for details.
handleSearch :: SearchEvent a -> EventM Bool (Searcher a) () Source #
searcherWidget :: (KnownNat n, KnownNat m) => SearchEnv n a (Widget Bool) -> Text -> SearcherSized m a -> Widget Bool Source #
The brick widget used to display the editor and the search result.
initialSearcher :: SearchEnv n a c -> BChan (SearchEvent a) -> SearcherSized 0 a Source #
The initial state of the searcher. The editor is empty.