ansi-terminal 1.1.1 → 1.1.2
raw patch · 6 files changed
+81/−15 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ System.Console.ANSI: disableLineWrap :: IO ()
+ System.Console.ANSI: disableLineWrapCode :: String
+ System.Console.ANSI: enableLineWrap :: IO ()
+ System.Console.ANSI: enableLineWrapCode :: String
+ System.Console.ANSI: hDisableLineWrap :: Handle -> IO ()
+ System.Console.ANSI: hEnableLineWrap :: Handle -> IO ()
+ System.Console.ANSI.Codes: disableLineWrapCode :: String
+ System.Console.ANSI.Codes: enableLineWrapCode :: String
Files
- CHANGELOG.md +6/−0
- README.md +2/−0
- ansi-terminal.cabal +1/−4
- app/Example.hs +19/−0
- src/System/Console/ANSI.hs +42/−11
- src/System/Console/ANSI/Codes.hs +11/−0
CHANGELOG.md view
@@ -1,6 +1,12 @@ Changes ======= +Version 1.1.2 +------------- + +* Add `enableLineWrap` and `disableLineWrap`, and support for enabling and + disabling automatic line wrapping. + Version 1.1.1 -------------
README.md view
@@ -15,6 +15,7 @@ - Hiding or showing the cursor - Moving the cursor around - Reporting the position of the cursor+- Enabling and disabling automatic line wrapping - Scrolling the screen up or down - Switching between the Alternate and Normal Screen Buffers - Clickable hyperlinks to URIs@@ -40,6 +41,7 @@ - Directly changing cursor position: `setCursorColumn` and `setCursorPosition` - Saving, restoring and reporting cursor position: `saveCursor`, `restoreCursor` and `reportCursorPosition`+- Automatic line wrapping: `enableLineWrap` and `disableLineWrap` - Scrolling the screen: `scrollPageUp` and `scrollPageDown` - Changing the title: `setTitle`
ansi-terminal.cabal view
@@ -1,6 +1,6 @@ Cabal-Version: 1.22 Name: ansi-terminal -Version: 1.1.1 +Version: 1.1.2 Category: User Interfaces Synopsis: Simple ANSI terminal support Description: ANSI terminal support for Haskell: allows cursor movement, @@ -47,9 +47,6 @@ System.Console.ANSI.Windows.Win32.Types System.Console.ANSI.Windows.Win32.MinTTY Include-Dirs: win/include - Includes: errors.h - HsWin32.h - winternl_compat.h Install-Includes: HsWin32.h C-Sources: win/c-source/errors.c win/c-source/HsWin32.c
app/Example.hs view
@@ -18,6 +18,7 @@ , setCursorPositionExample , saveRestoreCursorExample , clearExample + , lineWrapExample , scrollExample , screenBuffersExample , sgrColorExample @@ -205,6 +206,24 @@ clearScreen pause -- + +lineWrapExample :: IO () +lineWrapExample = do + putStrLn $ take 240 $ cycle "Default-line-wrap|" + pause + -- Default-line-wrap|Default-line-wrap|Default-line-wrap|Default-line-wrap|Def + -- ault-line-wrap|Default-line-wrap|Default-line-wrap|Default-line-wrap|Defaul + -- t-line-wrap|Default-line-wrap|Default-line-wrap|Default-line-wrap|Default-l + disableLineWrap + putStrLn $ take 240 $ cycle "Disable-line-wrap|" + pause + -- Disable-line-wrap|Disable-line-wrap|Disable-line-wrap|Disable-line-wrap|Dis + enableLineWrap + putStrLn $ take 240 $ cycle "Enable-line-wrap|" + pause + -- Enable-line-wrap|Enable-line-wrap|Enable-line-wrap|Enable-line-wrap|Enable- + -- line-wrap|Enable-line-wrap|Enable-line-wrap|Enable-line-wrap|Enable-line-wr + -- ap|Enable-line-wrap|Enable-line-wrap|Enable-line-wrap|Enable-line-wrap|Enab scrollExample :: IO () scrollExample = do
src/System/Console/ANSI.hs view
@@ -21,6 +21,8 @@ * Reporting the position of the cursor + * Enabling or disabling automatic line wrapping + * Scrolling the screen up or down * Switching between the Alternate and Normal Screen Buffers @@ -84,9 +86,9 @@ GHC's management of input and output (IO) on Windows has also developed over time. If they are supported by the terminal software, some control character sequences cause data to be emitted into the console input stream. For GHC's -historical and default IO manager, the function 'hGetBufNonBlocking' in module -"System.IO" does not work on Windows. This has been attributed to the lack of -non-blocking primatives in the operating system (see +historical and default IO manager, the function 'System.IO.hGetBufNonBlocking' +in module "System.IO" does not work on Windows. This has been attributed to the +lack of non-blocking primatives in the operating system (see [GHC bug report #806](https://ghc.haskell.org/trac/ghc/ticket/806). GHC's native IO manager on Windows (\'WinIO\'), introduced as a preview in [GHC 9.0.1](https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/9.0.1-notes.html#highlights), @@ -197,6 +199,7 @@ , cursorBackwardCode -- * Cursor movement by line + -- -- | The difference between movements \"by character\" and \"by line\" is -- that @*Line@ functions additionally move the cursor to the start of the -- line, while functions like @cursorUp@ and @cursorDown@ keep the column @@ -221,6 +224,7 @@ , setCursorPositionCode -- * Saving, restoring and reporting cursor position + -- -- | These code sequences are not part of ECMA-48 standard; they are popular, -- but non-portable extensions. E. g., Terminal.app on MacOS -- <https://stackoverflow.com/questions/25879183 does not support them>. @@ -243,6 +247,7 @@ , reportCursorPositionCode -- * Clearing parts of the screen + -- -- | Note that these functions only clear parts of the screen. They do not -- move the cursor. Some functions are based on the whole screen and others -- are based on the line in which the cursor is located. @@ -267,6 +272,19 @@ , clearFromCursorToLineBeginningCode , clearLineCode + -- * Enabling and disabling automatic line wrapping + -- + -- | These functions control whether or not characters automatically wrap to + -- the next line when the cursor reaches the right border. + , enableLineWrap + , disableLineWrap + -- ** \'h...\' variants + , hEnableLineWrap + , hDisableLineWrap + -- ** \'...Code\' variants + , enableLineWrapCode + , disableLineWrapCode + -- * Scrolling the screen , scrollPageUp , scrollPageDown @@ -278,6 +296,7 @@ , scrollPageDownCode -- * Using screen buffers + -- -- | These code sequences are not part of ECMA-48 standard; they are popular, -- but non-portable extensions, corresponding to @smcup@ and @rmcup@ capabilities -- in @terminfo@ database. @@ -303,6 +322,7 @@ , setSGRCode -- * Cursor visibilty changes + -- -- | Strictly speaking, these code sequences are not part of ECMA-48 standard; -- they are popular, but non-portable extensions. However, in practice they seem -- to work pretty much everywhere. @@ -316,6 +336,7 @@ , showCursorCode -- * Hyperlinks + -- -- | These code sequences are not part of ECMA-48 standard and not even an -- @xterm@ extension. Nevertheless -- <https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda many terminals> @@ -600,7 +621,7 @@ -- will work with a given handle. -- -- If the handle is not writable (that is, it cannot manage output - see --- 'hIsWritable'), then @pure False@ is returned. +-- 'System.IO.hIsWritable'), then @pure False@ is returned. -- -- For Unix-like operating systems, the current implementation checks -- that: (1) the handle is a terminal; and (2) a @TERM@ environment variable is @@ -611,12 +632,12 @@ -- a terminal, (2) a @TERM@ environment variable is not set to @dumb@, and (3) -- the processing of \'ANSI\' control characters in output is enabled; and -- second, as an alternative, whether the handle is connected to a \'mintty\' --- terminal. (That is because the function 'hIsTerminalDevice' is used to check --- if the handle is a terminal. However, where a non-native Windows terminal --- (such as \'mintty\') is implemented using redirection, that function will not --- identify a handle to the terminal as a terminal.) If it is not already --- enabled, this function does *not* enable the processing of \'ANSI\' control --- characters in output (see 'hNowSupportsANSI'). +-- terminal. (That is because the function 'System.IO.hIsTerminalDevice' is used +-- to check if the handle is a terminal. However, where a non-native Windows +-- terminal (such as \'mintty\') is implemented using redirection, that function +-- will not identify a handle to the terminal as a terminal.) If it is not +-- already enabled, this function does *not* enable the processing of \'ANSI\' +-- control characters in output (see 'hNowSupportsANSI'). -- -- @since 0.6.2 hSupportsANSI :: Handle -> IO Bool @@ -955,7 +976,7 @@ -- | Attempts to get the current terminal size (height in rows, width in -- columns), by writing control character sequences to the specified handle --- (which will typically be 'stdout' or 'stderr'). +-- (which will typically be 'stdout' or 'System.IO.stderr'). -- -- There is no \'ANSI\' control character sequence that reports the terminal -- size. So, it attempts to set the cursor position beyond the bottom right @@ -1027,6 +1048,16 @@ clearFromCursorToLineEnd = hClearFromCursorToLineEnd stdout clearFromCursorToLineBeginning = hClearFromCursorToLineBeginning stdout clearLine = hClearLine stdout + +hEnableLineWrap, hDisableLineWrap :: + Handle + -> IO () +hEnableLineWrap h = hPutStr h enableLineWrapCode +hDisableLineWrap h = hPutStr h disableLineWrapCode + +enableLineWrap, disableLineWrap :: IO () +enableLineWrap = hEnableLineWrap stdout +disableLineWrap = hDisableLineWrap stdout hScrollPageUp, hScrollPageDown :: Handle
src/System/Console/ANSI/Codes.hs view
@@ -35,6 +35,12 @@ , clearScreenCode, clearFromCursorToLineEndCode , clearFromCursorToLineBeginningCode, clearLineCode + -- * Enabling and disabling automatic line wrapping + -- + -- | These functions control whether or not characters automatically wrap to + -- the next line when the cursor reaches the right border. + , enableLineWrapCode, disableLineWrapCode + -- * Scrolling the screen -- -- | These functions yield @\"\"@ when the number is @0@ as, on some @@ -55,6 +61,7 @@ , hideCursorCode, showCursorCode -- * Hyperlinks + -- -- | Some, but not all, terminals support hyperlinks - that is, clickable -- text that points to a URI. , hyperlinkCode, hyperlinkWithIdCode, hyperlinkWithParamsCode @@ -308,6 +315,10 @@ clearFromCursorToLineEndCode = csi [0] "K" clearFromCursorToLineBeginningCode = csi [1] "K" clearLineCode = csi [2] "K" + +enableLineWrapCode, disableLineWrapCode :: String +enableLineWrapCode = csi [] "?7h" +disableLineWrapCode = csi [] "?7l" scrollPageUpCode, scrollPageDownCode :: Int -- ^ Number of lines to scroll by