@@ -4,8 +4,10 @@ module Graphics.Vty.Input ( Key(..)
4 , Modifier(..)
4 , Modifier(..)
5 , Button(..)
5 , Button(..)
6 , Event(..)
6 , Event(..)
7− , initTermInput
7+ , Input(..)
8 , defaultEscDelay
8 , defaultEscDelay
9+ , input_for_current_terminal
10+ , input_for_name_and_io
@@ -15,11 +17,12 @@ import Graphics.Vty.Input.Terminfo
16import Control.Concurrent
18import Control.Concurrent
18−import System.Console.Terminfo
20+import qualified System.Console.Terminfo as Terminfo
19−
21+import System.Environment
20import System.Posix.Signals.Exts
22import System.Posix.Signals.Exts
21import System.Posix.Terminal
23import System.Posix.Terminal
22import System.Posix.IO (stdInput)
24import System.Posix.IO (stdInput)
25+import System.Posix.Types (Fd)
24-- Right, I'm mostly guessing on these details. So, as far as I can figure:
27-- Right, I'm mostly guessing on these details. So, as far as I can figure:
@@ -45,6 +48,13 @@ import System.Posix.IO (stdInput)
45defaultEscDelay :: Int
48defaultEscDelay :: Int
46defaultEscDelay = 10000
49defaultEscDelay = 10000
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
48-- | Set up the terminal for input. Returns a function which reads key
58-- | Set up the terminal for input. Returns a function which reads key
49-- events, and a function for shutting down the terminal access.
59-- events, and a function for shutting down the terminal access.
@@ -71,26 +81,29 @@ defaultEscDelay = 10000
71-- * IEXTEN disabled
81-- * IEXTEN disabled
72-- - extended functions are disabled. Uh. Whatever these are.
82-- - extended functions are disabled. Uh. Whatever these are.
74−initTermInput :: Int -> Terminal -> IO (IO Event, IO ())
84+input_for_name_and_io :: Int -> String -> Fd -> IO Input
75−initTermInput escDelay terminal = do
85+input_for_name_and_io escDelay term_name term_in = do
86+ terminal <- Terminfo.setupTerm term_name
76− attr <- getTerminalAttributes stdInput
87+ attr <- getTerminalAttributes term_in
77 let attr' = foldl withoutMode attr [ StartStopOutput, KeyboardInterrupts
88 let attr' = foldl withoutMode attr [ StartStopOutput, KeyboardInterrupts
78 , EnableEcho, ProcessInput, ExtendedFunctions
89 , EnableEcho, ProcessInput, ExtendedFunctions
80− setTerminalAttributes stdInput attr' Immediately
91+ setTerminalAttributes term_in attr' Immediately
92+ -- TODO: pass Fd to set_term_timing
81 set_term_timing
93 set_term_timing
82 let classify_table = classify_table_for_term terminal
94 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
84 let pokeIO = Catch $ do
96 let pokeIO = Catch $ do
85 let e = error "(getsize in input layer)"
97 let e = error "(getsize in input layer)"
86− setTerminalAttributes stdInput attr' Immediately
98+ setTerminalAttributes term_in attr' Immediately
87 writeChan eventChannel (EvResize e e)
99 writeChan eventChannel (EvResize e e)
88 _ <- installHandler windowChange pokeIO Nothing
100 _ <- installHandler windowChange pokeIO Nothing
89 _ <- installHandler continueProcess pokeIO Nothing
101 _ <- installHandler continueProcess pokeIO Nothing
103+ { event_channel = eventChannel
90− let shutdown_input' = do
104+ , shutdown_input = do
91− shutdown_input
105+ shutdown_event_processing
92 _ <- installHandler windowChange Ignore Nothing
106 _ <- installHandler windowChange Ignore Nothing
93 _ <- installHandler continueProcess Ignore Nothing
107 _ <- installHandler continueProcess Ignore Nothing
94− setTerminalAttributes stdInput attr Immediately
108+ setTerminalAttributes term_in attr Immediately
95− return (readChan eventChannel, shutdown_input')
109+ }