load file with cmd argument and save with ctrl-s
This commit is contained in:
parent
80b83098cb
commit
b52d5c237f
1 changed files with 22 additions and 10 deletions
32
editor.hs
32
editor.hs
|
@ -4,9 +4,14 @@ import Data.Maybe
|
|||
import Data.Monoid
|
||||
import Data.List
|
||||
import Data.Tuple
|
||||
import Data.Default
|
||||
import Data.Text (pack, singleton, unpack)
|
||||
import Data.Text.Markup
|
||||
import Control.Monad
|
||||
import Control.Monad.IO.Class
|
||||
import Control.Concurrent
|
||||
import Control.DeepSeq
|
||||
import System.Environment
|
||||
import qualified Brick.Widgets.Edit as E
|
||||
import qualified Graphics.Vty as V
|
||||
|
||||
|
@ -18,8 +23,8 @@ type St = E.Editor Name
|
|||
|
||||
brackets = [('(',')'),('[',']'),('{','}')]
|
||||
|
||||
initialState :: St
|
||||
initialState = E.editor Text drawContent Nothing ""
|
||||
initialState :: String -> St
|
||||
initialState = E.editor Text drawContent Nothing
|
||||
|
||||
drawContent :: [String] -> Widget n
|
||||
drawContent = markup . (createMarkup []) . unlinesWA
|
||||
|
@ -57,22 +62,29 @@ 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 =
|
||||
appEvent :: String -> St -> V.Event -> EventM Name (Next St)
|
||||
appEvent s st ev =
|
||||
case ev of
|
||||
V.EvKey V.KEsc [] -> halt st
|
||||
V.EvKey (V.KChar 'c') [V.MCtrl] -> halt st
|
||||
V.EvKey (V.KChar 's') [V.MCtrl] -> liftIO (writeFile s (unlines $ E.getEditContents $ st)) >> continue st
|
||||
_ -> continue =<< E.handleEditorEvent ev st
|
||||
|
||||
theApp :: App St V.Event Name
|
||||
theApp =
|
||||
theApp :: String -> App St V.Event Name
|
||||
theApp s =
|
||||
App { appDraw = drawUI
|
||||
, appChooseCursor = appCursor
|
||||
, appHandleEvent = appEvent
|
||||
, appChooseCursor = showFirstCursor
|
||||
, appHandleEvent = appEvent s
|
||||
, appStartEvent = return
|
||||
, appAttrMap = const (attrMap V.defAttr [ ])
|
||||
, appLiftVtyEvent = id
|
||||
}
|
||||
|
||||
main = do
|
||||
st <- defaultMain theApp initialState
|
||||
putStrLn $ unlines $ E.getEditContents $ st
|
||||
f <- do
|
||||
a <- getArgs
|
||||
return $ head a
|
||||
c <- readFile f
|
||||
st <- defaultMain (theApp f) (initialState c)
|
||||
void $ return st
|
||||
-- putStrLn $ unlines $ E.getEditContents $ st
|
||||
|
|
Loading…
Reference in a new issue