Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options


by my_nihilist (Sexton)
on Mar 14, 2008 at 14:07 UTC ( #674205=sourcecode: print w/replies, xml ) Need Help??
Category: Chatterbox Clients
Author/Contact Info my_nihilist
Description: This is the result of bidirectional challange, see my final comment there if you are interested in my decision. Thanks halfcountplus for the winning suggestion.

If you use vim on a dark background THCB will suit your mind.

THCB may be just a *nix thing for reasons described by ikegami below. It will still work if you don't provide a valid user name and want to try it "anonymously". Ctrl-c interrupts to give you a prompt so you can talk, but you obviously won't see anymore incoming messages while you wait at the prompt (don't worry, they will be waiting). nb. that removing the line breaks was intentional...

Type DONE at the prompt to quit. Ctrl-\ might work too.

Update: i added a unique on_background colorscheme for each "name:" until there are five names. After that uniqueness is obseleted.

Update #2: now uses Term::ReadLine::Gnu (altho it just sez Term::ReadLine, it won't work unless Term::ReadLine::Gnu is there). This permits slightly improved editing, like use of the <- and ->. ReadLine also adds a command history ("up" and "down"), but since this is not so useful in the CB i replaced it with the names of previous chatters in square brackets, for quick person-to-person style address. There is also a "chatclip" programmed into the first three F-keys.
PLUS rather than fire off a greeting when you log in, your username now appears in THCB's "X" titlebar. PLUS you can now cancel a line by ending it with "*!*"

Really I would like to learn to do GUI web apps in perl, so this will hopefully develop and if anyone wants to help, eg. by pointing me in some direction, please go ahead.
#!/usr/bin/perl -w
use strict;

use Term::ANSIColor;
use Term::ReadLine;  # also required:
use IO::Handle;      # Term::ReadLine::Gnu
use IPC::Open2;         


print "\e]2;T H C B;)\7";

print "User: ";
my $User=<>;
print "Pass: ";
my $Pass=<>;

open2(*TNIN, *TNOUT, "telnet 4040");
open(LOG, ">THCB.log");

print TNOUT "auth ]$User [ $Pass";

my @c=("red","green","yellow","magenta");
my $n=0; my %hash; my $C=0; my $history=0;
my @ray = ("blue on_yellow", "red on_green", "magenta on_blue", "black
+ on_magenta", "magenta on_cyan");
my $RLterm = new Term::ReadLine 'THCB input';
my $prompt="\nchat> ";

alarm 120; my $m=2; my $dm=1;

$RLterm->add_defun('F1-clip', sub{print TNOUT "<i>you talkin' to <b>me
+</b></i> "});
$RLterm->add_defun('F2-clip', sub{print TNOUT "<i>reflects...</i>\n"})
$RLterm->add_defun('F3-clip', sub{print TNOUT "<b>HELLO WORLD!</b>\n"}

while (<TNIN>) {
        print LOG "$_"; chomp $_;
        if ($_ =~ /^Found you!\s?$/) {print "\e]0;$User\7" ;}
        my @line = split / /; my $chunk = shift @line; chomp @line;
        if ($chunk =~ /:$/) {
                if (exists($hash{$chunk})) {print color("$hash{$chunk}
+"), "$chunk"}
                else {$hash{$chunk}="$ray[$C]"; $C++;
                        print color("$hash{$chunk}"), "$chunk";
                        my $name; ($name = $chunk) =~ s/:/]/;
                        $RLterm->add_history("[$name"); $history++;
                        if ($C == 5) {$C=0} }
                print color("reset");
        else {print color("$c[$n]"), "$chunk "}
        print color("$c[$n]"), "@line "; print color("reset");
        if ($n == 3) {$n=0}
        else {$n++}

sub process {
        my $input=$RLterm->readline($prompt);
        if ($input eq "DONE") {exit 0}
        elsif ($input =~/\*!\*$/) {return}
        else {print TNOUT "$input\n"}

sub rearm {
        print color("white on_red"), "$m"; print "m";
        print color("reset");
        if ($dm == 4) {print LOG "***$m Minutes***\n";$dm=0;}
        alarm 120; $m += 2; $dm++;
Replies are listed 'Best First'.
by ikegami (Pope) on Mar 14, 2008 at 22:59 UTC

    THCB uses telnet, so it may be just a *nix thing

    Windows comes with telnet too, and I suspect it'll work. The problem is Windows doesn't have signals. ALRM and INT are emulated, but you may not get great results.

    By the way, I find having your user press Ctrl-C every time they want to do something is unreasonable.

by halfcountplus (Hermit) on Mar 14, 2008 at 22:17 UTC
    this really has potential. b/t/w i think you mean Ctrl-c, not "Ctrl-C".

    also im2 may be on to us, i notice that more and more often the greeting gets shot down by "Not so fast!", even if i didn't log in 35 times already.

      To me, all the variations on Ctrl[-+][Cc] are equal. I have not seen any other place where the distinction is made (on the case of key combined with the Ctrl modifier).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://674205]
[enrgyxprt]: how do I delete a question
[Lotus1]: you can't but you can request to have it deleted.
[Lotus1]: you can edit it as long as you were logged in when you submitted it

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (13)
As of 2017-01-17 13:15 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (156 votes). Check out past polls.