56 lines
1.6 KiB
Haskell
56 lines
1.6 KiB
Haskell
module Widgets where
|
|
|
|
import Brick
|
|
import Brick.Main
|
|
import Brick.Widgets.Center
|
|
import Brick.AttrMap (attrMap)
|
|
import Graphics.Vty (defAttr)
|
|
import Graphics.Vty.Input.Events
|
|
import Control.Monad.IO.Class (liftIO)
|
|
import qualified Data.Text as T
|
|
import Lens.Micro
|
|
|
|
import JSONTypes
|
|
import Request
|
|
import Misc
|
|
import AppTypes
|
|
|
|
widgetCons :: JSONMovie -> (Widget Ident, Int, AppS) -> (Widget Ident, Int, AppS)
|
|
widgetCons m (w, i, s) =
|
|
if s ^. appCursor == i
|
|
then embed . visible . select $
|
|
if s ^. appExpanded
|
|
then expandedWidget s m i
|
|
else movieWidget s m i
|
|
else embed (movieWidget s m i)
|
|
where
|
|
embed x = (w <=> x, i+1, s)
|
|
select = (withAttr (attrName "selected"))
|
|
|
|
|
|
movieWidgets :: AppS -> JSONListMovies -> Widget Ident
|
|
movieWidgets s m = let (items, _, _) = foldr widgetCons (emptyWidget, 0, s) (movies m)
|
|
in items
|
|
|
|
movieWidget :: AppS -> JSONMovie -> Int -> Widget Ident
|
|
movieWidget s m i = txt (movie_title m) <+> padLeft Max (str (show (movie_year m)))
|
|
|
|
expandedWidget :: AppS -> JSONMovie -> Int -> Widget Ident
|
|
expandedWidget s m i = movieWidget s m i <=> txtWrap (movie_summary m)
|
|
|
|
searchWidget :: AppS -> Widget Ident
|
|
searchWidget = undefined
|
|
|
|
browseWidget :: AppS -> Widget Ident
|
|
browseWidget s =
|
|
case (s ^. appListing) of
|
|
Nothing -> center $ str "No movies found matching query."
|
|
(Just m) -> headings <=> (viewport Listing Vertical (movieWidgets s m))
|
|
where headings = str "Title" <+> padLeft Max (str "Year")
|
|
|
|
errorWidget :: AppS -> Widget Ident
|
|
errorWidget s = center $
|
|
case (s ^. appError) of
|
|
Nothing -> str "Unknown Error."
|
|
(Just e) -> str e
|