ansi-terminal 0.4.0 → 0.5.0
raw patch · 8 files changed
+117/−61 lines, 8 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ System.Console.ANSI: hSetTitle :: Handle -> String -> IO ()
+ System.Console.ANSI: setTitle :: String -> IO ()
+ System.Console.ANSI: setTitleCode :: String -> String
Files
- README.textile +56/−55
- System/Console/ANSI/Example.hs +15/−0
- System/Console/ANSI/Unix.hs +9/−1
- System/Console/ANSI/Windows/Emulator.hs +8/−0
- System/Console/ANSI/Windows/Foreign.hs +6/−1
- ansi-terminal.cabal +3/−3
- includes/Common-Include.hs +14/−0
- includes/Exports-Include.hs +6/−1
README.textile view
@@ -1,56 +1,57 @@-h1. ANSI Terminal - -You can help improve this README with extra snippets and advice by using the "GitHub wiki":http://github.com/batterseapower/ansi-terminal/wikis/readme. - - -h2. Installing - -To just install the library: - -<pre> -<code>runghc Setup.lhs configure -runghc Setup.lhs build -sudo runghc Setup.lhs install -</pre> -</code> - -If you want to build the example, to check it's all working: - -<pre> -<code>runghc Setup.lhs configure -fexample -runghc Setup.lhs build -dist/build/ansi-terminal-example/ansi-terminal-example -</pre> -</code> - - -h2. Description - -"ANSI":http://en.wikipedia.org/wiki/ANSI_escape_sequences terminal support for Haskell, which allows: - -* Cursor movement -* Screen and line clearing -* Color output -* Showing or hiding the cursor - -It is compatible with Windows (via an emulation layer) and those Unixes with ANSI terminals - -If you like this, you may be interested in "ansi-wl-pprint":http://github.com/batterseapower/ansi-wl-pprint, which provides a pretty-printer that can construct strings containing ANSI colorisation. - - -h2. Example - -A full example is provided with the package, and can be compiled by suppling Cabal with the @-fexample@ flag. It is also available online at "GitHub":http://github.com/batterseapower/ansi-terminal/tree/master/System/Console/ANSI/Example.hs. - -Not all of the ANSI escape codes are provided by this module, but most (if not all) of the popular and well supported ones are. For a full list, you can see the API "here":http://github.com/batterseapower/ansi-terminal/tree/master/includes/Common-Include.hs. Each supported escape code or family of codes has a corresponding function that comes in three variants: - -* A straight @IO@ variant that doesn't take a @Handle@ and just applies the ANSI escape code to the terminal attached to stdout -* An @IO@ variant similar to above, but which takes a @Handle@ to which the ANSI escape should be applied -* A @String@ variant that returns a literal string that should be included to get the effect of the code. This is the only one of the three API variants that only works on Unix-like operating systems: on Windows these strings will always be blank! - - -h2. Linkage - -* "Hackage":http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ansi-terminal -* "Bug Tracker":http://bsp.lighthouseapp.com/projects/16235-hs-ansi-terminal +h1. ANSI Terminal++You can help improve this README with extra snippets and advice by using the "GitHub wiki":http://github.com/batterseapower/ansi-terminal/wikis/readme.+++h2. Installing++To just install the library:++<pre>+<code>runghc Setup.lhs configure+runghc Setup.lhs build+sudo runghc Setup.lhs install+</pre>+</code>++If you want to build the example, to check it's all working:++<pre>+<code>runghc Setup.lhs configure -fexample+runghc Setup.lhs build+dist/build/ansi-terminal-example/ansi-terminal-example+</pre>+</code>+++h2. Description++"ANSI":http://en.wikipedia.org/wiki/ANSI_escape_sequences terminal support for Haskell, which allows:++* Cursor movement+* Screen and line clearing+* Color output+* Showing or hiding the cursor+* Changing the console title (though this is not strictly part of ANSI, it is widely supported in Unix)++It is compatible with Windows (via an emulation layer) and those Unixes with ANSI terminals++If you like this, you may be interested in "ansi-wl-pprint":http://github.com/batterseapower/ansi-wl-pprint, which provides a pretty-printer that can construct strings containing ANSI colorisation.+++h2. Example++A full example is provided with the package, and can be compiled by suppling Cabal with the @-fexample@ flag. It is also available online at "GitHub":http://github.com/batterseapower/ansi-terminal/tree/master/System/Console/ANSI/Example.hs.++Not all of the ANSI escape codes are provided by this module, but most (if not all) of the popular and well supported ones are. For a full list, you can see the API "here":http://github.com/batterseapower/ansi-terminal/tree/master/includes/Common-Include.hs. Each supported escape code or family of codes has a corresponding function that comes in three variants:++* A straight @IO@ variant that doesn't take a @Handle@ and just applies the ANSI escape code to the terminal attached to stdout+* An @IO@ variant similar to above, but which takes a @Handle@ to which the ANSI escape should be applied+* A @String@ variant that returns a literal string that should be included to get the effect of the code. This is the only one of the three API variants that only works on Unix-like operating systems: on Windows these strings will always be blank!+++h2. Linkage++* "Hackage":http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ansi-terminal+* "Bug Tracker":http://bsp.lighthouseapp.com/projects/16235-hs-ansi-terminal * "GitHub":http://github.com/batterseapower/ansi-terminal/
System/Console/ANSI/Example.hs view
@@ -18,6 +18,7 @@ , scrollExample , sgrExample , cursorVisibilityExample+ , titleExample ] main :: IO ()@@ -250,3 +251,17 @@ showCursor pause -- Cursor Demo|++titleExample :: IO ()+titleExample = do+ putStr "Title Demo"+ pause+ -- ~/foo/ - ansi-terminal-ex - 83x70+ ------------------------------------+ -- Title Demo+ + setTitle "Yup, I'm a new title!"+ pause+ -- Yup, I'm a new title! - ansi-terminal-ex - 83x70+ ---------------------------------------------------+ -- Title Demo
System/Console/ANSI/Unix.hs view
@@ -13,7 +13,7 @@ #include "Common-Include.hs" --- | The reference I used for the escape characters in this module was http://en.wikipedia.org/wiki/ANSI_escape_sequences+-- | The reference I used for the ANSI escape characters in this module was <http://en.wikipedia.org/wiki/ANSI_escape_sequences>. csi :: [Int] -> String -> String csi args code = "\ESC[" ++ concat (intersperse ";" (map show args)) ++ code @@ -115,3 +115,11 @@ hHideCursor h = hPutStr h hideCursorCode hShowCursor h = hPutStr h showCursorCode+++-- | Thanks to Brandon S. Allbery and Curt Sampson for pointing me in the right direction on xterm title setting on haskell-cafe.+-- The "0" signifies that both the title and "icon" text should be set: i.e. the text for the window in the Start bar (or similar)+-- as well as that in the actual window title. This is chosen for consistent behaviour between Unixes and Windows.+setTitleCode title = "\ESC]0;" ++ filter (/= '\007') title ++ "\007"++hSetTitle h title = hPutStr h $ setTitleCode title
System/Console/ANSI/Windows/Emulator.hs view
@@ -220,3 +220,11 @@ hideCursorCode = "" showCursorCode = ""+++-- Windows only supports setting the terminal title on a process-wide basis, so for now we will+-- assume that that is what the user intended. This will fail if they are sending the command+-- over e.g. a network link... but that's not really what I'm designing for.+hSetTitle _ title = withTString title $ setConsoleTitle++setTitleCode _ = ""
System/Console/ANSI/Windows/Foreign.hs view
@@ -21,12 +21,13 @@ setConsoleTextAttribute, setConsoleCursorPosition, setConsoleCursorInfo,+ setConsoleTitle, fillConsoleOutputAttribute, fillConsoleOutputCharacter, scrollConsoleScreenBuffer, - withHandleToHANDLE+ withTString, withHandleToHANDLE ) where import Foreign.C.Types@@ -229,6 +230,7 @@ foreign import stdcall unsafe "windows.h SetConsoleTextAttribute" cSetConsoleTextAttribute :: HANDLE -> WORD -> IO BOOL foreign import stdcall unsafe "windows.h SetConsoleCursorPosition" cSetConsoleCursorPosition :: HANDLE -> UNPACKED_COORD -> IO BOOL foreign import stdcall unsafe "windows.h SetConsoleCursorInfo" cSetConsoleCursorInfo :: HANDLE -> Ptr CONSOLE_CURSOR_INFO -> IO BOOL+foreign import stdcall unsafe "windows.h SetConsoleTitleW" cSetConsoleTitle :: LPCTSTR -> IO BOOL foreign import stdcall unsafe "windows.h FillConsoleOutputAttribute" cFillConsoleOutputAttribute :: HANDLE -> WORD -> DWORD -> UNPACKED_COORD -> Ptr DWORD -> IO BOOL foreign import stdcall unsafe "windows.h FillConsoleOutputCharacterW" cFillConsoleOutputCharacter :: HANDLE -> TCHAR -> DWORD -> UNPACKED_COORD -> Ptr DWORD -> IO BOOL@@ -255,6 +257,9 @@ setConsoleCursorInfo :: HANDLE -> CONSOLE_CURSOR_INFO -> IO () setConsoleCursorInfo handle console_cursor_info = with console_cursor_info $ \ptr_console_cursor_info -> do failIfFalse_ "setConsoleCursorInfo" $ cSetConsoleCursorInfo handle ptr_console_cursor_info++setConsoleTitle :: LPCTSTR -> IO ()+setConsoleTitle title = failIfFalse_ "setConsoleTitle" $ cSetConsoleTitle title fillConsoleOutputAttribute :: HANDLE -> WORD -> DWORD -> COORD -> IO DWORD
ansi-terminal.cabal view
@@ -1,10 +1,10 @@ Name: ansi-terminal-Version: 0.4.0+Version: 0.5.0 Cabal-Version: >= 1.2 Category: User Interfaces Synopsis: Simple ANSI terminal support, with Windows compatibility-Description: ANSI terminal support for Haskell: allows cursor movement, screen clearing, color output and showing or hiding the cursor.- Compatible with Windows and those Unixes with ANSI terminals, but only GHC is supported as a compiler.+Description: ANSI terminal support for Haskell: allows cursor movement, screen clearing, color output showing or hiding the cursor, and+ changing the title. Compatible with Windows and those Unixes with ANSI terminals, but only GHC is supported as a compiler. License: BSD3 License-File: LICENSE Extra-Source-Files: README.textile
includes/Common-Include.hs view
@@ -111,3 +111,17 @@ hideCursor = hHideCursor stdout showCursor = hShowCursor stdout+++-- | Set the terminal window title+hSetTitle :: Handle+ -> String -- ^ New title+ -> IO ()+-- | Set the terminal window title+setTitle :: String -- ^ New title+ -> IO ()+-- | Set the terminal window title+setTitleCode :: String -- ^ New title+ -> String++setTitle = hSetTitle stdout
includes/Exports-Include.hs view
@@ -42,4 +42,9 @@ -- * Cursor visibilty changes hideCursor, showCursor, hHideCursor, hShowCursor,-hideCursorCode, showCursorCode+hideCursorCode, showCursorCode,++-- * Changing the title+setTitle,+hSetTitle,+setTitleCode