< Day Day Up > |
Hack 21 Format Text
IRC does not limit you to using plain text. Add extra formatting, such as underlining and italics, to your messages. Even though most IRC clients support color, simpler formatting can sometimes be more effective. Too much use of color tends to annoy people. In such circumstance, channel operators have at their disposal the option of banning the use of color. If this happens, it will still be possible to send messages with simpler formatting. To highlight a particular word in a message, you could underline it. To catch somebody's attention, you could make your message bold. To emphasize something, you could make it italic. All of these options are possible, regardless of channel restrictions. 4.6.1 Formatting Text in mIRCmIRC lets you view and send formatted text. Many other IRC clients behave in similar ways. Three main types of text formatting are available from mIRC. All of these can be accessed by keyboard shortcuts. These styles are complementary, so you can make text both bold and underlined, for example. 4.6.1.1 BoldWhen composing a line or message, the text can be formatted as bold by pressing Ctrl-B. You will see a control character appear in your message. Anything you type after this will appear in bold. You will not see the result of this until you actually send your message to the server. 4.6.1.2 UnderlineYou can underline part of your message by pressing Ctrl-U. This will cause a control character to be inserted into your message. Everything after this character will be underlined. 4.6.1.3 Italic or reversedItalic text can also be used. However, because some clients are incapable of rendering italic text, you will find that most clients (including those that can render italic text) display this as normal text with the background and foreground colors swapped. For this reason, it is also known as reversed text formatting and can be achieved in mIRC by pressing Ctrl-R. 4.6.1.4 NormalTo return text to its unformatted state, press Ctrl-O. This removes all formatting, even if more than one style has been applied. Combinations of these options are illustrated in Figure 4-14. Figure 4-14. Combinations of formatting rendered by mIRC4.6.2 Formatting Text with a BotFormatting text with the aforementioned attributes is simpler than applying colors, as only one control character is required for each style. There are no parameters to add after each style character. 4.6.2.1 BoldBold text can be achieved by prefixing the text with ASCII character 0x02, which can be represented in Unicode as \u0002. The following Java code creates a bold IRC message: String bold = "\u0002This is bold"; 4.6.2.2 UnderlineText can be underlined with ASCII character 0x1F, which can be represented in Unicode as \u001F. String underlined = "\u001FThis is underlined"; 4.6.2.3 Italic or reversedItalic or reversed text is formatted with ASCII character 0x16, or Unicode character \u0016. String reversed = "\u0016This is reversed"; 4.6.2.4 NormalTo remove all formatting from a message, use ASCII character 0x0F, or Unicode character \u000F. Any text after this point in the message will return to its normal state, unless other formatting characters are applied again. String mixture = "\u0002Bold\u000F and gone"; 4.6.3 Formatting Text with PircBotThe Colors class in the PircBot Java IRC API [Hack #35] contains useful constants, not only for coloring, but also for formatting text with these styles. Using these is probably easier than remembering the Unicode characters. String bold = Colors.BOLD + "This is bold"; String underlined = Colors.UNDERLINE + "This is underlined"; String reversed = Colors.REVERSE + "This is reversed"; String mixture = Colors.BOLD + "Bold" + Colors.NORMAL + " and gone";
Some of the bots covered later in this book use bold formatting to make parts of messages stand out more clearly. |
< Day Day Up > |