New submission from Ganesh Sittampalam <[email protected]>:

breaking out of patch2457 for independent review

2 patches for repository [email protected]:/opt/darcs/screened:

patch 9d723bedd600912a04c2480e066d553f352775e9
Author: Gian Piero Carrubba <[email protected]>
Date:   Tue Sep 16 16:07:53 BST 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 99be3ad02140e22e3c0e8b5f7de6e3d226b5bcaf
Author: Gian Piero Carrubba <[email protected]>
Date:   Tue Sep 16 16:09:46 BST 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).

----------
files: 
invoke-the-pager-based-on-terminal-size-rather-than-a-fixed-threshold.dpatch, 
patch-preview.txt
messages: 24227
nosy: ganesh
status: needs-screening
title: invoke the pager based on terminal size ... (and 1 more)

__________________________________
Darcs bug tracker <[email protected]>
<https://bugs.darcs.net/patch2466>
__________________________________
[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

[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

Attachment: invoke-the-pager-based-on-terminal-size-rather-than-a-fixed-threshold.dpatch
Description: application/darcs-patch

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

Reply via email to