Wolfgang Jeltsch pushed to branch wip/jeltsch/querying-newline-modes at Glasgow Haskell Compiler / GHC
Commits:
-
29c804df
by Wolfgang Jeltsch at 2025-09-29T23:28:11+03:00
4 changed files:
- libraries/base/changelog.md
- libraries/base/src/System/IO.hs
- libraries/ghc-internal/src/GHC/Internal/IO/Handle.hs
- libraries/ghc-internal/src/GHC/Internal/System/IO.hs
Changes:
| ... | ... | @@ -10,6 +10,7 @@ |
| 10 | 10 | * Fix bug where `naturalAndNot` was incorrectly truncating results ([CLC proposal #350](github.com/haskell/core-libraries-committee/issues/350))
|
| 11 | 11 | * Remove extra laziness from `Data.Bifunctor.Bifunctor` instances for all tuples to have the same laziness as their `Data.Functor.Functor` counterparts (i.e. they became more strict than before) ([CLC proposal #339](https://github.com/haskell/core-libraries-committee/issues/339))
|
| 12 | 12 | * Adjust the strictness of `Data.List.iterate'` to be more reasonable: every element of the output list is forced to WHNF when the `(:)` containing it is forced. ([CLC proposal #335)](https://github.com/haskell/core-libraries-committee/issues/335)
|
| 13 | + * Add `System.IO.hGetNewlineMode` ([CLC proposal #370](https://github.com/haskell/core-libraries-committee/issues/370))
|
|
| 13 | 14 | |
| 14 | 15 | ## 4.22.0.0 *TBA*
|
| 15 | 16 | * Shipped with GHC 9.14.1
|
| ... | ... | @@ -175,6 +175,7 @@ module System.IO |
| 175 | 175 | -- Binary-mode 'Handle's do no newline translation at all.
|
| 176 | 176 | |
| 177 | 177 | hSetNewlineMode,
|
| 178 | + hGetNewlineMode,
|
|
| 178 | 179 | Newline(..),
|
| 179 | 180 | nativeNewline,
|
| 180 | 181 | NewlineMode(..),
|
| ... | ... | @@ -40,7 +40,7 @@ module GHC.Internal.IO.Handle ( |
| 40 | 40 | hIsOpen, hIsClosed, hIsReadable, hIsWritable, hGetBuffering, hIsSeekable,
|
| 41 | 41 | hSetEcho, hGetEcho, hIsTerminalDevice,
|
| 42 | 42 | |
| 43 | - hSetNewlineMode, Newline(..), NewlineMode(..), nativeNewline,
|
|
| 43 | + hSetNewlineMode, hGetNewlineMode, Newline(..), NewlineMode(..), nativeNewline,
|
|
| 44 | 44 | noNewlineTranslation, universalNewlineMode, nativeNewlineMode,
|
| 45 | 45 | |
| 46 | 46 | hShow,
|
| ... | ... | @@ -238,7 +238,7 @@ hSetBuffering handle mode = |
| 238 | 238 | return Handle__{ haBufferMode = mode,.. }
|
| 239 | 239 | |
| 240 | 240 | -- -----------------------------------------------------------------------------
|
| 241 | --- hSetEncoding
|
|
| 241 | +-- Setting and getting the text encoding
|
|
| 242 | 242 | |
| 243 | 243 | -- | The action 'hSetEncoding' @hdl@ @encoding@ changes the text encoding
|
| 244 | 244 | -- for the handle @hdl@ to @encoding@. The default encoding when a 'Handle' is
|
| ... | ... | @@ -624,16 +624,22 @@ hSetBinaryMode handle bin = |
| 624 | 624 | haOutputNL = outputNL nl, .. }
|
| 625 | 625 | |
| 626 | 626 | -- -----------------------------------------------------------------------------
|
| 627 | --- hSetNewlineMode
|
|
| 627 | +-- Setting and getting the newline mode
|
|
| 628 | 628 | |
| 629 | --- | Set the 'NewlineMode' on the specified 'Handle'. All buffered
|
|
| 629 | +-- | Set the 'NewlineMode' for the specified 'Handle'. All buffered
|
|
| 630 | 630 | -- data is flushed first.
|
| 631 | 631 | hSetNewlineMode :: Handle -> NewlineMode -> IO ()
|
| 632 | -hSetNewlineMode handle NewlineMode{ inputNL=i, outputNL=o } =
|
|
| 632 | +hSetNewlineMode handle NewlineMode{..} =
|
|
| 633 | 633 | withAllHandles__ "hSetNewlineMode" handle $ \h_@Handle__{} ->
|
| 634 | 634 | do
|
| 635 | 635 | flushBuffer h_
|
| 636 | - return h_{ haInputNL=i, haOutputNL=o }
|
|
| 636 | + return h_{ haInputNL = inputNL, haOutputNL = outputNL }
|
|
| 637 | + |
|
| 638 | +-- | Return the current 'NewlineMode' for the specified 'Handle'.
|
|
| 639 | +hGetNewlineMode :: Handle -> IO NewlineMode
|
|
| 640 | +hGetNewlineMode hdl =
|
|
| 641 | + withHandle_ "hGetNewlineMode" hdl $ \h_@Handle__{..} ->
|
|
| 642 | + return NewlineMode{ inputNL = haInputNL, outputNL = haOutputNL }
|
|
| 637 | 643 | |
| 638 | 644 | -- -----------------------------------------------------------------------------
|
| 639 | 645 | -- Duplicating a Handle
|
| ... | ... | @@ -213,6 +213,7 @@ module GHC.Internal.System.IO ( |
| 213 | 213 | -- Binary-mode 'Handle's do no newline translation at all.
|
| 214 | 214 | --
|
| 215 | 215 | hSetNewlineMode,
|
| 216 | + hGetNewlineMode,
|
|
| 216 | 217 | Newline(..), nativeNewline,
|
| 217 | 218 | NewlineMode(..),
|
| 218 | 219 | noNewlineTranslation, universalNewlineMode, nativeNewlineMode,
|