New submission from Gian Piero Carrubba <[email protected]>:

Some mixed patches. I've split the one regarding the pager in two:

- patch 99be3ad02140e22e3c0e8b5f7de6e3d226b5bcaf
I think this is how it should work, but that means there's no way for
preserving the current behaviour.

- patch 9d723bedd600912a04c2480e066d553f352775e9
If, for some reason I could not think of, preserving the current behaviour is
mandatory, only apply this patch and not the previous one. Users setting
DARCS_FORCE_PAGER=20 should not note any difference.

I have not tested that System.Console.Terminal.Size works on any supported
platform.

5 patches for repository http://darcs.net/screened:

patch aea7e3314c91b7cf143594d5451095abd5214210
Author: Gian Piero Carrubba <[email protected]>
Date:   Sun Sep 14 23:51:24 CEST 2025
  * fix a typo in help environment's output

patch 9d723bedd600912a04c2480e066d553f352775e9
Author: Gian Piero Carrubba <[email protected]>
Date:   Tue Sep 16 17:07:53 CEST 2025
  * invoke the pager based on terminal size rather than a fixed threshold

  Also introduce the DARCS_FORCE_PAGER environment variable so that the user can
  set a fixed threshold if desired.

patch e0e0614ba0f437b0cca1cacd8ea56777ba58fd58
Author: Gian Piero Carrubba <[email protected]>
Date:   Tue Sep 16 20:59:48 CEST 2025
  * show the super command (if any) in the "disabled" message

  Also enclose the command name in single quotes.

patch 99be3ad02140e22e3c0e8b5f7de6e3d226b5bcaf
Author: Gian Piero Carrubba <[email protected]>
Date:   Tue Sep 16 17:09:46 CEST 2025
  * invoke the pager based on terminal size rather than a fixed threshold

  Remove the DARCS_FORCE_PAGER environment variable and introduce instead the
  DARCS_PAGER_ALLOWANCE one, so that the user can fine tune the use of pager
  depending on their own environment (e.g., a multi-line prompt).

patch f0bc660a3766938de7fe1a914baec5bd84217475
Author: Gian Piero Carrubba <[email protected]>
Date:   Sun Sep 21 14:31:09 CEST 2025
  * set DARCS_HOOK and DARCS_CMD environment vars for use by hook scripts

----------
files: fix-a-typo-in-help-environment_s-output.dpatch, patch-preview.txt
messages: 24207
nosy: gpiero
status: needs-screening
title: fix a typo in help environment's output (and 4 more)

__________________________________
Darcs bug tracker <[email protected]>
<https://bugs.darcs.net/patch2457>
__________________________________
[fix a typo in help environment's output
Gian Piero Carrubba <[email protected]>**20250914215124
 Ignore-this: 71463cd8e28c9e94bd3007c3e4c7ea9f0a956c913bc56d008cc1b41e16f1cfe28abc299f27512107
] hunk ./src/Darcs/UI/Commands/Help.hs 438
- "Set the maximum time in seconds that darcs allows and connection to",
+ "Set the maximum time in seconds that darcs allows a connection to",

