You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

doc.go 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // written by Daniel Oaks <daniel@danieloaks.net>
  2. // released under the ISC license
  3. /*
  4. Package ircfmt handles IRC formatting codes, escaping and unescaping.
  5. This allows for a simpler representation of strings that contain colour codes,
  6. bold codes, and such, without having to write and handle raw bytes when
  7. assembling outgoing messages.
  8. This lets you turn raw IRC messages into our escaped versions, and turn escaped
  9. versions back into raw messages suitable for sending on IRC connections. This
  10. is designed to be used on things like PRIVMSG / NOTICE commands, MOTD blocks,
  11. and such.
  12. The escape character we use in this library is the dollar sign ("$"), along
  13. with the given escape characters:
  14. --------------------------------
  15. Name | Escape | Raw
  16. --------------------------------
  17. Dollarsign | $$ | $
  18. Bold | $b | 0x02
  19. Colour | $c | 0x03
  20. Monospace | $m | 0x11
  21. Reverse Colour | $v | 0x16
  22. Italic | $i | 0x1d
  23. Strikethrough | $s | 0x1e
  24. Underscore | $u | 0x1f
  25. Reset | $r | 0x0f
  26. --------------------------------
  27. Colours are escaped in a slightly different way, using the actual names of them
  28. rather than just the raw numbers.
  29. In our escaped format, the colours for the fore and background are contained in
  30. square brackets after the colour ("$c") escape. For example:
  31. Red foreground:
  32. Escaped: This is a $c[red]cool message!
  33. Raw: This is a 0x034cool message!
  34. Blue foreground, green background:
  35. Escaped: This is a $c[blue,green]rad message!
  36. Raw: This is a 0x032,3rad message!
  37. When assembling a raw message, we make sure to use the full colour code
  38. ("02" vs just "2") when it could become confused due to numbers just after the
  39. colour escape code. For instance, lines like this will be unescaped correctly:
  40. No number after colour escape:
  41. Escaped: This is a $c[red]cool message!
  42. Raw: This is a 0x034cool message!
  43. Number after colour escape:
  44. Escaped: This is $c[blue]20% cooler!
  45. Raw: This is 0x030220% cooler
  46. Here are the colour names and codes we recognise:
  47. --------------------
  48. Code | Name
  49. --------------------
  50. 00 | white
  51. 01 | black
  52. 02 | blue
  53. 03 | green
  54. 04 | red
  55. 05 | brown
  56. 06 | magenta
  57. 07 | orange
  58. 08 | yellow
  59. 09 | light green
  60. 10 | cyan
  61. 11 | light cyan
  62. 12 | light blue
  63. 13 | pink
  64. 14 | grey
  65. 15 | light grey
  66. 99 | default
  67. --------------------
  68. These other colours aren't given names:
  69. https://modern.ircdocs.horse/formatting.html#colors-16-98
  70. */
  71. package ircfmt