Skip to content

Giving rcirc correct and complete support for mIRC-style color and attribute codes

License

Notifications You must be signed in to change notification settings

aaron-em/rcirc-styles.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rcirc-styles.el

http://melpa.org/packages/rcirc-styles-badge.svg http://stable.melpa.org/packages/rcirc-styles-badge.svg https://travis-ci.org/aaron-em/rcirc-styles.el.svg

Giving rcirc correct and complete support for mIRC-style color and attribute codes

Copyright © 2016 Aaron Miller. All rights reversed. Share and Enjoy!

Last revision: Saturday, February 6, 2016, ca. 22:00.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Commentary

The de facto standard for IRC color codes, as originally implemented in mIRC, can be found at http://en.wikichip.org/wiki/irc/colors.

As may be expected from the context, it’s a bit ad hoc and not the easiest thing in the world to parse correctly, which may explain why a prior attempt to satisfy this use case, under the name of “rcirc-controls.el”, attempted to do so with a recondite yet woefully inadequate regexp.

Rather than attempt to fix the regexp, and even if successful make it even more incomprehensible than it started out being, I decided it’d be easier and more maintainable to write a string-walking parser.

So I did that. In addition to those cases supported in the previous library, this code correctly handles:

  • Background colors, including implicit backgrounds when a new code provides only a foreground color.
  • Colors at codes between 8 and 15 (and correct colors for codes < 8).
  • Color specifications implicitly terminated by EOL.
  • Color specifications implicitly terminated by new color specifications.
  • The ^O character terminating color specifications.

While I was at it, I noticed some areas in which the both the stock attribute markup function in rcirc, and the one provided in the previous library, could use improving.

So I did that too, and the following cases are now correctly handled:

  • Implicit termination of attribute markup by EOL.
  • ^V as the specifier for reverse video, rather than italics.
  • ^] as the specifier for italics.

There are a couple of attribute codes which I’ve only seen mentioned in a few places, and haven’t been able to confirm whether or how widely they’re used:

  • ^F for flashing text;
  • ^K for fixed-width text.

Since these appear to be so ill-used, I’m not terribly anxious to support them in rcirc, but they are on my radar. If you want one or both of these, open an issue!

As far as I’m aware, this code implements correct and, subject to the preceding caveats, complete support for mIRC colors and attributes. If I’ve missed something, let me know!

Usage

Once installed, this package will activate when (package-activate) is called in your init process. If you happen to have rcirc-controls.el installed, and it’s already been activated, then rcirc-styles will supersede it at that time.

You don’t need to do anything to see styled text sent by other IRC users in your channels; it’ll Just Work™.

If you want to send styled text of your own, you have a couple of methods available.

First, you can always just insert color and attribute codes directly: for example, C-q C-c 1 , 13 to insert the color code for black text on a pink background, or C-q C-b to insert the attribute code for bold text.

Second, you can use the convenience functions which rcirc-styles provides since version 1.3 for this purpose: rcirc-styles-insert-color and rcirc-styles-insert-attribute. Both are interactive functions, so can be invoked via M-x, and both provide completion of valid values and will not accept invalid ones.

Version 1.3 also introduces a convenience function, rcirc-styles-toggle-preview, for previewing styled input as it will appear once sent, so that you can see how your text will look before actually sending it. Invoke this function to toggle between editable input with literal style codes, and a read-only preview of the same input with styles applied.

All of these convenience functions are also bound to a keymap, rcirc-styles-map, which you can attach to a key sequence in rcirc-mode-map for additional convenice. For example, if you include in your init file

(define-key rcirc-mode-map (kbd “C-c C-s”) rcirc-styles-map)

then the following keybindings will be available in rcirc buffers:

  • C-c C-s C-c: insert a color code
  • C-c C-s C-a: insert an attribute code
  • C-c C-s C-p: toggle styled preview mode

In a future version, I plan to automate the binding to rcirc-mode-map and make it customizable; in the meantime, the above snippet should suffice for most purposes. (If you want to see customization implemented faster, comment on the relevant issue and ask!)

Also in a future version, I plan to add shortcut keybindings for commonly used attributes, so that e.g. C-c C-s b will insert the bold attribute code directly, rather than requiring all of C-c C-s C-a bold RET. (As above, if you want to see it faster, let me know!)

Release History

1.3.2

February 6, 2016 - Merge a pull request from @tarsius (Jonas Bernoulli) bringing rcirc-styles.el into compliance with best practices around testing in the Emacs Lisp community.

1.3.1

January 10, 2016 - Fix a bug wherein `rcirc-styles-insert-attribute` fails under Emacs 24.3 due to `try-completion` accepting different argument types from its Emacs 24.4 equivalent.

1.3

January 10, 2016 - Satisfy feature request for color and attribute code insertion functions; also, add toggle-able instant previewing of styled rcirc buffer input, so that you can see how it’ll look before you actually send it.

1.2

December 20, 2015 - Fix a bug on sequential attribute code handling.

1.1

July 20, 2015 - Fix a bunch of bugs, including a dependency on cl.el instead of the correct cl-lib.

1.0

July 20, 2015 - Initial release.

About

Giving rcirc correct and complete support for mIRC-style color and attribute codes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •