ansi-escape-codes (empty) → 0.1.0.0
raw patch · 6 files changed
+544/−0 lines, 6 filesdep +basesetup-changed
Dependencies added: base
Files
- ChangeLog.md +5/−0
- LICENSE +20/−0
- README.md +37/−0
- Setup.hs +2/−0
- ansi-escape-codes.cabal +70/−0
- src/AnsiEscapeCodes.hs +410/−0
+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Revision history for ansi-escape-codes++## 0.1.0.0 -- YYYY-mm-dd++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2017 Joe Gesualdo++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ README.md view
@@ -0,0 +1,37 @@+## ansi-escape-codes+> Haskell package to generate ANSI escape codes for styling strings in the terminal Edit++## Install+```+Coming soon...+```++## Usage+```haskell+import AnsiEscapeCodes++main :: IO ()+main = do+ putStr $+ "Hi"+ ++ (show (CursorForwardSequence 1))+ ++ (show (CursorForwardSequence 1))+ ++ "B"+ ++ (show (CursorForwardSequence 1))+ ++ (show (CursorForwardSequence 1))+ ++ "O"+ ++ (show (CursorForwardSequence 1))+ ++ (show (CursorForwardSequence 1))+ ++ "0"+```++## Test+```+Coming soon...+```++## API+Coming soon++## License+MIT © [Joe Gesualdo]()
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ ansi-escape-codes.cabal view
@@ -0,0 +1,70 @@+-- Initial ansi-escape-codes.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/++-- The name of the package.+name: ansi-escape-codes++-- The package version. See the Haskell package versioning policy (PVP) +-- for standards guiding when and how versions should be incremented.+-- https://wiki.haskell.org/Package_versioning_policy+-- PVP summary: +-+------- breaking API changes+-- | | +----- non-breaking API additions+-- | | | +--- code changes with no API change+version: 0.1.0.0++-- A short (one-line) description of the package.+synopsis: Haskell package to generate ANSI escape codes for styling strings in the terminal.++-- A longer description of the package.+-- description: ++-- URL for the project homepage or repository.+homepage: https://github.com/joegesualdo/ansi-escape-codes++-- The license under which the package is released.+license: MIT++-- The file containing the license text.+license-file: LICENSE++-- The package author(s).+author: Joe Gesualdo++-- An email address to which users can send suggestions, bug reports, and +-- patches.+maintainer: joegesualdo@gmail.com++-- A copyright notice.+-- copyright: ++-- category: ++build-type: Simple++-- Extra files to be distributed with the package, such as examples or a +-- README.+extra-source-files: ChangeLog.md, README.md++-- Constraint on the version of Cabal needed to build this package.+cabal-version: >=1.10+++library+ -- Modules exported by the library.+ exposed-modules: AnsiEscapeCodes+ + -- Modules included in this library but not exported.+ -- other-modules: + + -- LANGUAGE extensions used by modules in this package.+ -- other-extensions: + + -- Other library packages from which modules are imported.+ build-depends: base >=4.10 && <4.11+ + -- Directories containing source files.+ hs-source-dirs: src+ + -- Base language which the package is written in.+ default-language: Haskell2010+
+ src/AnsiEscapeCodes.hs view
@@ -0,0 +1,410 @@+module AnsiEscapeCodes where++import Data.List (intercalate)++-- RESOURCES+-- https://en.wikipedia.org/wiki/ANSI_escape_code+-- http://book.realworldhaskell.org/read/characters-strings-and-escaping-rules.html++-- Types ----------------------------------------------------++-- Reference: http://book.realworldhaskell.org/read/characters-strings-and-escaping-rules.html+data ASCIIControlCode =+ NullCode+ | StartOfHeadingCode+ | StartOfTextCode+ | EndofTextCode+ | EndOfTransmissionCode+ | EnquiryCode+ | AcknowledgeCode+ | BellCode+ | BackspaceCode+ | HorizontalTabCode+ | LineFeedCode+ | VerticalTabCode+ | FormFeedCode+ | CarriageReturnCode+ | ShiftOutCode+ | ShiftInCode+ | DataLinkEscapeCode+ | DeviceControlOneCode+ | DeviceControlTwoCode+ | DeviceControlThreeCode+ | DeviceControlFourCode+ | NegativeAcknowledgeCode+ | SynchronousIdleCode+ | EndOfTransmissionBlockCode+ | CancelCode+ | EndOfMediumCode+ | SubsituteCode+ | EscapeCode+ | FileSeperatorCode+ | GroupSeperatorCode+ | RecordSeperatorCode+ | UnitSeperatorCode+ | SpaceCode+ | DeleteCode++-- TODO: Implement for the rest of the CSIParameters+data CSIParameter =+ CursorUpParameter Integer+ | CursorDownParameter Integer+ | CursorForwardParameter Integer+ | CursorBackParameter Integer+ | CursorNextLineParameter Integer+ | CursorPreviousLineParameter Integer+ | CursorHorizontalAbsoluteParameter Integer+ | CursorPositionParameter Integer Integer+ | EraseScreenAfterCursorParameter+ | EraseScreenBeforeCursorParameter+ | EraseScreenParameter+ | EraseScreenAndScrollbackParameter+ | EraseLineAfterCursorParameter+ | EraseLineBeforeCursorParameter+ | EraseLineParameter+ | ScrollUpParameter Integer+ | ScrollDownParameter Integer+ | HorizontalVerticalPositionParameter Integer Integer+ | SelectGraphicRenditionSequenceParameter [SelectGraphicRenditionParameter]+ | AUXPortOnParameter+ | AUXPortOffParameter+ | DeviceStatusReportParameter+ | SaveCursorPositionParameter+ | RestoreCursorPositionParameter++data SelectGraphicRenditionParameter =+ ResetNormalParameter+ | BoldParameter+ | IncreasedSensitivityParameter+ | FaintParameter+ | DecreasedSensitivityParameter+ | ItalicParameter+ | UnderlineParameter+ | SlowBlinkParameter+ | RapidBlinkParameter+ | ReverseVideoParameter+ | ConcealParameter+ | CrossedOutParameter+ | PrimaryFontParameter+ | DefaultFontParameter+ | AlternativeFontParameter Int+ | FrakturParameter+ | BoldOffParameter+ | DoubleUnderlineParameter+ | NormalColorParameter+ | NormalIntensityParameter+ | NotItalicParameter+ | NotFrakturParameter+ | UnderlineOffParameter+ | BlinkOffParameter+ | InverseOffParameter+ | RevealParameter+ | NotCrossedOutParameter+ | SetForegroundColorParameter ForegroundColor+ | DefaultForegroundColorParameter+ | SetBackgroundColorParameter BackgroundColor+ | DefaultBackgroundColorParameter+ | FramedParameter+ | EncircledParameter+ | OverlinedParameter+ | NotFramedParameter+ | NotEncircledParameter+ | NotOverlinedParameter+ | IdeogramUnderlineParameter+ | RightSideLineParameter+ | IdeogramDoubleUnderlineParameter+ | DoubleLIneOnRightSideParameter+ | IdeogramStressMarkingParameter+ | IdeogramAttributesOffParameter+ | SetBrightForegroundColorParameter BrightForegroundColor+ | SetBrightBackgroundColorParameter BrightBackgroundColor++data ForegroundColor =+ BlackForeground+ | RedForeground+ | GreenForeground+ | YellowForeground+ | BlueForeground+ | MagentaForeground+ | CyanForeground+ | WhiteForeground+ | ForegroundColor Color++data BrightForegroundColor =+ BrightBlackForeground+ | BrightRedForeground+ | BrightGreenForeground+ | BrightYellowForeground+ | BrightBlueForeground+ | BrightMagentaForeground+ | BrightCyanForeground+ | BrightWhiteForeground++data BackgroundColor =+ BlackBackground+ | RedBackground+ | GreenBackground+ | YellowBackground+ | BlueBackground+ | MagentaBackground+ | CyanBackground+ | WhiteBackground+ | BackgroundColor Color++data BrightBackgroundColor =+ BrightBlackBackground+ | BrightRedBackground+ | BrightGreenBackground+ | BrightYellowBackground+ | BrightBlueBackground+ | BrightMagentaBackground+ | BrightCyanBackground+ | BrightWhiteBackground++data Color =+ Color256 Integer-- TODO: Validate only integers 1-256+ | RGB Integer Integer Integer -- TODO: Validate only integers 1-256++data EscapeSequence =+ CursorUpSequence Integer+ | CursorDownSequence Integer+ | CursorForwardSequence Integer+ | CursorBackSequence Integer+ | CursorNextLineSequence Integer+ | CursorPreviousLineSequence Integer+ | CursorHorizontalAbsoluteSequence Integer+ | CursorPositionSequence Integer Integer+ | EraseScreenAfterCursorSequence+ | EraseScreenBeforeCursorSequence+ | EraseScreenSequence+ | EraseScreenAndScrollbackSequence+ | EraseLineAfterCursorSequence+ | EraseLineBeforeCursorSequence+ | EraseLineSequence+ | ScrollUpSequence Integer+ | ScrollDownSequence Integer+ | HorizontalVerticalPositionSequence Integer Integer+ | SelectGraphicRenditionSequence [SelectGraphicRenditionParameter]+ | AUXPortOnSequence+ | AUXPortOffSequence+ | DeviceStatusReportSequence+ | SaveCursorPositionSequence+ | RestoreCursorPositionSequence+ | ResetColorsSequence+ | ResetAttributesSequence++data EscapeSequenceEntry = EscapeSequenceEntry++-- Instances ----------------------------------------------------++-- TODO: Implement for the rest of the ASCIIControlCodes+instance Show ASCIIControlCode where+ show EscapeCode = "\x001b"+ show _ = error "That Ascii Control Code doesn't exist"++instance Show EscapeSequenceEntry where+ show _ = (show EscapeCode) ++ "["++instance Show CSIParameter where+ show (CursorUpParameter moveCount) = (show moveCount) ++ "A"+ show (CursorDownParameter moveCount) = (show moveCount) ++ "B"+ show (CursorForwardParameter moveCount) = (show moveCount) ++ "C"+ show (CursorBackParameter moveCount) = (show moveCount) ++ "D"+ show (CursorNextLineParameter moveCount) = (show moveCount) ++ "E"+ show (CursorPreviousLineParameter moveCount) = (show moveCount) ++ "F"+ show (CursorHorizontalAbsoluteParameter moveCount) = (show moveCount) ++ "F"+ show (CursorPositionParameter rowPosition columnPosition) = (show rowPosition) ++ ";" ++ (show columnPosition) ++ "H"+ show EraseScreenAfterCursorParameter = "0J"+ show EraseScreenBeforeCursorParameter = "1J"+ show EraseScreenParameter = "2J"+ show EraseScreenAndScrollbackParameter= "3J"+ show EraseLineAfterCursorParameter = "0K"+ show EraseLineBeforeCursorParameter = "1K"+ show EraseLineParameter = "2K"+ show (ScrollUpParameter moveCount) = (show moveCount) ++ "S"+ show (ScrollDownParameter moveCount) = (show moveCount) ++ "T"+ show (HorizontalVerticalPositionParameter rowPosition columnPosition) = (show rowPosition) ++ ";" ++ (show columnPosition) ++ "f"+ show (SelectGraphicRenditionSequenceParameter sgrParameters) = (intercalate ";" $ map show sgrParameters) ++ "m"+ show (AUXPortOnParameter) = "5i"+ show (AUXPortOffParameter) = "4i"+ show (DeviceStatusReportParameter) = "6n" -- This is probably wrong+ show (SaveCursorPositionParameter) = "s"+ show (RestoreCursorPositionParameter) = "u"++instance Show SelectGraphicRenditionParameter where+ show ResetNormalParameter = "0"+ show BoldParameter = "1"+ show IncreasedSensitivityParameter = "1"+ show FaintParameter = "2"+ show DecreasedSensitivityParameter = "2"+ show ItalicParameter = "3"+ show UnderlineParameter = "4"+ show SlowBlinkParameter = "5"+ show RapidBlinkParameter = "6"+ show ReverseVideoParameter = "7"+ show ConcealParameter = "8"+ show CrossedOutParameter = "9"+ show PrimaryFontParameter = "10"+ show DefaultFontParameter = "10"+ show (AlternativeFontParameter x) = (show x) -- TODO: x should only be 11-19+ show FrakturParameter = "20"+ show BoldOffParameter = "21"+ show DoubleUnderlineParameter = "21"+ show NormalColorParameter = "22"+ show NormalIntensityParameter = "22"+ show NotItalicParameter = "23"+ show NotFrakturParameter = "23"+ show UnderlineOffParameter = "24"+ show BlinkOffParameter = "25"+ show InverseOffParameter = "27"+ show RevealParameter = "28"+ show NotCrossedOutParameter = "29"+ show (SetForegroundColorParameter (ForegroundColor (RGB redColorCode greenColorCode blueColorCode))) = "38;" ++ (show (ForegroundColor (RGB redColorCode greenColorCode blueColorCode)))+ show (SetForegroundColorParameter (ForegroundColor (Color256 colorCode256))) = "38;" ++ (show (ForegroundColor (Color256 colorCode256)))+ show (SetForegroundColorParameter color) = (show color)+ show DefaultForegroundColorParameter = "39"++instance Show ForegroundColor where+ show BlackForeground = "30"+ show RedForeground = "31"+ show GreenForeground = "32"+ show YellowForeground = "33"+ show BlueForeground = "34"+ show MagentaForeground = "35"+ show CyanForeground = "36"+ show WhiteForeground = "37"+ show (ForegroundColor (Color256 colorCode)) = "5;" ++ (show colorCode)+ show (ForegroundColor (RGB redColorCode greenColorCode blueColorCode)) = "2;" ++ (show redColorCode) ++ ";" ++ (show greenColorCode) ++ ";" ++ (show blueColorCode)++instance Show BackgroundColor where+ show BlackBackground = "40"+ show RedBackground = "41"+ show GreenBackground = "42"+ show YellowBackground = "43"+ show BlueBackground = "44"+ show MagentaBackground = "45"+ show CyanBackground = "46"+ show WhiteBackground = "47"+ show (BackgroundColor (Color256 colorCode)) = "5;" ++ (show colorCode)+ show (BackgroundColor (RGB redColorCode greenColorCode blueColorCode)) = "2;" ++ (show redColorCode) ++ ";" ++ (show greenColorCode) ++ ";" ++ (show blueColorCode)++instance Show BrightForegroundColor where+ show BrightBlackForeground = "1;30"+ show BrightRedForeground = "1;31"+ show BrightGreenForeground = "1;32"+ show BrightYellowForeground = "1;33"+ show BrightBlueForeground = "1;34"+ show BrightMagentaForeground = "1;35"+ show BrightCyanForeground = "1;36"+ show BrightWhiteForeground = "1;37"++instance Show BrightBackgroundColor where+ show BrightBlackBackground = "100"+ show BrightRedBackground = "101"+ show BrightGreenBackground = "102"+ show BrightYellowBackground = "103"+ show BrightBlueBackground = "104"+ show BrightMagentaBackground = "105"+ show BrightCyanBackground = "106"+ show BrightWhiteBackground = "107"++instance Show EscapeSequence where+ show (CursorUpSequence moveCount) =+ (show EscapeSequenceEntry)+ ++ (show (CursorUpParameter moveCount))+ show (CursorDownSequence moveCount) =+ (show EscapeSequenceEntry)+ ++ (show (CursorDownParameter moveCount))+ show (CursorForwardSequence moveCount) =+ (show EscapeSequenceEntry)+ ++ (show (CursorForwardParameter moveCount))+ show (CursorBackSequence moveCount) =+ (show EscapeSequenceEntry)+ ++ (show (CursorBackParameter moveCount))+ show (CursorNextLineSequence moveCount) =+ (show EscapeSequenceEntry)+ ++ (show (CursorNextLineParameter moveCount))+ show (CursorPreviousLineSequence moveCount) =+ (show EscapeSequenceEntry)+ ++ (show (CursorPreviousLineParameter moveCount))+ show (CursorHorizontalAbsoluteSequence moveCount) =+ (show EscapeSequenceEntry)+ ++ (show (CursorHorizontalAbsoluteParameter moveCount))+ show (CursorPositionSequence rowPosition columnPosition) =+ (show EscapeSequenceEntry)+ ++ (show (CursorPositionParameter rowPosition columnPosition))+ show (EraseScreenAfterCursorSequence) =+ (show EscapeSequenceEntry)+ ++ (show (EraseScreenAfterCursorParameter))+ show (EraseScreenBeforeCursorSequence) =+ (show EscapeSequenceEntry)+ ++ (show (EraseScreenBeforeCursorParameter))+ show (EraseScreenSequence) =+ (show EscapeSequenceEntry)+ ++ (show (EraseScreenParameter))+ show (EraseScreenAndScrollbackSequence) =+ (show EscapeSequenceEntry)+ ++ (show (EraseScreenAndScrollbackParameter))+ show (EraseLineAfterCursorSequence) =+ (show EscapeSequenceEntry)+ ++ (show (EraseLineAfterCursorParameter))+ show (EraseLineBeforeCursorSequence) =+ (show EscapeSequenceEntry)+ ++ (show (EraseLineBeforeCursorParameter))+ show (EraseLineSequence) =+ (show EscapeSequenceEntry)+ ++ (show (EraseLineParameter))+ show (ScrollUpSequence moveCount) =+ (show EscapeSequenceEntry)+ ++ (show (ScrollUpParameter moveCount))+ show (ScrollDownSequence moveCount) =+ (show EscapeSequenceEntry)+ ++ (show (ScrollDownParameter moveCount))+ show (HorizontalVerticalPositionSequence rowPosition columnPosition) =+ (show EscapeSequenceEntry)+ ++ (show (HorizontalVerticalPositionParameter rowPosition columnPosition))+ show (SelectGraphicRenditionSequence srgParameters) =+ (show EscapeSequenceEntry)+ ++ (show (SelectGraphicRenditionSequenceParameter srgParameters))+ show (AUXPortOnSequence) =+ (show EscapeSequenceEntry)+ ++ (show (AUXPortOnParameter))+ show (AUXPortOffSequence) =+ (show EscapeSequenceEntry)+ ++ (show (AUXPortOffParameter))+ show (DeviceStatusReportSequence) =+ (show EscapeSequenceEntry)+ ++ (show (DeviceStatusReportParameter))+ show (SaveCursorPositionSequence) =+ (show EscapeSequenceEntry)+ ++ (show (SaveCursorPositionParameter))+ show (RestoreCursorPositionSequence) =+ (show EscapeSequenceEntry)+ ++ (show (RestoreCursorPositionParameter))+ show (ResetAttributesSequence) =+ (show EscapeCode)+ ++ "[0m"+ show (ResetColorsSequence) =+ (show EscapeCode)+ ++ "[39;49m"++-- -- Main -------------------------------------------------+-- main :: IO ()+-- main = do+-- putStr $+-- "Hi"+-- ++ (show (CursorForwardSequence 1))+-- ++ (show (CursorForwardSequence 1))+-- ++ "B"+-- ++ (show (CursorForwardSequence 1))+-- ++ (show (CursorForwardSequence 1))+-- ++ "O"+-- ++ (show (CursorForwardSequence 1))+-- ++ (show (CursorForwardSequence 1))+-- ++ "0"++ -- (show (SelectGraphicRenditionSequence [UnderlineParameter, (SetForegroundColorParameter (ForegroundColor (RGB 177 209 174)))]))+ -- putStr $+ -- (show (CursorDownSequence 3)) ++ "Bro" +++ -- (show (CursorNextLineSequence 1)) ++ "meow\n"+