Skip to content

Commit

Permalink
Freeze/help user triggered features
Browse files Browse the repository at this point in the history
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 ><
  • Loading branch information
picnoir committed Dec 4, 2024
1 parent d085cce commit 21562df
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
22 changes: 16 additions & 6 deletions lib/NOM/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ processTextStream config parser updater maintenance printerMay finalize initialS
printerMay & maybe keepProcessing \(printer, output_handle) -> do
linesVar <- newTVarIO 0
let keepProcessingStdin :: IO ()
let toggleHelp :: IO () = atomically $ do
print_state <- readTMVar print_state_var
writeTMVar print_state_var $ print_state{printHelp = not print_state.printHelp}
writeTMVar new_user_input ()
keepProcessingStdin = forever $ do
key <- getKey
case key of
Expand All @@ -260,15 +264,21 @@ processTextStream config parser updater maintenance printerMay finalize initialS
print_state <- readTMVar print_state_var
let print_state_style = if print_state.printName == PrintName then PrintDerivationPath else PrintName
writeTMVar print_state_var $ print_state{printName = print_state_style}
writeTMVar input_received ()
"?" -> do
writeTMVar new_user_input ()
"?" -> toggleHelp
"h" -> toggleHelp
"f" -> do
atomically $ do
print_state <- takeTMVar print_state_var
putTMVar print_state_var $ print_state{printHelp = True}
writeTMVar input_received ()
print_state <- readTMVar print_state_var
writeTMVar print_state_var $ print_state{freeze = not print_state.freeze}
writeTMVar new_user_input ()
_ -> pure ()
writeToScreen :: IO ()
writeToScreen = writeStateToScreen (not config.silent) linesVar state_var print_state_var output_builder_var refresh_display_var maintenance printer output_handle
writeToScreen = do
print_state <- atomically $ readTMVar print_state_var
case (print_state.freeze, print_state.printHelp) of
(True, _) -> pure () -- Freezing the output, do not print anything.
_ -> writeStateToScreen (not config.silent) printedLinesVar state_var print_state_var output_builder_var refresh_display_var maintenance printer output_handle
keepPrinting :: IO ()
keepPrinting = forever do
runConcurrently
Expand Down
14 changes: 12 additions & 2 deletions lib/NOM/Print.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module NOM.Print (stateToText, showCode, Config (..)) where
module NOM.Print (stateToText, showCode, helpString, Config (..)) where

import Data.Foldable qualified as Unsafe
import Data.IntMap.Strict qualified as IntMap
Expand Down Expand Up @@ -184,7 +184,7 @@ stateToText config buildState@MkNOMV1State{..} printState = memo printWithSize .
horizontal
(vertical <> " ")
(vertical <> " ")
(printBuilds buildState printState hostNums maxHeight now)
(if not printState.printHelp then printBuilds buildState printState hostNums maxHeight now else helpString)
errorDisplay = printErrors nixErrors maxHeight
traceDisplay = printTraces nixTraces maxHeight
-- evalMessage = case evaluationState.lastFileName of
Expand All @@ -197,6 +197,7 @@ stateToText config buildState@MkNOMV1State{..} printState = memo printWithSize .
MkDependencySummary{..} = fullSummary
runningBuilds' = (.host) <$> runningBuilds
completedBuilds' = (.host) <$> completedBuilds

failedBuilds' = (.host) <$> failedBuilds
numFailedBuilds = CMap.size failedBuilds
table time' =
Expand Down Expand Up @@ -588,3 +589,12 @@ printDuration diff

timeDiffSeconds :: Int -> Text
timeDiffSeconds = printDuration . fromIntegral

helpString :: NonEmpty Text
helpString =
fromList
[ markup bold " Key Bindings"
, "n: toggle derivation name/derivation path print"
, "f: toggle screen freeze"
, "? or h: toggle help view"
]
2 changes: 2 additions & 0 deletions lib/NOM/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ data PrintNameStyle = PrintName | PrintDerivationPath deriving stock (Show, Eq,
data PrintState = MkPrintState
{ printName :: PrintNameStyle
, printHelp :: Bool
, freeze :: Bool
}
deriving stock (Show, Eq, Ord, Generic)

Expand All @@ -210,6 +211,7 @@ initPrintState =
MkPrintState
{ printName = PrintName
, printHelp = False
, freeze = False
}

data NOMV1State = MkNOMV1State
Expand Down

0 comments on commit 21562df

Please sign in to comment.