mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-12-01 17:32:52 +03:00
Very basic incomplete text editor experiment
This commit is contained in:
parent
4fc7813918
commit
5e91b0b617
@ -10,12 +10,13 @@ import Brick
|
||||
data St =
|
||||
St { msg :: String
|
||||
, focus :: FocusRing
|
||||
, stEditor :: Editor
|
||||
}
|
||||
|
||||
drawUI :: St -> Widget
|
||||
drawUI st =
|
||||
let editor = txt (msg st) `withNamedCursor` (Name "edit", Location (length $ msg st, 0))
|
||||
in vBox [ editor `withAttr` (cyan `on` blue)
|
||||
let ew = edit (stEditor st)
|
||||
in vBox [ ew `withAttr` (cyan `on` blue)
|
||||
, hBorder '-'
|
||||
, "stuff and things"
|
||||
]
|
||||
@ -34,8 +35,10 @@ pickCursor st ls =
|
||||
|
||||
initialState :: St
|
||||
initialState =
|
||||
let eName = Name "edit"
|
||||
St { msg = ""
|
||||
, focus = focusRing [Name "edit"]
|
||||
, focus = focusRing [eName]
|
||||
, stEditor = editor eName ""
|
||||
}
|
||||
|
||||
main :: IO ()
|
||||
|
22
src/Brick.hs
22
src/Brick.hs
@ -34,6 +34,28 @@ txt s = Widget { render = \_ _ a -> ( string a s
|
||||
instance IsString Widget where
|
||||
fromString = txt
|
||||
|
||||
data Editor =
|
||||
Editor { editStr :: String
|
||||
, editCursorPos :: Int
|
||||
, editorName :: Name
|
||||
}
|
||||
|
||||
editor :: Name -> String -> Editor
|
||||
editor name s = Editor s (length name) name
|
||||
|
||||
edit :: Editor -> Widget
|
||||
edit e =
|
||||
Widget { render = renderEditor
|
||||
}
|
||||
where
|
||||
renderEditor loc sz@(width, _) attr =
|
||||
let cursorPos = CursorLocation (Location (editCursorPos e, 0)) (Just $ editorName e)
|
||||
w = hBox [ txt (editStr e)
|
||||
, txt (replicate (width - (length $ editStr e)) ' ')
|
||||
]
|
||||
(img, _) = render_ w loc sz attr
|
||||
in (img, [cursorPos])
|
||||
|
||||
hBorder :: Char -> Widget
|
||||
hBorder ch =
|
||||
Widget { render = \_ (width, _) attr -> ( charFill attr ch width 1
|
||||
|
Loading…
Reference in New Issue
Block a user