🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #191220

[slrn] very easy display filter enabling colour in message body

#191220
From: Troy Piggins
Date: Mon, 02 Oct 2006 03:09
96 lines
4373 bytes
I've been using a demime and t-prot display filter for some time
to tidy up MIME pgp signed and html messages, and trimming long
quote blocks, trimming overly long sigs etc.  All good.

I just recently started playing with my own display filter to
take it all one step further to fix some things like improper sig
delimiters etc using a sed script.  I got that working and
thought I'd share.  It's very customisable.

While playing with it I had a thought about colours (that's the
same as colors, but with a 'u' in it like there should be ;-) ).
One of the things that frustrate me with slrn is that you can't
colour the body of a message for anything other than slrn's
inbuilt options - emphasis, bold, url's etc.

Well guess what, with my new homemade display filter you can.
Sort of.  Just create a sed expression to change the text you
want coloured into /emphasis/, *bold*, or _underline_.

eg, say I want to colour my name in the message body.  I add this
entry into my display filter:

sed -e '
s/Troy Piggins/*&*/
# other substitutions can go here too!
# eg fix incorrect sig delimiters
s/^--$/-- /
'

This changes my name to *Troy Piggins* in the message body.

I saved the above as a bash script in $HOME/bin/slrn_display_filter
then 'interpret $HOME/.slrn/display_filter.sl' in my
$HOME/.slrnrc :

%variable tmpdir = "$HOME/.tmpdir"; % you better make sure it
%exists

define display_filter () {

variable display_filter_tmp, raw_art, fp, art_display_filter;
  display_filter_tmp = "/tmp/slrn_display_filter."+ string (getpid () );
  raw_art = raw_article_as_string ();
  fp = fopen (display_filter_tmp, "w");
  if (fp == NULL)
    error (_function_name () +": could not open "+display_filter_tmp);
  fputs (raw_art, fp);
  fclose (fp);
  fp = popen ("/home/troy/bin/slrn_display_filter - < "+display_filter_tmp, "r");
  if (fp == NULL)
    error (_function_name () +": display_filter pipe failed" );
  art_display_filter = strjoin (fgetslines (fp), "");
  pclose (fp);
  if (art_display_filter != "") replace_article (art_display_filter);
  else error (_function_name () +": failed");
  system ("rm "+display_filter_tmp);

}

define register_display_filters () {
  () = register_hook ("read_article_hook", "display_filter");
}

define unregister_display_filters () {
  () = unregister_hook ("read_article_hook", "display_filter");
}

register_display_filters ();

definekey ("register_display_filters", "\e6", "article");
definekey ("unregister_display_filters", "\e7", "article");

I have set set emphasized_text_mask 1 and
set emphasized_text_mode 1
so I don't see the *, / or _

It's very rudimentary at the moment.  I'd appreciate comments or
help to take it further.

There are some limitations - I tried sed script for smiley faces
like :) to change to /:)/ but slrn's inbuilt emphasis detection
algorithm doesn't seem to like the colons or something.

Also if you followup a filtered message, it's the filtered
message that is quoted not the original, because the macro
replaces the article (not on the server, just viewed).  You can
turn off the filter by hitting <esc>-7 or whatever you assign
unregister_display_filters to.

Hope the above makes sense.  If not, just ask.

-- 
Troy Piggins
 ,-o
o   ) Ubuntu linux 6.06 http://ubuntu.com  RLU#415538 http://counter.li.org
 `-o  uptime: 12:37:32 up 21 days,18:06,2 users,load average:0.00,0.00,0.00
Technical Details
Message-ID: <20061002123732@usenet.piggo.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed.iinet.net.au!newsfeed.iinet.net.au!per-qv1-newsstorage1.iinet.net.au!per-qv1-newsstorage1.iinet.net.au!per-qv1-newsreader-01.iinet.net.au!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <20061002123732@usenet.piggo.com>
Subject: [slrn] very easy display filter enabling colour in message body
Date: Mon, 02 Oct 2006 13:09:08 +1000
From: Troy Piggins <usenet-0610@piggo.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed.iinet.net.au!newsfeed.iinet.net.au!per-qv1-newsstorage1.iinet.net.au!per-qv1-newsstorage1.iinet.net.au!per-qv1-newsreader-01.iinet.net.au!not-for-mail
Newsgroups: news.software.readers
Reply-To: usenet-0610@piggo.com
User-Agent: slrn/0.9.8.1pl1/rt (Linux)
Lines: 96
NNTP-Posting-Host: 203.206.60.205
X-Trace: 1159758602 per-qv1-newsreader-01.iinet.net.au 8430 203.206.60.205