mirror of
https://github.com/jtdaugherty/brick.git
synced 2025-01-08 15:08:46 +03:00
Code cleanup and rename WithState to With
This commit is contained in:
parent
af99a58e23
commit
4b0e192a90
@ -30,11 +30,11 @@ drawUI _ = [a]
|
||||
a = centered $
|
||||
bordered $
|
||||
(VLimit 1 $ HLimit 25 $ UseAttr (cyan `on` blue) $
|
||||
WithState stEditor drawEditor)
|
||||
With stEditor drawEditor)
|
||||
<<=
|
||||
HFill '-'
|
||||
=>>
|
||||
(VLimit 10 $ HLimit 25 $ WithState stList drawList)
|
||||
(VLimit 10 $ HLimit 25 $ With stList drawList)
|
||||
|
||||
appEvent :: Event -> St -> IO St
|
||||
appEvent e st =
|
||||
|
@ -13,8 +13,6 @@ module Brick.Main
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Applicative ((<$>))
|
||||
import Control.Arrow ((>>>))
|
||||
import Control.Exception (finally)
|
||||
import Control.Monad (when, forever)
|
||||
import Control.Concurrent (forkIO, Chan, newChan, readChan, writeChan)
|
||||
@ -22,7 +20,6 @@ import Data.Default
|
||||
import Data.Maybe (listToMaybe)
|
||||
import Graphics.Vty
|
||||
( Vty
|
||||
, DisplayRegion
|
||||
, Picture(..)
|
||||
, Cursor(..)
|
||||
, Event(..)
|
||||
@ -36,7 +33,7 @@ import Graphics.Vty
|
||||
|
||||
import Brick.Prim (Prim)
|
||||
import Brick.Prim.Internal (renderFinal)
|
||||
import Brick.Core (Name(..), Location(..), CursorLocation(..))
|
||||
import Brick.Core (Location(..), CursorLocation(..))
|
||||
|
||||
data App a e =
|
||||
App { appDraw :: a -> [Prim a]
|
||||
|
@ -38,7 +38,7 @@ data Prim a = Txt !String
|
||||
| SetSize (DisplayRegion -> a -> a) !(Prim a)
|
||||
| HRelease !(Prim a)
|
||||
| VRelease !(Prim a)
|
||||
| forall b. WithState (Lens' a b) (b -> Prim b)
|
||||
| forall b. With (Lens' a b) (b -> Prim b)
|
||||
|
||||
instance IsString (Prim a) where
|
||||
fromString = Txt
|
||||
|
@ -52,13 +52,13 @@ unrestricted :: Int
|
||||
unrestricted = 1000
|
||||
|
||||
render :: DisplayRegion -> Attr -> Prim a -> State a Render
|
||||
render sz a (WithState getter f) = do
|
||||
render sz a (With target f) = do
|
||||
outerState <- get
|
||||
|
||||
let innerPrim = f oldInnerState
|
||||
oldInnerState = outerState^.getter
|
||||
oldInnerState = outerState^.target
|
||||
(innerRender, newInnerState) = runState (render sz a innerPrim) oldInnerState
|
||||
modify $ \s -> s & getter .~ newInnerState
|
||||
modify $ \s -> s & target .~ newInnerState
|
||||
return innerRender
|
||||
render (w, h) a (Txt s) =
|
||||
return $ if w > 0 && h > 0
|
||||
|
Loading…
Reference in New Issue
Block a user