widgettest/app/Main.hs

55 lines
1.7 KiB
Haskell
Raw Normal View History

2023-05-20 17:25:31 -04:00
{-
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/>.
-}
2023-05-19 15:00:22 -04:00
module Main (main) where
2023-05-20 17:25:31 -04:00
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
2023-05-19 15:00:22 -04:00
main :: IO ()
2023-05-20 17:25:31 -04:00
main = let
s = editor () Nothing ""
in void $ defaultMain app s
--jl