@@ -4,8 +4,10 @@ module Graphics.Vty.Input ( Key(..)
44 , Modifier(..)
55 , Button(..)
66 , Event(..)
7− , initTermInput
7+ , Input(..)
88 , defaultEscDelay
9+ , input_for_current_terminal
10+ , input_for_name_and_io
911 )
1012 where
1113
@@ -15,11 +17,12 @@ import Graphics.Vty.Input.Terminfo
1517
1618import Control.Concurrent
1719
18−import System.Console.Terminfo
19−
20+import qualified System.Console.Terminfo as Terminfo
21+import System.Environment
2022import System.Posix.Signals.Exts
2123import System.Posix.Terminal
2224import System.Posix.IO (stdInput)
25+import System.Posix.Types (Fd)
2326
2427-- Right, I'm mostly guessing on these details. So, as far as I can figure:
2528--
@@ -45,6 +48,13 @@ import System.Posix.IO (stdInput)
4548defaultEscDelay :: Int
4649defaultEscDelay = 10000
4750
51+-- | Set up the current terminal for input.
52+-- This determines the current terminal then invokes 'input_for_name_and_io'
53+input_for_current_terminal :: Int -> IO Input
54+input_for_current_terminal escDelay = do
55+ term_name <- getEnv "TERM"
56+ input_for_name_and_io escDelay term_name stdInput
57+
4858-- | Set up the terminal for input. Returns a function which reads key
4959-- events, and a function for shutting down the terminal access.
5060--
@@ -71,26 +81,29 @@ defaultEscDelay = 10000
7181-- * IEXTEN disabled
7282-- - extended functions are disabled. Uh. Whatever these are.
7383--
74−initTermInput :: Int -> Terminal -> IO (IO Event, IO ())
75−initTermInput escDelay terminal = do
76− attr <- getTerminalAttributes stdInput
84+input_for_name_and_io :: Int -> String -> Fd -> IO Input
85+input_for_name_and_io escDelay term_name term_in = do
86+ terminal <- Terminfo.setupTerm term_name
87+ attr <- getTerminalAttributes term_in
7788 let attr' = foldl withoutMode attr [ StartStopOutput, KeyboardInterrupts
7889 , EnableEcho, ProcessInput, ExtendedFunctions
7990 ]
80− setTerminalAttributes stdInput attr' Immediately
91+ setTerminalAttributes term_in attr' Immediately
92+ -- TODO: pass Fd to set_term_timing
8193 set_term_timing
8294 let classify_table = classify_table_for_term terminal
83− (eventChannel, shutdown_input) <- initInputForFd escDelay classify_table stdInput
95+ (eventChannel, shutdown_event_processing) <- initInputForFd escDelay classify_table term_in
8496 let pokeIO = Catch $ do
8597 let e = error "(getsize in input layer)"
86− setTerminalAttributes stdInput attr' Immediately
98+ setTerminalAttributes term_in attr' Immediately
8799 writeChan eventChannel (EvResize e e)
88100 _ <- installHandler windowChange pokeIO Nothing
89101 _ <- installHandler continueProcess pokeIO Nothing
90− let shutdown_input' = do
91− shutdown_input
102+ return $ Input
103+ { event_channel = eventChannel
104+ , shutdown_input = do
105+ shutdown_event_processing
92106 _ <- installHandler windowChange Ignore Nothing
93107 _ <- installHandler continueProcess Ignore Nothing
94− setTerminalAttributes stdInput attr Immediately
95− return (readChan eventChannel, shutdown_input')
96−
108+ setTerminalAttributes term_in attr Immediately
109+ }