Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module is a quick hack to enable representation of data with columns of text. We use the fact the since the candidates are supposed to fit in a line,
they can't have a newlines but text with newlines can otherwise be searched normally. We use this here to separate columns by newlines. Like in
Talash.Brick the candidates comes from vector of text. Each such text consists of a fixed number of lines each representing a column. We match against such
text and partsColumns
then uses the newlines to reconstruct the columns and the parts of the match within each column. This trick of using newline saves us
from dealing with the partial state of the match when we cross a column but there is probably a better way . The function runApp
, selected
and
selectedIndex
hide this and instead take as argument a Vector
[ErrorMessage
] with each element of the list representing a column. Each list must have the same
length. Otherwise this module provides a reduced version of the functions in Talash.Brick.
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
- _columnAttrs :: [AttrName]
- _columnLimits :: [Int]
- _themeAttrs :: [(AttrName, Attr)]
- _borderStyle :: BorderStyle
- type AppSettings n a = AppSettingsG n a Text 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 SearchFunctions a b
- data CaseSensitivity
- searchApp :: KnownNat n => AppSettings n a -> SearchEnv n a Text -> App (Searcher a) (SearchEvent a) Bool
- defSettings :: KnownNat n => AppSettings n a
- selected :: KnownNat n => AppSettings n a -> SearchFunctions a Text -> Vector [Text] -> IO (Maybe [Text])
- selectedIndex :: KnownNat n => AppSettings n a -> SearchFunctions a Text -> Vector [Text] -> IO (Maybe Int)
- runApp :: KnownNat n => AppSettings n a -> SearchFunctions a Text -> Vector [Text] -> IO (Searcher a)
- query :: forall n a b. Lens' (SearchEnv n a b) (MVar (Maybe Text))
- prevQuery :: forall n a a. Lens (SearchStateSized n a) (SearchStateSized n a) Text Text
- 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
- searchFunctions :: forall n a b b. Lens (SearchEnv n a b) (SearchEnv n a b) (SearchFunctions a b) (SearchFunctions a b)
- candidates :: forall n a b. Lens' (SearchEnv n a b) (Chunks n)
- eventSource :: forall n a. Lens' (SearcherSized n a) (BChan (SearchEvent a))
- 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))
- 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) => AppTheme -> SearchEnv n a Text -> SearcherSized m a -> Widget Bool
- initialSearcher :: SearchEnv n a c -> BChan (SearchEvent a) -> SearcherSized 0 a
- partsColumns :: [Text] -> [[Text]]
- runApp' :: KnownNat n => AppSettings n a -> SearchFunctions a Text -> Chunks n -> IO (Searcher a)
- selected' :: KnownNat n => AppSettings n a -> SearchFunctions a Text -> Chunks n -> IO (Maybe [Text])
- selectedIndex' :: KnownNat n => AppSettings n a -> SearchFunctions a Text -> Vector Text -> IO (Maybe Int)
Documentation
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 Text AppTheme Source #
data AppSettingsG (n :: Nat) a b t Source #
AppSettings | |
|
data SearchFunctions a b Source #
data CaseSensitivity #
Instances
The Brick App and Helpers
searchApp :: KnownNat n => AppSettings n a -> SearchEnv n a Text -> 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.
selected :: KnownNat n => AppSettings n a -> SearchFunctions a Text -> Vector [Text] -> IO (Maybe [Text]) Source #
Run app and return the the selection if there is one else Nothing.
selectedIndex :: KnownNat n => AppSettings n a -> SearchFunctions a Text -> Vector [Text] -> IO (Maybe Int) Source #
Returns the index of selected candidate in the vector of candidates. Note: it uses elemIndex
which is O(N).
runApp :: KnownNat n => AppSettings n a -> SearchFunctions a Text -> Vector [Text] -> IO (Searcher a) Source #
Lenses
Searcher
prevQuery :: forall n a a. Lens (SearchStateSized n a) (SearchStateSized n a) Text Text Source #
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
searchFunctions :: forall n a b b. Lens (SearchEnv n a b) (SearchEnv n a b) (SearchFunctions a b) (SearchFunctions a b) Source #
eventSource :: forall n a. Lens' (SearcherSized n a) (BChan (SearchEvent a)) 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 #
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) => AppTheme -> SearchEnv n a 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.
partsColumns :: [Text] -> [[Text]] Source #
This function reconstructs the columns from the parts returned by the search by finding the newlines.
runApp' :: KnownNat n => AppSettings n a -> SearchFunctions a Text -> Chunks n -> IO (Searcher a) Source #
The 'raw' version of runApp
taking a vector of text with columns separated by newlines.
selected' :: KnownNat n => AppSettings n a -> SearchFunctions a Text -> Chunks n -> IO (Maybe [Text]) Source #
The 'raw' version of selected
taking a vector of text with columns separated by newlines.
selectedIndex' :: KnownNat n => AppSettings n a -> SearchFunctions a Text -> Vector Text -> IO (Maybe Int) Source #
The 'raw' version of selectedIndex
taking a vector of text with columns separated by newlines.