mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-11-27 02:53:16 +03:00
EditDemo: remove list widget
This commit is contained in:
parent
1df256f4ed
commit
3b604fd5af
@ -5,7 +5,6 @@ module Main where
|
|||||||
|
|
||||||
import Lens.Micro
|
import Lens.Micro
|
||||||
import Lens.Micro.TH
|
import Lens.Micro.TH
|
||||||
import qualified Data.Vector as DV
|
|
||||||
import qualified Graphics.Vty as V
|
import qualified Graphics.Vty as V
|
||||||
|
|
||||||
import qualified Brick.Main as M
|
import qualified Brick.Main as M
|
||||||
@ -19,7 +18,6 @@ import Brick.Widgets.Core
|
|||||||
, str
|
, str
|
||||||
)
|
)
|
||||||
import qualified Brick.Widgets.Center as C
|
import qualified Brick.Widgets.Center as C
|
||||||
import qualified Brick.Widgets.List as L
|
|
||||||
import qualified Brick.Widgets.Edit as E
|
import qualified Brick.Widgets.Edit as E
|
||||||
import qualified Brick.AttrMap as A
|
import qualified Brick.AttrMap as A
|
||||||
import qualified Brick.Focus as F
|
import qualified Brick.Focus as F
|
||||||
@ -27,14 +25,12 @@ import Brick.Util (on)
|
|||||||
|
|
||||||
data Name = Edit1
|
data Name = Edit1
|
||||||
| Edit2
|
| Edit2
|
||||||
| List1
|
|
||||||
deriving (Ord, Show, Eq)
|
deriving (Ord, Show, Eq)
|
||||||
|
|
||||||
data St =
|
data St =
|
||||||
St { _focusRing :: F.FocusRing Name
|
St { _focusRing :: F.FocusRing Name
|
||||||
, _edit1 :: E.Editor Name
|
, _edit1 :: E.Editor Name
|
||||||
, _edit2 :: E.Editor Name
|
, _edit2 :: E.Editor Name
|
||||||
, _list1 :: L.List Name Int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
makeLenses ''St
|
makeLenses ''St
|
||||||
@ -42,18 +38,14 @@ makeLenses ''St
|
|||||||
drawUI :: St -> [T.Widget Name]
|
drawUI :: St -> [T.Widget Name]
|
||||||
drawUI st = [ui]
|
drawUI st = [ui]
|
||||||
where
|
where
|
||||||
theList = F.withFocusRing (st^.focusRing) (L.renderList drawElem) (st^.list1)
|
|
||||||
e1 = F.withFocusRing (st^.focusRing) E.renderEditor (st^.edit1)
|
e1 = F.withFocusRing (st^.focusRing) E.renderEditor (st^.edit1)
|
||||||
e2 = F.withFocusRing (st^.focusRing) E.renderEditor (st^.edit2)
|
e2 = F.withFocusRing (st^.focusRing) E.renderEditor (st^.edit2)
|
||||||
|
|
||||||
drawElem _ i = (str $ show i) <+> (vLimit 1 $ fill ' ')
|
|
||||||
ui = C.center $
|
ui = C.center $
|
||||||
(str "Input 1 (unlimited): " <+> (hLimit 30 $ vLimit 5 e1)) <=>
|
(str "Input 1 (unlimited): " <+> (hLimit 30 $ vLimit 5 e1)) <=>
|
||||||
str " " <=>
|
str " " <=>
|
||||||
(str "Input 2 (limited to 2 lines): " <+> (hLimit 30 e2)) <=>
|
(str "Input 2 (limited to 2 lines): " <+> (hLimit 30 e2)) <=>
|
||||||
str " " <=>
|
str " " <=>
|
||||||
(str "Input 3: " <+> (hLimit 30 $ vLimit 3 theList)) <=>
|
|
||||||
str " " <=>
|
|
||||||
str "Press Tab to switch between editors, Esc to quit."
|
str "Press Tab to switch between editors, Esc to quit."
|
||||||
|
|
||||||
appEvent :: St -> V.Event -> T.EventM Name (T.Next St)
|
appEvent :: St -> V.Event -> T.EventM Name (T.Next St)
|
||||||
@ -66,23 +58,18 @@ appEvent st ev =
|
|||||||
_ -> M.continue =<< case F.focusGetCurrent (st^.focusRing) of
|
_ -> M.continue =<< case F.focusGetCurrent (st^.focusRing) of
|
||||||
Just Edit1 -> T.handleEventLensed st edit1 E.handleEditorEvent ev
|
Just Edit1 -> T.handleEventLensed st edit1 E.handleEditorEvent ev
|
||||||
Just Edit2 -> T.handleEventLensed st edit2 E.handleEditorEvent ev
|
Just Edit2 -> T.handleEventLensed st edit2 E.handleEditorEvent ev
|
||||||
Just List1 -> T.handleEventLensed st list1 L.handleListEvent ev
|
|
||||||
Nothing -> return st
|
Nothing -> return st
|
||||||
|
|
||||||
initialState :: St
|
initialState :: St
|
||||||
initialState =
|
initialState =
|
||||||
St (F.focusRing [Edit1, Edit2, List1])
|
St (F.focusRing [Edit1, Edit2])
|
||||||
(E.editor Edit1 (str . unlines) Nothing "")
|
(E.editor Edit1 (str . unlines) Nothing "")
|
||||||
(E.editor Edit2 (str . unlines) (Just 2) "")
|
(E.editor Edit2 (str . unlines) (Just 2) "")
|
||||||
(L.list List1 (DV.fromList [1, 2, 3, 4, 5]) 1)
|
|
||||||
|
|
||||||
theMap :: A.AttrMap
|
theMap :: A.AttrMap
|
||||||
theMap = A.attrMap V.defAttr
|
theMap = A.attrMap V.defAttr
|
||||||
[ (E.editAttr, V.white `on` V.blue)
|
[ (E.editAttr, V.white `on` V.blue)
|
||||||
, (L.listSelectedAttr, V.white `on` V.blue)
|
|
||||||
|
|
||||||
, (E.editFocusedAttr, V.black `on` V.yellow)
|
, (E.editFocusedAttr, V.black `on` V.yellow)
|
||||||
, (L.listSelectedFocusedAttr, V.black `on` V.yellow)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
appCursor :: St -> [T.CursorLocation Name] -> Maybe (T.CursorLocation Name)
|
appCursor :: St -> [T.CursorLocation Name] -> Maybe (T.CursorLocation Name)
|
||||||
|
Loading…
Reference in New Issue
Block a user