Skip to content

Commit 21562df

Browse files
committed
Freeze/help user triggered features
When the user presses h or ?, we print a short usage/help text listing the interactive key bindings. When the user presses f, we freeze the output text. I personally use this to copy/paste stuff from the terminal output, that's quite convenient. There's no visual feedback showing the output text is paused at the moment. This might be a UX footgun ><
1 parent d085cce commit 21562df

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

lib/NOM/IO.hs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ processTextStream config parser updater maintenance printerMay finalize initialS
252252
printerMay & maybe keepProcessing \(printer, output_handle) -> do
253253
linesVar <- newTVarIO 0
254254
let keepProcessingStdin :: IO ()
255+
let toggleHelp :: IO () = atomically $ do
256+
print_state <- readTMVar print_state_var
257+
writeTMVar print_state_var $ print_state{printHelp = not print_state.printHelp}
258+
writeTMVar new_user_input ()
255259
keepProcessingStdin = forever $ do
256260
key <- getKey
257261
case key of
@@ -260,15 +264,21 @@ processTextStream config parser updater maintenance printerMay finalize initialS
260264
print_state <- readTMVar print_state_var
261265
let print_state_style = if print_state.printName == PrintName then PrintDerivationPath else PrintName
262266
writeTMVar print_state_var $ print_state{printName = print_state_style}
263-
writeTMVar input_received ()
264-
"?" -> do
267+
writeTMVar new_user_input ()
268+
"?" -> toggleHelp
269+
"h" -> toggleHelp
270+
"f" -> do
265271
atomically $ do
266-
print_state <- takeTMVar print_state_var
267-
putTMVar print_state_var $ print_state{printHelp = True}
268-
writeTMVar input_received ()
272+
print_state <- readTMVar print_state_var
273+
writeTMVar print_state_var $ print_state{freeze = not print_state.freeze}
274+
writeTMVar new_user_input ()
269275
_ -> pure ()
270276
writeToScreen :: IO ()
271-
writeToScreen = writeStateToScreen (not config.silent) linesVar state_var print_state_var output_builder_var refresh_display_var maintenance printer output_handle
277+
writeToScreen = do
278+
print_state <- atomically $ readTMVar print_state_var
279+
case (print_state.freeze, print_state.printHelp) of
280+
(True, _) -> pure () -- Freezing the output, do not print anything.
281+
_ -> writeStateToScreen (not config.silent) printedLinesVar state_var print_state_var output_builder_var refresh_display_var maintenance printer output_handle
272282
keepPrinting :: IO ()
273283
keepPrinting = forever do
274284
runConcurrently

lib/NOM/Print.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module NOM.Print (stateToText, showCode, Config (..)) where
1+
module NOM.Print (stateToText, showCode, helpString, Config (..)) where
22

33
import Data.Foldable qualified as Unsafe
44
import Data.IntMap.Strict qualified as IntMap
@@ -184,7 +184,7 @@ stateToText config buildState@MkNOMV1State{..} printState = memo printWithSize .
184184
horizontal
185185
(vertical <> " ")
186186
(vertical <> " ")
187-
(printBuilds buildState printState hostNums maxHeight now)
187+
(if not printState.printHelp then printBuilds buildState printState hostNums maxHeight now else helpString)
188188
errorDisplay = printErrors nixErrors maxHeight
189189
traceDisplay = printTraces nixTraces maxHeight
190190
-- evalMessage = case evaluationState.lastFileName of
@@ -197,6 +197,7 @@ stateToText config buildState@MkNOMV1State{..} printState = memo printWithSize .
197197
MkDependencySummary{..} = fullSummary
198198
runningBuilds' = (.host) <$> runningBuilds
199199
completedBuilds' = (.host) <$> completedBuilds
200+
200201
failedBuilds' = (.host) <$> failedBuilds
201202
numFailedBuilds = CMap.size failedBuilds
202203
table time' =
@@ -588,3 +589,12 @@ printDuration diff
588589

589590
timeDiffSeconds :: Int -> Text
590591
timeDiffSeconds = printDuration . fromIntegral
592+
593+
helpString :: NonEmpty Text
594+
helpString =
595+
fromList
596+
[ markup bold " Key Bindings"
597+
, "n: toggle derivation name/derivation path print"
598+
, "f: toggle screen freeze"
599+
, "? or h: toggle help view"
600+
]

lib/NOM/State.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ data PrintNameStyle = PrintName | PrintDerivationPath deriving stock (Show, Eq,
202202
data PrintState = MkPrintState
203203
{ printName :: PrintNameStyle
204204
, printHelp :: Bool
205+
, freeze :: Bool
205206
}
206207
deriving stock (Show, Eq, Ord, Generic)
207208

@@ -210,6 +211,7 @@ initPrintState =
210211
MkPrintState
211212
{ printName = PrintName
212213
, printHelp = False
214+
, freeze = False
213215
}
214216

215217
data NOMV1State = MkNOMV1State

0 commit comments

Comments
 (0)