Skip to content

Commit 5d3d3a2

Browse files
committed
Allow uinput-echo to end gracefully when input ends
1 parent a014ea8 commit 5d3d3a2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

evdev-examples/uinput/Main.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
module Main (main) where
22

3+
import Control.Exception
34
import Control.Monad
45
import Data.Maybe (mapMaybe)
6+
import System.Exit
7+
import System.IO.Error
58

69
import qualified Evdev.Codes as Codes
710
import Evdev.Uinput
@@ -13,7 +16,11 @@ main = do
1316
"haskell-uinput-echo-example"
1417
defaultDeviceOpts{keys = mapMaybe charToEvent (['a' .. 'z'] ++ ['0' .. '9'])}
1518
forever do
16-
cs <- getLine
19+
cs <-
20+
catchJust
21+
(guard . isEOFError)
22+
getLine
23+
\() -> exitSuccess
1724
writeBatch dev [KeyEvent k a | Just k <- map charToEvent cs, a <- [Pressed, Released]]
1825

1926
charToEvent :: Char -> Maybe Codes.Key

0 commit comments

Comments
 (0)