simple text editor using the bricks library
This commit is contained in:
parent
c9200c190d
commit
9fed792c40
1 changed files with 35 additions and 0 deletions
35
editor.hs
Normal file
35
editor.hs
Normal file
|
@ -0,0 +1,35 @@
|
|||
import Brick
|
||||
import qualified Brick.Widgets.Edit as E
|
||||
import qualified Graphics.Vty as V
|
||||
|
||||
data Name = Text deriving (Ord, Show, Eq)
|
||||
type St = E.Editor Name
|
||||
|
||||
initialState :: St
|
||||
initialState = E.editor Text (str . unlines) Nothing ""
|
||||
|
||||
drawUI :: St -> [Widget Name]
|
||||
drawUI st = [E.renderEditor True st]
|
||||
|
||||
appCursor :: St -> [CursorLocation Name] -> Maybe (CursorLocation Name)
|
||||
appCursor st c = Just (head c)
|
||||
|
||||
appEvent :: St -> V.Event -> EventM Name (Next St)
|
||||
appEvent st ev =
|
||||
case ev of
|
||||
V.EvKey V.KEsc [] -> halt st
|
||||
_ -> continue =<< E.handleEditorEvent ev st
|
||||
|
||||
theApp :: App St V.Event Name
|
||||
theApp =
|
||||
App { appDraw = drawUI
|
||||
, appChooseCursor = appCursor
|
||||
, appHandleEvent = appEvent
|
||||
, appStartEvent = return
|
||||
, appAttrMap = const (attrMap V.defAttr [ ])
|
||||
, appLiftVtyEvent = id
|
||||
}
|
||||
|
||||
main = do
|
||||
st <- defaultMain theApp initialState
|
||||
putStrLn $ unlines $ E.getEditContents $ st
|
Loading…
Reference in a new issue