Parse colours in buffer title
Requires a WeeChat version including 013165209a
i.e., WeeChat 1.1 or a November 2014 nightly (or later)
(for previous versions, see https://github.com/weechat/weechat/issues/237)
Fixes #308
This commit is contained in:
parent
8eda79e2f3
commit
1d4caa91cd
4 changed files with 61 additions and 48 deletions
|
@ -215,7 +215,9 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel
|
||||||
</a>
|
</a>
|
||||||
<button ng-if="debugMode" ng-click="countWatchers()">Count<br />Watchers</button>
|
<button ng-if="debugMode" ng-click="countWatchers()">Count<br />Watchers</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="title" ng-bind-html="activeBuffer().title | linky:'_blank' | DOMfilter:'irclinky'" title="{{activeBuffer().title}}"></div>
|
<div class="title" title="{{activeBuffer().rtitle}}">
|
||||||
|
<span ng-repeat="part in activeBuffer().title" ng-class="::part.classes" ng-bind-html="::(part.text | linky:'_blank' | DOMfilter:'irclinky')"></span>
|
||||||
|
</div>
|
||||||
<div class="actions pull-right vertical-line-left">
|
<div class="actions pull-right vertical-line-left">
|
||||||
<div class="pull-left">
|
<div class="pull-left">
|
||||||
<a class="settings-toggle" ng-click="showModal('settingsModal')" title="Options menu">
|
<a class="settings-toggle" ng-click="showModal('settingsModal')" title="Options menu">
|
||||||
|
|
|
@ -64,8 +64,13 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific
|
||||||
var buffer = obj.pointers[0];
|
var buffer = obj.pointers[0];
|
||||||
var old = models.getBuffer(buffer);
|
var old = models.getBuffer(buffer);
|
||||||
old.fullName = obj.full_name;
|
old.fullName = obj.full_name;
|
||||||
old.title = obj.title;
|
old.title = models.parseRichText(obj.title);
|
||||||
old.number = obj.number;
|
old.number = obj.number;
|
||||||
|
|
||||||
|
old.rtitle = "";
|
||||||
|
for (var i = 0; i < old.title.length; ++i) {
|
||||||
|
old.rtitle += old.title[i].text;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var handleBufferRenamed = function(message) {
|
var handleBufferRenamed = function(message) {
|
||||||
|
|
96
js/models.js
96
js/models.js
|
@ -8,6 +8,48 @@
|
||||||
var models = angular.module('weechatModels', []);
|
var models = angular.module('weechatModels', []);
|
||||||
|
|
||||||
models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) {
|
models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) {
|
||||||
|
var parseRichText = function(text) {
|
||||||
|
var textElements = weeChat.Protocol.rawText2Rich(text),
|
||||||
|
typeToClassPrefixFg = {
|
||||||
|
'option': 'cof-',
|
||||||
|
'weechat': 'cwf-',
|
||||||
|
'ext': 'cef-'
|
||||||
|
},
|
||||||
|
typeToClassPrefixBg = {
|
||||||
|
'option': 'cob-',
|
||||||
|
'weechat': 'cwb-',
|
||||||
|
'ext': 'ceb-'
|
||||||
|
};
|
||||||
|
|
||||||
|
textElements.forEach(function(textEl) {
|
||||||
|
textEl.classes = [];
|
||||||
|
|
||||||
|
// foreground color
|
||||||
|
var prefix = typeToClassPrefixFg[textEl.fgColor.type];
|
||||||
|
textEl.classes.push(prefix + textEl.fgColor.name);
|
||||||
|
|
||||||
|
// background color
|
||||||
|
prefix = typeToClassPrefixBg[textEl.bgColor.type];
|
||||||
|
textEl.classes.push(prefix + textEl.bgColor.name);
|
||||||
|
|
||||||
|
// attributes
|
||||||
|
if (textEl.attrs.name !== null) {
|
||||||
|
textEl.classes.push('coa-' + textEl.attrs.name);
|
||||||
|
}
|
||||||
|
var attr, val;
|
||||||
|
for (attr in textEl.attrs.override) {
|
||||||
|
val = textEl.attrs.override[attr];
|
||||||
|
if (val) {
|
||||||
|
textEl.classes.push('a-' + attr);
|
||||||
|
} else {
|
||||||
|
textEl.classes.push('a-no-' + attr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return textElements;
|
||||||
|
};
|
||||||
|
this.parseRichText = parseRichText;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Buffer class
|
* Buffer class
|
||||||
*/
|
*/
|
||||||
|
@ -21,7 +63,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
var trimmedName = shortName.replace(/^[#&+]/, '') || (shortName ? ' ' : null);
|
var trimmedName = shortName.replace(/^[#&+]/, '') || (shortName ? ' ' : null);
|
||||||
// get channel identifier
|
// get channel identifier
|
||||||
var prefix = ['#', '&', '+'].indexOf(shortName.charAt(0)) >= 0 ? shortName.charAt(0) : '';
|
var prefix = ['#', '&', '+'].indexOf(shortName.charAt(0)) >= 0 ? shortName.charAt(0) : '';
|
||||||
var title = message.title;
|
var title = parseRichText(message.title);
|
||||||
var number = message.number;
|
var number = message.number;
|
||||||
var pointer = message.pointers[0];
|
var pointer = message.pointers[0];
|
||||||
var notify = 3; // Default 3 == message
|
var notify = 3; // Default 3 == message
|
||||||
|
@ -44,6 +86,11 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
notify = message.notify;
|
notify = message.notify;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rtitle = "";
|
||||||
|
for (var i = 0; i < title.length; ++i) {
|
||||||
|
rtitle += title[i].text;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adds a line to this buffer
|
* Adds a line to this buffer
|
||||||
*
|
*
|
||||||
|
@ -234,6 +281,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
prefix: prefix,
|
prefix: prefix,
|
||||||
number: number,
|
number: number,
|
||||||
title: title,
|
title: title,
|
||||||
|
rtitle: rtitle,
|
||||||
lines: lines,
|
lines: lines,
|
||||||
clear: clear,
|
clear: clear,
|
||||||
requestedLines: requestedLines,
|
requestedLines: requestedLines,
|
||||||
|
@ -268,53 +316,11 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
var date = message.date;
|
var date = message.date;
|
||||||
var shortTime = $filter('date')(date, 'HH:mm');
|
var shortTime = $filter('date')(date, 'HH:mm');
|
||||||
|
|
||||||
function addClasses(textElements) {
|
var prefix = parseRichText(message.prefix);
|
||||||
var typeToClassPrefixFg = {
|
|
||||||
'option': 'cof-',
|
|
||||||
'weechat': 'cwf-',
|
|
||||||
'ext': 'cef-'
|
|
||||||
};
|
|
||||||
var typeToClassPrefixBg = {
|
|
||||||
'option': 'cob-',
|
|
||||||
'weechat': 'cwb-',
|
|
||||||
'ext': 'ceb-'
|
|
||||||
};
|
|
||||||
textElements.forEach(function(textEl) {
|
|
||||||
textEl.classes = [];
|
|
||||||
|
|
||||||
// foreground color
|
|
||||||
var prefix = typeToClassPrefixFg[textEl.fgColor.type];
|
|
||||||
textEl.classes.push(prefix + textEl.fgColor.name);
|
|
||||||
|
|
||||||
// background color
|
|
||||||
prefix = typeToClassPrefixBg[textEl.bgColor.type];
|
|
||||||
textEl.classes.push(prefix + textEl.bgColor.name);
|
|
||||||
|
|
||||||
// attributes
|
|
||||||
if (textEl.attrs.name !== null) {
|
|
||||||
textEl.classes.push('coa-' + textEl.attrs.name);
|
|
||||||
}
|
|
||||||
var val;
|
|
||||||
for (var attr in textEl.attrs.override) {
|
|
||||||
val = textEl.attrs.override[attr];
|
|
||||||
if (val) {
|
|
||||||
textEl.classes.push('a-' + attr);
|
|
||||||
} else {
|
|
||||||
textEl.classes.push('a-no-' + attr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var prefix = weeChat.Protocol.rawText2Rich(message.prefix);
|
|
||||||
addClasses(prefix);
|
|
||||||
|
|
||||||
var tags_array = message.tags_array;
|
var tags_array = message.tags_array;
|
||||||
var displayed = message.displayed;
|
var displayed = message.displayed;
|
||||||
var highlight = message.highlight;
|
var highlight = message.highlight;
|
||||||
var content = weeChat.Protocol.rawText2Rich(message.message);
|
var content = parseRichText(message.message);
|
||||||
addClasses(content);
|
|
||||||
|
|
||||||
if (highlight) {
|
if (highlight) {
|
||||||
prefix.forEach(function(textEl) {
|
prefix.forEach(function(textEl) {
|
||||||
|
|
|
@ -52,7 +52,7 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', function($root
|
||||||
|
|
||||||
var activeBuffer = models.getActiveBuffer();
|
var activeBuffer = models.getActiveBuffer();
|
||||||
if (activeBuffer) {
|
if (activeBuffer) {
|
||||||
$rootScope.pageTitle = activeBuffer.shortName + ' | ' + activeBuffer.title;
|
$rootScope.pageTitle = activeBuffer.shortName + ' | ' + activeBuffer.rtitle;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue