widgettest/app/Main.hs

64 lines
1.8 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-22 13:58:34 -04:00
import Brick.AttrMap (AttrMap, attrMap)
2023-05-20 17:25:31 -04:00
import Brick.Main (App (..), defaultMain, halt, showFirstCursor)
import Brick.Types (BrickEvent (VtyEvent), EventM, Widget)
import Brick.Util (on)
2023-05-22 13:58:34 -04:00
import Brick.Widgets.FileBrowser (
FileBrowser,
fileBrowserSelectedAttr,
handleFileBrowserEvent,
newFileBrowser,
renderFileBrowser)
2023-05-20 17:25:31 -04:00
import Control.Monad (void)
import Graphics.Vty.Attributes.Color (black, white)
import Graphics.Vty.Input.Events (Event (EvKey), Key (KEsc))
2023-05-22 13:58:34 -04:00
app :: App (FileBrowser ()) () ()
2023-05-20 17:25:31 -04:00
app = App
{ appDraw = draw
, appChooseCursor = showFirstCursor
, appHandleEvent = eventHandler
, appStartEvent = return ()
2023-05-22 13:58:34 -04:00
, appAttrMap = const myAttrMap
2023-05-20 17:25:31 -04:00
}
2023-05-22 13:58:34 -04:00
draw :: FileBrowser () -> [Widget ()]
draw = return . renderFileBrowser True
2023-05-20 17:25:31 -04:00
2023-05-22 13:58:34 -04:00
eventHandler :: BrickEvent () () -> EventM () (FileBrowser ()) ()
2023-05-20 17:25:31 -04:00
eventHandler (VtyEvent (EvKey KEsc _)) = halt
2023-05-22 13:58:34 -04:00
eventHandler (VtyEvent e) = handleFileBrowserEvent e
eventHandler _ = return ()
myAttrMap :: AttrMap
myAttrMap = attrMap (white `on` black)
[ ( fileBrowserSelectedAttr , black `on` white )
]
2023-05-19 15:00:22 -04:00
main :: IO ()
2023-05-22 13:58:34 -04:00
main = void $ newFileBrowser (const True) () Nothing
>>= defaultMain app
2023-05-20 17:25:31 -04:00
--jl