[invoke the pager based on terminal size rather than a fixed threshold
Gian Piero Carrubba <[email protected]>**20250916150753
 Ignore-this: 9b3316f394896c9002a6feee0bd680d56ada0332f186fd9f420d2d691aeefbc558e8e0dd387c8f50
 
 Also introduce the DARCS_FORCE_PAGER environment variable so that the user can
 set a fixed threshold if desired.
] hunk ./src/Darcs/UI/Commands/Help.hs 429
-environmentHelpPager = (["DARCS_PAGER", "PAGER"],[
- "Darcs will invoke a pager if the output of some command is longer",
- "than 20 lines. Darcs will use the pager specified by $DARCS_PAGER",
- "or $PAGER.  If neither are set, `less` will be used.  Set $DARCS_PAGER",
- "- or $PAGER if the former is not set - to the empty string in order not",
- "to use a pager."])
+environmentHelpPager = (["DARCS_PAGER", "PAGER", "DARCS_FORCE_PAGER"],[
+ "When printing to a terminal, Darcs will invoke a pager if the output",
+ "of some command is at least as long as the number of lines in the terminal",
+ "minus 2.  Darcs will use the pager specified by $DARCS_PAGER or $PAGER, or,",
+ "if neither is set, `less`.  Set $DARCS_PAGER - or $PAGER if the former is",
+ "not set - to the empty string in order not to use a pager.  You can set",
+ "DARCS_FORCE_PAGER to an integer to force the use of the pager when the",
+ "output's length is equal or greater than that number of lines, regardless",
+ "of the size of the terminal."])
hunk ./src/Darcs/UI/External.hs 37
+    , lookupEnv
hunk ./src/Darcs/UI/External.hs 43
-    , hIsTerminalDevice
hunk ./src/Darcs/UI/External.hs 46
+import qualified System.Console.Terminal.Size as TS ( size, height, Window )
hunk ./src/Darcs/UI/External.hs 51
+import Text.Read ( readMaybe )
hunk ./src/Darcs/UI/External.hs 394
-  isTerminal <- hIsTerminalDevice stdout
-  void $ if isTerminal && lengthGreaterThan (20 :: Int) (lines $ renderString msg)
+  isTerminal <- isTerminal'
+  maxLength <- maxLength'
+  void $ if isTerminal && lengthEqualOrGreaterThan maxLength (lines $ renderString msg)
hunk ./src/Darcs/UI/External.hs 411
-              where lengthGreaterThan n _ | n <= 0 = True
-                    lengthGreaterThan _ [] = False
-                    lengthGreaterThan n (_:xs) = lengthGreaterThan (n-1) xs
+              where lengthEqualOrGreaterThan n _ | n <= 0 = True
+                    lengthEqualOrGreaterThan _ [] = False
+                    lengthEqualOrGreaterThan n (_:xs) = lengthEqualOrGreaterThan (n-1) xs
+                    isTerminal' = do
+                        size :: Maybe (TS.Window Int) <- TS.size
+                        return $ isJust size
+                    terminalHeight' = do
+                        size :: Maybe (TS.Window Int) <- TS.size
+                        case size of
+                            Nothing -> return 0
+                            (Just window) -> return $ TS.height window
+                    maxLength' = do
+                        terminalHeight <- terminalHeight'
+                        darcsForcePager <- lookupEnv "DARCS_FORCE_PAGER"
+                        let defaultMaxLength = terminalHeight - 2
+                        return $ case darcsForcePager of
+                                    Nothing -> defaultMaxLength
+                                    (Just string) -> case (readMaybe string :: (Maybe Int)) of
+                                                        Nothing -> defaultMaxLength
+                                                        (Just int) -> int

[show the super command (if any) in the "disabled" message
Gian Piero Carrubba <[email protected]>**20250916185948
 Ignore-this: a463a736df8f56eb014e1bb0c85bae32d70590c7ce80a3bb3806e73affe6b930836b13547205a30f
 
 Also enclose the command name in single quotes.
] hunk ./src/Darcs/UI/RunCommand.hs 77
-import Darcs.Util.Printer ( (<+>), ($+$), renderString, text, vcat )
+import Darcs.Util.Printer ( ($+$), renderString, text, vcat )
hunk ./src/Darcs/UI/RunCommand.hs 119
-          die $ "Command "++commandName cmd++" disabled with --disable option!"
+          die $ "Command '"++ superName msuper ++ commandName cmd ++"' disabled with --disable option!"
hunk ./src/Darcs/UI/RunCommand.hs 234
-          "Command" <+> text (commandName super) <+> "disabled with --disable option!"
+          "Command '" <> text (commandName super) <> "' disabled with --disable option!"

[invoke the pager based on terminal size rather than a fixed threshold
Gian Piero Carrubba <[email protected]>**20250916150946
 Ignore-this: b9d8ec97986c0b0bdb579e7fc4db7964d7efa25eeffba710b726dd08e8421f77f855a019a7ef0401
 
 Remove the DARCS_FORCE_PAGER environment variable and introduce instead the
 DARCS_PAGER_ALLOWANCE one, so that the user can fine tune the use of pager
 depending on their own environment (e.g., a multi-line prompt).
] hunk ./src/Darcs/UI/Commands/Help.hs 429
-environmentHelpPager = (["DARCS_PAGER", "PAGER", "DARCS_FORCE_PAGER"],[
+environmentHelpPager = (["DARCS_PAGER", "PAGER", "DARCS_PAGER_ALLOWANCE"],[
hunk ./src/Darcs/UI/Commands/Help.hs 431
- "of some command is at least as long as the number of lines in the terminal",
- "minus 2.  Darcs will use the pager specified by $DARCS_PAGER or $PAGER, or,",
- "if neither is set, `less`.  Set $DARCS_PAGER - or $PAGER if the former is",
- "not set - to the empty string in order not to use a pager.  You can set",
- "DARCS_FORCE_PAGER to an integer to force the use of the pager when the",
- "output's length is equal or greater than that number of lines, regardless",
- "of the size of the terminal."])
+ "of some command is longer than the number of lines in the terminal minus",
+ "$DARCS_PAGER_ALLOWANCE (default: 3).  Darcs will use the pager specified by",
+ "$DARCS_PAGER or $PAGER, or, if neither is set, `less`.  Set $DARCS_PAGER",
+ "- or $PAGER if the former is not set - to the empty string in order not to",
+ "use a pager."])
hunk ./src/Darcs/UI/External.hs 396
-  void $ if isTerminal && lengthEqualOrGreaterThan maxLength (lines $ renderString msg)
+  void $ if isTerminal && lengthGreaterThan maxLength (lines $ renderString msg)
hunk ./src/Darcs/UI/External.hs 411
-              where lengthEqualOrGreaterThan n _ | n <= 0 = True
-                    lengthEqualOrGreaterThan _ [] = False
-                    lengthEqualOrGreaterThan n (_:xs) = lengthEqualOrGreaterThan (n-1) xs
+              where lengthGreaterThan n _ | n < 0 = True
+                    lengthGreaterThan _ [] = False
+                    lengthGreaterThan n (_:xs) = lengthGreaterThan (n-1) xs
hunk ./src/Darcs/UI/External.hs 424
-                        darcsForcePager <- lookupEnv "DARCS_FORCE_PAGER"
-                        let defaultMaxLength = terminalHeight - 2
-                        return $ case darcsForcePager of
-                                    Nothing -> defaultMaxLength
-                                    (Just string) -> case (readMaybe string :: (Maybe Int)) of
-                                                        Nothing -> defaultMaxLength
+                        darcsPagerAllowance <- lookupEnv "DARCS_PAGER_ALLOWANCE"
+                        let allowance = case darcsPagerAllowance of
+                                            Nothing -> defaultAllowance
+                                            (Just string) ->
+                                                    case (readMaybe string :: (Maybe Int)) of
+                                                        Nothing -> defaultAllowance
hunk ./src/Darcs/UI/External.hs 431
+                                where defaultAllowance = 3
+                        return $ terminalHeight - allowance

[set DARCS_HOOK and DARCS_CMD environment vars for use by hook scripts
Gian Piero Carrubba <[email protected]>**20250921123109
 Ignore-this: bf44d4f76ad7fb770ed4f6c2c7acd87604fce90a9aa0be871fef09d62f8316d58bf401f9cf1f4f65
] hunk ./src/Darcs/UI/Commands/Help.hs 234
- environmentHelpTimeout]
+ environmentHelpTimeout,
+ -- Variables set by darcs
+ environmentHelpHooks]
hunk ./src/Darcs/UI/Commands/Help.hs 445
+environmentHelpHooks :: ([String], [String])
+environmentHelpHooks = (["DARCS_HOOK", "DARCS_CMD"],[
+ "Darcs sets these variables for the convenience of users' hook scripts.",
+ "DARCS_CMD contains the darcs command being executed, while the value of",
+ "DARCS_HOOK is 'prehook' or 'posthook' depending on the hook invoked."])
+
hunk ./src/Darcs/UI/RunCommand.hs 34
+import System.Environment ( setEnv )
hunk ./src/Darcs/UI/RunCommand.hs 131
-                  Nothing     -> runWithHooks cmd (new_wd, old_wd) flags extra
+                  Nothing     -> do setEnv "DARCS_CMD" $ superName msuper ++ commandName cmd
+                                    runWithHooks cmd (new_wd, old_wd) flags extra
hunk ./src/Darcs/UI/RunHook.hs 27
+import System.Environment ( setEnv )
hunk ./src/Darcs/UI/RunHook.hs 32
+import Data.Char ( toLower )
hunk ./src/Darcs/UI/RunHook.hs 67
-    do ec <- system command
+    do setEnv "DARCS_HOOK" $ map toLower cname
+       ec <- system command
hunk ./tests/posthook.sh 42
+
+# Check that DARCS_HOOK and DARCS_CMD are correctly set
+rm -rf R
+darcs init      --repo R
+cd R
+
+echo 'ALL  posthook  echo "HOOK: $DARCS_HOOK"' > _darcs/prefs/defaults
+touch f
+darcs record -lam 'Add f' | grep '^HOOK: posthook$'
+
+echo 'ALL  posthook  echo "CMD: $DARCS_CMD"' > _darcs/prefs/defaults
+touch g
+darcs record -lam 'Add g' | grep '^CMD: record$'
+# two-word command
+darcs show repo | grep '^CMD: show repo$'
+
+cd ..
hunk ./tests/prehook.sh 28
+
+# Check that DARCS_HOOK and DARCS_CMD are correctly set
+rm -rf R
+darcs init      --repo R
+cd R
+
+echo 'ALL  prehook  echo "HOOK: $DARCS_HOOK"' > _darcs/prefs/defaults
+touch f
+darcs record -lam 'Add f' | grep '^HOOK: prehook$'
+
+echo 'ALL  prehook  echo "CMD: $DARCS_CMD"' > _darcs/prefs/defaults
+touch g
+darcs record -lam 'Add g' | grep '^CMD: record$'
+# two-word command
+darcs show repo | grep '^CMD: show repo$'
+
+cd ..

Attachment: fix-a-typo-in-help-environment_s-output.dpatch
Description: application/darcs-patch

_______________________________________________
darcs-devel mailing list
[email protected]
https://lists.darcs.net/mailman/listinfo/darcs-devel

Reply via email to