test the editor

This commit is contained in:
Jonathan Lamothe 2023-05-20 17:25:31 -04:00
parent 9b4d4819ff
commit 70afacfee8
3 changed files with 54 additions and 2 deletions

View File

@ -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

View File

@ -21,6 +21,7 @@ description: Please see the README.md file
dependencies:
- base >= 4.7 && < 5
- brick >= 1.4 && < 1.5
- vty >= 5.37 && < 5.38
ghc-options:
- -Wall

View File

@ -30,6 +30,7 @@ library
build-depends:
base >=4.7 && <5
, brick ==1.4.*
, vty ==5.37.*
default-language: Haskell2010
executable widgettest
@ -44,6 +45,7 @@ executable widgettest
build-depends:
base >=4.7 && <5
, brick ==1.4.*
, vty ==5.37.*
, widgettest
default-language: Haskell2010
@ -60,5 +62,6 @@ test-suite widgettest-test
build-depends:
base >=4.7 && <5
, brick ==1.4.*
, vty ==5.37.*
, widgettest
default-language: Haskell2010