Skip to content

Commit a85251d

Browse files
committed
(chore): rename a few variables in IO.hs
Kind of a Nit.
1 parent b54c98d commit a85251d

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

lib/NOM/IO.hs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module NOM.IO (interact, processTextStream, StreamParser, Stream, Window, Output) where
1+
module NOM.IO (interact, mainIOLoop, StreamParser, Stream, Window, Output) where
22

33
import Control.Concurrent (threadDelay)
44
import Control.Concurrent.Async (Concurrently (Concurrently, runConcurrently))
@@ -201,7 +201,7 @@ interact ::
201201
state ->
202202
IO state
203203
interact config parser updater maintenance printer finalize input_stream output_handle initialState =
204-
processTextStream config parser updater maintenance (Just (printer, output_handle)) finalize initialState input_stream
204+
mainIOLoop config parser updater maintenance (Just (printer, output_handle)) finalize initialState input_stream
205205

206206
-- frame durations are passed to threadDelay and thus are given in microseconds
207207

@@ -223,7 +223,7 @@ getKey = reverse <$> getKey' ""
223223
more <- System.IO.hReady stdin
224224
(if more then getKey' else return) (char : chars)
225225

226-
processTextStream ::
226+
mainIOLoop ::
227227
forall update state.
228228
Config ->
229229
StreamParser update ->
@@ -234,24 +234,23 @@ processTextStream ::
234234
state ->
235235
Stream (Either NOMError ByteString) ->
236236
IO state
237-
processTextStream config parser updater maintenance printerMay finalize initialState inputStream = do
237+
mainIOLoop config parser updater maintenance printerMay finalize initialState inputStream = do
238238
state_var <- newTMVarIO initialState
239239
print_state_var <- newTMVarIO initPrintState
240-
input_received <- newEmptyTMVarIO
240+
new_user_input <- newEmptyTMVarIO
241241
output_builder_var <- newTVarIO []
242242
refresh_display_var <- newTVarIO False
243-
let keepProcessing :: IO ()
244-
keepProcessing =
243+
let keepProcessingNixCmd :: IO ()
244+
keepProcessingNixCmd =
245245
inputStream
246246
& Stream.tap (errorsToBuilderFold output_builder_var)
247247
& Stream.mapMaybe rightToMaybe
248248
& parser
249249
& Stream.fold (Fold.drainMapM (runUpdate output_builder_var state_var refresh_display_var updater))
250250
waitForInput :: IO ()
251251
waitForInput = atomically $ check =<< readTVar refresh_display_var
252-
printerMay & maybe keepProcessing \(printer, output_handle) -> do
253-
linesVar <- newTVarIO 0
254-
let keepProcessingStdin :: IO ()
252+
printerMay & maybe keepProcessingNixCmd \(printer, output_handle) -> do
253+
printedLinesVar <- newTVarIO 0
255254
let toggleHelp :: IO () = atomically $ do
256255
print_state <- readTMVar print_state_var
257256
writeTMVar print_state_var $ print_state{printHelp = not print_state.printHelp}
@@ -285,13 +284,15 @@ processTextStream config parser updater maintenance printerMay finalize initialS
285284
_ -> writeStateToScreen (not config.silent) printedLinesVar state_var print_state_var output_builder_var refresh_display_var maintenance printer output_handle
286285
keepPrinting :: IO ()
287286
keepPrinting = forever do
287+
-- Wait for either a Nix new input, the max frame duration (to update the timestamp), or a new input from the user.
288288
runConcurrently
289289
$ (Concurrently (threadDelay minFrameDuration) *> Concurrently waitForInput)
290290
<|> Concurrently (threadDelay maxFrameDuration)
291-
<|> Concurrently (atomically $ takeTMVar input_received)
291+
<|> Concurrently (atomically $ takeTMVar new_user_input)
292292
writeToScreen
293+
-- Actual main loop.
293294
runConcurrently
294-
$ Concurrently keepProcessing
295+
$ Concurrently keepProcessingNixCmd
295296
<|> Concurrently keepProcessingStdin
296297
<|> Concurrently keepPrinting
297298
atomically (takeTMVar state_var) >>= execStateT finalize >>= atomically . putTMVar state_var

test/Golden.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Data.ByteString.Char8 qualified as ByteString
55
import Data.Text qualified as Text
66
import NOM.Builds (parseStorePath)
77
import NOM.Error (NOMError)
8-
import NOM.IO (processTextStream)
8+
import NOM.IO (mainIOLoop)
99
import NOM.IO.Input (NOMInput (..), UpdateResult (..))
1010
import NOM.IO.Input.JSON ()
1111
import NOM.IO.Input.OldStyle (OldStyleInput)
@@ -100,7 +100,7 @@ testBuild name config asserts =
100100
testProcess :: forall input. (NOMInput input) => Stream.Stream IO ByteString -> IO NOMV1State
101101
testProcess input = withParser @input \streamParser -> do
102102
first_state <- firstState @input <$> initalStateFromBuildPlatform (Just "x86_64-linux")
103-
end_state <- processTextStream @input @(UpdaterState input) (MkConfig False False) streamParser stateUpdater (\now -> nomState @input %~ maintainState now) Nothing (finalizer @input) first_state (Right <$> input)
103+
end_state <- mainIOLoop @input @(UpdaterState input) (MkConfig False False) streamParser stateUpdater (\now -> nomState @input %~ maintainState now) Nothing (finalizer @input) first_state (Right <$> input)
104104
pure (end_state ^. nomState @input)
105105

106106
stateUpdater :: forall input m. (NOMInput input, UpdateMonad m) => input -> StateT (UpdaterState input) m ([NOMError], ByteString, Bool)

0 commit comments

Comments
 (0)