From: Darren Date: Mon, 4 Nov 2013 16:51:04 +0000 (+0000) Subject: Font formatting + colours in sent message (xchats %Cn format) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b166c1acd943e60461ea07bec874861e0a9f24b1;p=KiwiIRC.git Font formatting + colours in sent message (xchats %Cn format) --- diff --git a/client/src/helpers/utils.js b/client/src/helpers/utils.js index a9624e4..8931c87 100644 --- a/client/src/helpers/utils.js +++ b/client/src/helpers/utils.js @@ -214,6 +214,30 @@ function hsl2rgb(h, s, l) { } +/** + * Formats a kiwi message to IRC format + */ +function formatToIrcMsg(message) { + // Format any colour codes (eg. $c4) + message = message.replace(/%C(\d)/ig, function(match, colour_number) { + return String.fromCharCode(3) + colour_number.toString(); + }); + + var formatters = { + B: '\x02', // Bold + I: '\x1D', // Italics + U: '\x1F', // Underline + O: '\x0F' // Out / Clear formatting + }; + message = message.replace(/%([BIUO])/ig, function(match, format_code) { + if (typeof formatters[format_code.toUpperCase()] !== 'undefined') + return formatters[format_code.toUpperCase()]; + }); + + return message; +} + + /** * Formats a message. Adds bold, underline and colouring * @param {String} msg The message to format diff --git a/client/src/models/application.js b/client/src/models/application.js index 05a282b..c1552e0 100644 --- a/client/src/models/application.js +++ b/client/src/models/application.js @@ -711,13 +711,15 @@ _kiwi.model.Application = function () { } function msgCommand (ev) { - var destination = ev.params[0], + var message, + destination = ev.params[0], panel = that.connections.active_connection.panels.getByName(destination) || that.panels().server; ev.params.shift(); + message = formatToIrcMsg(ev.params.join(' ')); - panel.addMsg(_kiwi.app.connections.active_connection.get('nick'), ev.params.join(' ')); - _kiwi.gateway.privmsg(null, destination, ev.params.join(' ')); + panel.addMsg(_kiwi.app.connections.active_connection.get('nick'), message); + _kiwi.gateway.privmsg(null, destination, message); } function actionCommand (ev) {