Browse code
Allow input to be piped in
fiddlerwoaroof authored on 29/09/2015 05:14:48
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -45,7 +45,7 @@ mainLoop lim filein cols infinitep = stToIO (newSTRef 1) >>= loop |
45 | 45 |
initialize n = readSTRef n >>= incSTRef n `keepOldBinding` addSTRefToTuple n |
46 | 46 |
|
47 | 47 |
step (x,nextX) = discardResult $ do |
48 |
- let handleInputp = not infinitep && ( nextX `mod` lim == 0) |
|
48 |
+ let handleInputp = filein /= stdin && not infinitep && ( nextX `mod` lim == 0) |
|
49 | 49 |
eofp <- atEnd |
50 | 50 |
if eofp then threadDelay 100 |
51 | 51 |
else do |
... | ... |
@@ -85,10 +85,9 @@ allocate = do |
85 | 85 |
deallocate :: IO () |
86 | 86 |
deallocate = HSCurses.endWin |
87 | 87 |
|
88 |
-work :: String -> [FilePath] -> Bool -> String -> IO () |
|
89 |
-work enc run infinitep stream = do |
|
88 |
+startTask :: String -> [FilePath] -> IO (Handle,Handle) |
|
89 |
+startTask enc run = do |
|
90 | 90 |
let (runprog:myArgs) = run |
91 |
- (rows, cols) <- HSCurses.scrSize |
|
92 | 91 |
(_, Just hout, Just herr, _) <- |
93 | 92 |
createProcess (proc runprog myArgs) { |
94 | 93 |
std_out=CreatePipe, |
... | ... |
@@ -99,10 +98,23 @@ work enc run infinitep stream = do |
99 | 98 |
encoding <- mkTextEncoding enc |
100 | 99 |
hSetEncoding hout encoding |
101 | 100 |
hSetEncoding herr encoding |
101 |
+ return (hout,herr) |
|
102 |
+ |
|
103 |
+getStream :: String -> String -> [FilePath] -> IO Handle |
|
104 |
+getStream stream enc run = do |
|
105 |
+ (hout,herr) <- startTask enc run |
|
106 |
+ return $ case stream of |
|
107 |
+ "stdout" -> hout |
|
108 |
+ _ -> herr |
|
102 | 109 |
|
103 |
- case stream of |
|
104 |
- "stdout" -> mainLoop rows hout cols infinitep |
|
105 |
- _ -> mainLoop rows herr cols infinitep |
|
110 |
+ |
|
111 |
+work :: String -> [FilePath] -> Bool -> String -> IO () |
|
112 |
+work enc run infinitep stream = do |
|
113 |
+ (rows, cols) <- HSCurses.scrSize |
|
114 |
+ stream <- case run of |
|
115 |
+ [] -> return stdin |
|
116 |
+ _ -> getStream stream enc run |
|
117 |
+ mainLoop rows stream cols infinitep |
|
106 | 118 |
return () |
107 | 119 |
|
108 | 120 |
|