vty/demos/ModeDemo.hs
Jonathan Daugherty 4362b3cb1c Add Graphics.Vty.Config.getTtyEraseChar
This commit adds getTtyEraseChar. This function queries the kernel
for the current terminal's settings to obtain the character assigned
by the "stty erase" command. The "erase" character indicates which
input character the terminal should interpret to mean "backspace" when
the terminal is in canonical input mode. Vty applications run with
canonical mode disabled, but even in those cases some users may want
their "stty erase" setting honored by Vty's input-handling so that
incoming erase characters (according to stty) result in "KBS" key events
being delivered to the application.
2020-02-27 09:46:04 -08:00

56 lines
1.9 KiB
Haskell

module Main where
import Control.Applicative
import Data.Monoid
import Foreign.C.Types (CInt(..), CChar(..))
import System.Posix.Types (Fd(..))
import Graphics.Vty
mkUI :: (Bool, Bool, Bool, Bool) -> Maybe Event -> Image
mkUI (m, ms, p, ps) e =
vertCat [ string defAttr $ "Mouse mode supported: " <> show m
, string defAttr $ "Mouse mode status: " <> show ms
, string defAttr " "
, string defAttr $ "Paste mode supported: " <> show p
, string defAttr $ "Paste mode status: " <> show ps
, string defAttr " "
, string defAttr $ "Last event: " <> show e
, string defAttr " "
, string defAttr "Press 'm' to toggle mouse mode, 'p' to toggle paste mode, and 'q' to quit."
]
main :: IO ()
main = do
cfg <- standardIOConfig
vty <- mkVty cfg
let renderUI lastE = do
let output = outputIface vty
info <- (,,,) <$> (pure $ supportsMode output Mouse)
<*> getModeStatus output Mouse
<*> (pure $ supportsMode output BracketedPaste)
<*> getModeStatus output BracketedPaste
return $ picForImage $ mkUI info lastE
let go lastE = do
pic <- renderUI lastE
update vty pic
e <- nextEvent vty
case e of
EvKey (KChar 'q') [] -> return ()
EvKey (KChar 'm') [] -> do
let output = outputIface vty
enabled <- getModeStatus output Mouse
setMode output Mouse (not enabled)
go (Just e)
EvKey (KChar 'p') [] -> do
let output = outputIface vty
enabled <- getModeStatus output BracketedPaste
setMode output BracketedPaste (not enabled)
go (Just e)
_ -> go (Just e)
go Nothing
shutdown vty