MyGit

UnkindPartition/ansi-terminal

Fork: 27 Star: 110 (更新于 2024-11-25 19:31:58)

license: BSD-3-Clause

Language: Haskell .

ANSI terminal support for Haskell, with Windows compatibility

GitHub网址

ansi-terminal and ansi-terminal-types GitHub CI

Haskell packages together providing support for 'ANSI' control character sequences for terminals on Unix-like operating systems and Windows

Description

'ANSI' terminal escape code support for Haskell, which allows:

  • Colored text output, with control over foreground, background and (where supported) underlining colors
  • Clearing parts of a line or the screen
  • 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
  • Changing the title of the terminal

If you like this, you may be interested in ansi-wl-pprint, which provides a pretty-printer that can construct strings containing 'ANSI' colorisation.

Not all 'ANSI' escape codes are suported by this library but most (if not all) of the popular ones that are well-supported by terminal software are, including:

  • Select Graphic Rendition mode (colors and other attributes): setSGR
  • Clearing parts of the screen: clearFromCursorToScreenEnd, clearFromCursorToScreenBeginning, clearScreen, clearFromCursorToLineEnd, clearFromCursorToLineBeginning and clearLine
  • Cursor visibility changes: hideCursor and showCursor
  • Cursor movement by character: cursorUp, cursorDown, cursorForward and cursorBackward
  • Cursor movement by line: cursorUpLine and cursorDownLine
  • 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

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 escape code to stdout and any terminal attached to it
  • An IO variant similar to above, but which takes a Handle to which the escape code should be applied
  • A String variant that returns a literal string that should be included to get the effect of the code.

Example

A full example is available, but for a taste of how the library works try the following code:

import System.Console.ANSI
import System.IO (stdout)

main :: IO ()
main = do
  stdoutSupportsANSI <- hNowSupportsANSI stdout
  if stdoutSupportsANSI
    then do
      setCursorPosition 5 0
      setTitle "ANSI Terminal Short Example"

      setSGR [ SetConsoleIntensity BoldIntensity
             , SetColor Foreground Vivid Red
             ]
      putStr "Hello"

      setSGR [ SetConsoleIntensity NormalIntensity
             , SetColor Foreground Vivid White
             , SetColor Background Dull Blue
             ]
      putStrLn "World!"
    else
      putStrLn "Standard output does not support 'ANSI' escape codes."

Documentation

Haddock documentation is available at Hackage (ansi-terminal) and (ansi-terminal-types).

Credits

The library was originally written by Max Bolingbroke

Maintainers

Mike Pilgrem and Roman Cheplyaka are the primary maintainers.

Oliver Charles is the backup maintainer. Please get in touch with him if the primary maintainers cannot be reached.

最近版本更新:(数据更新于 2024-10-12 12:20:48)

UnkindPartition/ansi-terminal同语言 Haskell最近更新仓库

2024-08-22 12:09:58 ivanperez-keera/dunai

2024-05-25 09:59:31 reflex-frp/reflex-vty

2024-05-05 03:36:38 PostgREST/postgrest

2023-11-11 06:13:10 clash-lang/clash-compiler

2022-08-13 21:55:30 HeinrichApfelmus/reactive-banana

2016-10-03 14:00:16 z0w0/helm