test FileBrowser widget

This commit is contained in:
Jonathan Lamothe 2023-05-22 13:58:34 -04:00
parent 70afacfee8
commit 776593d853

View File

@ -20,35 +20,44 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Main (main) where
import Brick.AttrMap (forceAttrMap)
import Brick.AttrMap (AttrMap, attrMap)
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 Brick.Widgets.FileBrowser (
FileBrowser,
fileBrowserSelectedAttr,
handleFileBrowserEvent,
newFileBrowser,
renderFileBrowser)
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 (FileBrowser ()) () ()
app = App
{ appDraw = draw
, appChooseCursor = showFirstCursor
, appHandleEvent = eventHandler
, appStartEvent = return ()
, appAttrMap = const $ forceAttrMap $ white `on` black
, appAttrMap = const myAttrMap
}
draw :: Editor String () -> [Widget ()]
draw = return . renderEditor (vBox . map str) True
draw :: FileBrowser () -> [Widget ()]
draw = return . renderFileBrowser True
eventHandler :: BrickEvent () () -> EventM () (Editor String ()) ()
eventHandler :: BrickEvent () () -> EventM () (FileBrowser ()) ()
eventHandler (VtyEvent (EvKey KEsc _)) = halt
eventHandler e = handleEditorEvent e
eventHandler (VtyEvent e) = handleFileBrowserEvent e
eventHandler _ = return ()
myAttrMap :: AttrMap
myAttrMap = attrMap (white `on` black)
[ ( fileBrowserSelectedAttr , black `on` white )
]
main :: IO ()
main = let
s = editor () Nothing ""
in void $ defaultMain app s
main = void $ newFileBrowser (const True) () Nothing
>>= defaultMain app
--jl