termonad.hs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. {-# LANGUAGE OverloadedStrings #-}
  2. module Main where
  3. import Data.Singletons (Sing, sing)
  4. import Termonad.App (defaultMain)
  5. import Termonad.Config
  6. ( FontConfig, FontSize(FontSizePoints), Option(Set)
  7. , ShowScrollbar(ShowScrollbarAlways), defaultConfigOptions, defaultFontConfig
  8. , defaultTMConfig, fontConfig, fontFamily, fontSize, options, showScrollbar, showMenu
  9. )
  10. import Termonad.Config.Colour
  11. ( AlphaColour, ColourConfig, addColourExtension, createColour
  12. , createColourExtension, cursorBgColour, defaultColourConfig, Palette(ExtendedPalette), foregroundColour, palette
  13. )
  14. import Termonad.Config.Vec
  15. ( N4, N8, Vec((:*), EmptyVec), fin_, setAtVec, unsafeFromListVec_
  16. )
  17. -- | This sets the color of the cursor in the terminal.
  18. --
  19. -- This uses the "Data.Colour" module to define a dark-red color.
  20. -- There are many default colors defined in "Data.Colour.Names".
  21. cursBgColour :: AlphaColour Double
  22. cursBgColour = createColour 204 0 0
  23. -- -- | This sets the colors used for the terminal. We only specify the background
  24. -- -- color of the cursor.
  25. -- colConf :: ColourConfig (AlphaColour Double)
  26. -- colConf =
  27. -- defaultColourConfig
  28. -- { cursorBgColour = Set cursBgColour
  29. -- }
  30. myColourConfig =
  31. defaultColourConfig
  32. -- Set the cursor background colour. This is the normal colour of the
  33. -- cursor.
  34. { cursorBgColour = Set (createColour 218 112 214) -- orchid
  35. -- Set the default foreground colour of text of the terminal.
  36. , foregroundColour = Set (createColour 255 255 255) -- white
  37. -- Set the extended palette that has 8 colours standard colors and then 8
  38. -- light colors.
  39. , palette = ExtendedPalette myStandardColours myLightColours
  40. }
  41. where
  42. -- This is a an example of creating a length-indexed linked-list of colours,
  43. -- using 'Vec' constructors.
  44. myStandardColours :: Vec N8 (AlphaColour Double)
  45. myStandardColours =
  46. createColour 0 0 0 -- dark brown (used as background colour)
  47. :* createColour 178 24 24
  48. :* createColour 102 205 0
  49. :* createColour 178 104 24
  50. :* createColour 65 105 225
  51. :* createColour 178 24 178
  52. :* createColour 24 178 178
  53. :* createColour 178 178 178
  54. :* EmptyVec
  55. -- This is an example of creating a length-indexed linked-list of colours,
  56. -- using the 'unsafeFromListVec_' function. 'unsafeFromListVec_' is okay to
  57. -- use as long as you're absolutely sure you have 8 elements.
  58. myLightColours :: Vec N8 (AlphaColour Double)
  59. myLightColours =
  60. unsafeFromListVec_
  61. [ createColour 104 104 104
  62. , createColour 255 84 84
  63. , createColour 84 255 84
  64. , createColour 238 201 0
  65. , createColour 84 84 255
  66. , createColour 255 84 255
  67. , createColour 84 255 255
  68. , createColour 255 255 255
  69. ]
  70. -- This is an example of updating just a single value in a 'Colour' 'Vec'.
  71. -- Here we are updating the 5th 'Colour' (which is at index 4).
  72. _updateSingleColor :: Vec N8 (AlphaColour Double)
  73. _updateSingleColor =
  74. let fin4 = fin_ (sing :: Sing N4)
  75. in setAtVec fin4 (createColour 40 30 150) myStandardColours
  76. -- | This defines the font for the terminal.
  77. fontConf :: FontConfig
  78. fontConf =
  79. defaultFontConfig
  80. { fontFamily = "DejaVu Sans Mono"
  81. , fontSize = FontSizePoints 13
  82. }
  83. main :: IO ()
  84. main = do
  85. colExt <- createColourExtension myColourConfig
  86. let termonadConf =
  87. defaultTMConfig
  88. { options =
  89. defaultConfigOptions
  90. { fontConfig = fontConf
  91. -- Make sure the scrollbar is always visible.
  92. , showScrollbar = ShowScrollbarAlways
  93. , showMenu = False
  94. }
  95. }
  96. `addColourExtension` colExt
  97. defaultMain termonadConf