test the editor
This commit is contained in:
52
app/Main.hs
52
app/Main.hs
@@ -1,6 +1,54 @@
|
||||
{-
|
||||
|
||||
Widget Test
|
||||
Copyright (C) Jonathan Lamothe <jonathan@jlamothe.net>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at
|
||||
your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
-}
|
||||
|
||||
module Main (main) where
|
||||
|
||||
import Lib
|
||||
import Brick.AttrMap (forceAttrMap)
|
||||
import Brick.Main (App (..), defaultMain, halt, showFirstCursor)
|
||||
import Brick.Types (BrickEvent (VtyEvent), EventM, Widget)
|
||||
import Brick.Util (on)
|
||||
import Brick.Widgets.Core (str, vBox)
|
||||
import Brick.Widgets.Edit (Editor, editor, handleEditorEvent, renderEditor)
|
||||
import Control.Monad (void)
|
||||
import Graphics.Vty.Attributes.Color (black, white)
|
||||
import Graphics.Vty.Input.Events (Event (EvKey), Key (KEsc))
|
||||
|
||||
app :: App (Editor String ()) () ()
|
||||
app = App
|
||||
{ appDraw = draw
|
||||
, appChooseCursor = showFirstCursor
|
||||
, appHandleEvent = eventHandler
|
||||
, appStartEvent = return ()
|
||||
, appAttrMap = const $ forceAttrMap $ white `on` black
|
||||
}
|
||||
|
||||
draw :: Editor String () -> [Widget ()]
|
||||
draw = return . renderEditor (vBox . map str) True
|
||||
|
||||
eventHandler :: BrickEvent () () -> EventM () (Editor String ()) ()
|
||||
eventHandler (VtyEvent (EvKey KEsc _)) = halt
|
||||
eventHandler e = handleEditorEvent e
|
||||
|
||||
main :: IO ()
|
||||
main = someFunc
|
||||
main = let
|
||||
s = editor () Nothing ""
|
||||
in void $ defaultMain app s
|
||||
|
||||
--jl
|
||||
|
||||
Reference in New Issue
Block a user