BBS-Universal

 view release on metacpan or  search on metacpan

lib/BBS/Universal.pm  view on Meta::CPAN

	};
###
	# Special sequences
	my $special = $pairs_to_map->(
		['APC', "\e_",   'Application Program Command'],
		['SS2', "\eN",   'Single Shift 2'],
		['SS3', "\eO",   'Single Shift 3'],
		['CSI', "\e[",   'Control Sequence Introducer'],
		['OSC', "\e]",   'Operating System Command'],
		['SOS', "\eX",   'Start Of String'],
		['ST',  "\e\\",  'String Terminator'],
		['DCS', "\eP",   'Device Control String'],
	);

	# Clear controls
	my $clear = $pairs_to_map->(
		['CLS',        "\e[2J\e[H",           'Clear screen and place cursor at the top of the screen'],
		['CLEAR',      "\e[2J",               'Clear screen and keep cursor location'],
		['CLEAR LINE', "\e[0K",               'Clear the current line from cursor'],
		['CLEAR DOWN', "\e[0J",               'Clear from cursor position to bottom of the screen'],
		['CLEAR UP',   "\e[1J",               'Clear to the top of the screen from cursor position'],
	);

	# Cursor movement and control
	my $cursor = $pairs_to_map->(
		['BACKSPACE',     chr(8),            'Backspace'],
		['RETURN',        chr(13),           'Carriage Return (ASCII 13)'],
		['LINEFEED',      chr(10),           'Line feed (ASCII 10)'],
		['NEWLINE',       chr(13) . chr(10), 'New line (ASCII 13 and ASCII 10)'],
		['HOME',          "\e[H",            'Place cursor at top left of the screen'],
		['UP',            "\e[A",            'Move cursor up one line'],
		['DOWN',          "\e[B",            'Move cursor down one line'],
		['RIGHT',         "\e[C",            'Move cursor right one space non-destructively'],
		['LEFT',          "\e[D",            'Move cursor left one space non-destructively'],
		['NEXT LINE',     "\e[E",            'Place the cursor at the beginning of the next line'],
		['PREVIOUS LINE', "\e[F",            'Place the cursor at the beginning of the previous line'],
		['SAVE',          "\e[s",            'Save cureent cursor position'],
		['RESTORE',       "\e[u",            'Restore the cursor to the saved position'],
		['CURSOR ON',     "\e[?25h",         'Turn the cursor on'],
		['CURSOR OFF',    "\e[?25l",         'Turn the cursor off'],
		['SCREEN 1',      "\e[?1049l",       'Set display to screen 1'],
		['SCREEN 2',      "\e[?1049h",       'Set display to screen 2'],
	);

	# Text attributes
	my $attributes = $pairs_to_map->(
		['FONT 1',                    "\e[1m",  'ANSI FONT 1'],
		['FONT 2',                    "\e[2m",  'ANSI FONT 2'],
		['FONT 3',                    "\e[3m",  'ANSI FONT 3'],
		['FONT 4',                    "\e[4m",  'ANSI FONT 4'],
		['FONT 5',                    "\e[5m",  'ANSI FONT 5'],
		['FONT 6',                    "\e[6m",  'ANSI FONT 6'],
		['FONT 7',                    "\e[7m",  'ANSI FONT 7'],
		['FONT 8',                    "\e[8m",  'ANSI FONT 8'],
		['FONT 9',                    "\e[9m",  'ANSI FONT 9'],
		['FONT DOUBLE-HEIGHT TOP',    "\e#3",   'Double-Height Font Top Portion'],
		['FONT DOUBLE-HEIGHT BOTTOM', "\e#4",   'Double-Height Font Bottom Portion'],
		['FONT DOUBLE-WIDTH',         "\e#6",   'Double-Width Font'],
		['FONT DEFAULT SIZE',         "\e#5",   'Default Font Size'],
		['RESET',                     "\e[0m",  'Restore all attributes and colors to their defaults'],
		['BOLD',                      "\e[1m",  'Set to bold text'],
		['NORMAL',                    "\e[22m", 'Turn off all attributes'],
		['FAINT',                     "\e[2m",  'Set to faint (light) text'],
		['ITALIC',                    "\e[3m",  'Set to italic text'],
		['UNDERLINE',                 "\e[4m",  'Set to underlined text'],
		['DEFAULT UNDERLINE COLOR',   "\e[59m", 'Set underline color to the default'],
		['FRAMED',                    "\e[51m", 'Turn on framed text'],
		['FRAMED OFF',                "\e[54m", 'Turn off framed text'],
		['ENCIRCLED',                 "\e[52m", 'Turn on encircled letters'],
		['ENCIRCLED OFF',             "\e[54m", 'Turn off encircled letters'],
		['OVERLINED',                 "\e[53m", 'Turn on overlined text'],
		['OVERLINED OFF',             "\e[55m", 'Turn off overlined text'],
		['SUPERSCRIPT',               "\e[73m", 'Turn on superscript'],
		['SUBSCRIPT',                 "\e[74m", 'Turn on superscript'],
		['SUPERSCRIPT OFF',           "\e[75m", 'Turn off superscript'],
		['SUBSCRIPT OFF',             "\e[75m", 'Turn off subscript'],
		['SLOW BLINK',                "\e[5m",  'Set slow blink'],
		['RAPID BLINK',               "\e[6m",  'Set rapid blink'],
		['INVERT',                    "\e[7m",  'Invert text'],
		['REVERSE',                   "\e[7m",  'Invert text'],
		['HIDE',                      "\e[8m",  'Hide enclosed text'],
		['REVEAL',                    "\e[28m", 'Reveal hidden text'],
		['CROSSED OUT',               "\e[9m",  'Crossed out text'],
		['FONT DEFAULT',              "\e[10m", 'Set default font'],
		['PROPORTIONAL ON',           "\e[26m", 'Turn on proportional text'],
		['PROPORTIONAL OFF',          "\e[50m", 'Turn off proportional text'],
		['RING BELL',                 chr(7),   'Console bell'],
	);

	# Foreground (base 16 + bright variants)
	my @fg16 = (
		['DEFAULT',        "\e[39m", 'Default foreground color'],
		['BLACK',          "\e[30m", 'Black'],
		['RED',            "\e[31m", 'Red'],
		['GREEN',          "\e[32m", 'Green'],
		['YELLOW',         "\e[33m", 'Yellow'],
		['BLUE',           "\e[34m", 'Blue'],
		['MAGENTA',        "\e[35m", 'Magenta'],
		['CYAN',           "\e[36m", 'Cyan'],
		['WHITE',          "\e[37m", 'White'],
		['BRIGHT BLACK',   "\e[90m", 'Bright black'],
		['BRIGHT RED',     "\e[91m", 'Bright red'],
		['BRIGHT GREEN',   "\e[92m", 'Bright green'],
		['BRIGHT YELLOW',  "\e[93m", 'Bright yellow'],
		['BRIGHT BLUE',    "\e[94m", 'Bright blue'],
		['BRIGHT MAGENTA', "\e[95m", 'Bright magenta'],
		['BRIGHT CYAN',    "\e[96m", 'Bright cyan'],
		['BRIGHT WHITE',   "\e[97m", 'Bright white'],
	);

	# Foreground extensions: all named 256-color and truecolor entries

    # Foreground extensions: all named 256-color and truecolor entries
	my @fg_extra = (
		['NAVY',                          "\e[38;5;17m",           'Navy'],
		['PINK',                          "\e[38;5;198m",          'Pink'],
		['AIR FORCE BLUE',                "\e[38;2;93;138;168m",   'Air Force blue'],
		['ALICE BLUE',                    "\e[38;2;240;248;255m",  'Alice blue'],
		['ALIZARIN CRIMSON',              "\e[38;2;227;38;54m",    'Alizarin crimson'],
		['ALMOND',                        "\e[38;2;239;222;205m",  'Almond'],
		['AMARANTH',                      "\e[38;2;229;43;80m",    'Amaranth'],

lib/BBS/Universal.pm  view on Meta::CPAN

                $ch = $self->{'sysop_tokens'}->{$key}->($self);
            } else {
                $ch = $self->{'sysop_tokens'}->{$key};
            }
            $text =~ s/\[\%\s+$key\s+\%\]/$ch/gi;
        } ## end elsif ($text =~ /\[\%\s+$key\s+\%\]/)
    } ## end foreach my $key (keys %{ $self...})

    $text = $self->ansi_decode($text);

    return ($text);
} ## end sub sysop_detokenize

sub sysop_menu_choice {
    my $self   = shift;
    my $choice = shift;
    my $color  = shift;
    my $desc   = shift;

    $self->{'debug'}->DEBUG(['Start SysOp Menu Choice']);
    my $response;
    if ($choice eq 'TOP') {
        $response = charnames::string_vianame('BOX DRAWINGS LIGHT ARC DOWN AND RIGHT') . charnames::string_vianame('BOX DRAWINGS LIGHT HORIZONTAL') . charnames::string_vianame('BOX DRAWINGS LIGHT ARC DOWN AND LEFT') . "\n";
    } elsif ($choice eq 'BOTTOM') {
        $response = $self->news_title_colorize(charnames::string_vianame('BOX DRAWINGS LIGHT ARC UP AND RIGHT') . charnames::string_vianame('BOX DRAWINGS LIGHT HORIZONTAL') . charnames::string_vianame('BOX DRAWINGS LIGHT ARC UP AND LEFT')) . "\n";
    } else {
        $response = $self->ansi_decode(charnames::string_vianame('BOX DRAWINGS LIGHT VERTICAL') . '[% BOLD %][% ' . $color . ' %]' . $choice . '[% RESET %]' . charnames::string_vianame('BOX DRAWINGS LIGHT VERTICAL') . ' [% ' . $color . ' %]' . charna...
    }
    $self->{'debug'}->DEBUG(['End SysOp Menu Choice']);
    return ($response);
} ## end sub sysop_menu_choice

sub sysop_showenv {
    my $self = shift;

    $self->{'debug'}->DEBUG(['Start SysOp ShowENV']);
    my $MAX  = 0;
    my $text = '';
    foreach my $e (keys %ENV) {
        $MAX = max(length($e), $MAX);
    }

    foreach my $env (sort(keys %ENV)) {
        if ($ENV{$env} =~ /\n/g || $env eq 'WHATISMYIP_INFO') {
            my @in     = split(/\n/, $ENV{$env});
            my $indent = $MAX + 4;
            $text .= '[% BRIGHT WHITE %]' . sprintf("%${MAX}s", $env) . "[% RESET %] = ---\n";
            foreach my $line (@in) {
                if ($line =~ /\:/) {
                    my ($f, $l) = $line =~ /^(.*?):(.*)/;
                    chomp($l);
                    chomp($f);
                    $f = uc($f);
                    if ($f eq 'IP') {
                        $l = colored(['bright_green'], $l);
                        $f = 'IP ADDRESS';
                    }
                    my $le = 11 - length($f);
                    $f .= ' ' x $le;
                    $l = colored(['green'],    uc($l))                                                                         if ($l =~ /^ok/i);
                    $l = colored(['bold red'], 'U') . colored(['bold bright_white'], 'S') . colored(['bold bright_blue'], 'A') if ($l =~ /^us/i);
                    $text .= colored(['bold bright_cyan'], sprintf("%${indent}s", $f)) . " = $l\n";
                } else {
                    $text .= "$line\n";
                }
            } ## end foreach my $line (@in)
        } else {
            my $orig = $ENV{$env};
            my $new;

            if ($orig =~ /(256color)/) {
                $new = colored(['red'], '2') . colored(['green'], '5') . colored(['yellow'], '6') . colored(['cyan'], 'c') . colored(['bright_blue'], 'o') . colored(['magenta'], 'l') . colored(['bright_green'], 'o') . colored(['bright_blue'], 'r');
                $orig =~ s/$1/$new/g;
            } elsif ($orig =~ /(truecolor)/) {
                $new = colored(['red'], 't') . colored(['green'], 'r') . colored(['yellow'], 'u') . colored(['cyan'], 'e') . colored(['bright_blue'], 'c') . colored(['magenta'], 'o') . colored(['bright_green'], 'l') . colored(['bright_blue'], 'o') . ...
                $orig =~ s/$1/$new/g;
            } elsif ($orig =~ /(\d+\.\d+\.\d+\.\d+)/) {
                $new = '[% BRIGHT GREEN %]' . $1 . '[% RESET %]';
                $orig =~ s/$1/$new/g;
            } elsif ($orig =~ /(ubuntu)/i) {
                $new = '[% ORANGE %]' . $1 . '[% RESET %]';
                $orig =~ s/$1/$new/g;
            } elsif ($orig =~ /(redhat)/i) {
                $new = colored(['bright_red'], $1);
                $orig =~ s/$1/$new/g;
            } elsif ($orig =~ /(fedora)/i) {
                $new = colored(['bright_cyan'], $1);
                $orig =~ s/$1/$new/g;
            } elsif ($orig =~ /(mint)/i) {
                $new = colored(['bright_green'], $1);
                $orig =~ s/$1/$new/g;
            } elsif ($orig =~ /(zorin)/i) {
                $new = colored(['bright_white'], $1);
                $orig =~ s/$1/$new/g;
            } elsif ($orig =~ /(wayland)/i) {
                $new = colored(['bright_yellow'], $1);
                $orig =~ s/$1/$new/g;
            }
            $text .= colored(['bold white'], sprintf("%${MAX}s", $env)) . ' = ' . $orig . "\n";
        } ## end else [ if ($ENV{$env} =~ /\n/g...)]
    } ## end foreach my $env (sort(keys ...))
    $self->{'debug'}->DEBUG(['End SysOp ShowENV']);
    return ($text);
} ## end sub sysop_showenv

sub sysop_scroll {
    my $self = shift;

    $self->{'debug'}->DEBUG(['Start SysOp Scroll']);
    my $response = TRUE;
    print $self->{'ansi_meta'}->{'attributes'}->{'RESET'}->{'out'}, "\rScroll?  ";
    if ($self->sysop_keypress(ECHO, BLOCKING) =~ /N/i) {
        $response = FALSE;
    } else {
        print "\r" . clline;
    }
    $self->{'debug'}->DEBUG(['End SysOp Scroll']);
    return (TRUE);
} ## end sub sysop_scroll

sub sysop_list_bbs {
    my $self = shift;

    $self->{'debug'}->DEBUG(['Start SysOp List BBS']);
    my $sth = $self->{'dbh'}->prepare('SELECT * FROM bbs_listing_view ORDER BY bbs_name');
    $sth->execute();
    my @listing;
    my ($id_size, $name_size, $hostname_size, $poster_size) = (2, 4, 14, 6);
    while (my $row = $sth->fetchrow_hashref()) {
        push(@listing, $row);
        $name_size     = max(length($row->{'bbs_name'}),     $name_size);
        $hostname_size = max(length($row->{'bbs_hostname'}), $hostname_size);
        $id_size       = max(length('' . $row->{'bbs_id'}),  $id_size);
        $poster_size   = max(length($row->{'bbs_poster'}),   $poster_size);
    } ## end while (my $row = $sth->fetchrow_hashref...)
    my $table = Text::SimpleTable->new($id_size, $name_size, $hostname_size, 5, $poster_size);
    $table->row('ID', 'NAME', 'HOSTNAME/PHONE', 'PORT', 'POSTER');
    $table->hr();
    foreach my $line (@listing) {
        $table->row($line->{'bbs_id'}, $line->{'bbs_name'}, $line->{'bbs_hostname'}, $line->{'bbs_port'}, $line->{'bbs_poster'});
    }
    $self->sysop_output($table->round('BRIGHT BLUE')->draw());
    print 'Press a key to continue... ';
    $self->sysop_keypress();
    $self->{'debug'}->DEBUG(['End SysOp List BBS']);
    return (TRUE);
} ## end sub sysop_list_bbs

sub sysop_edit_bbs {
    my $self = shift;

    $self->{'debug'}->DEBUG(['Start SysOp Edit BBS']);
    my @choices = (qw( bbs_id bbs_name bbs_hostname bbs_port ));
    $self->sysop_prompt('Please enter the ID, the hostname/phone, or the BBS name to edit');
    my $search;
    $search = $self->sysop_get_line(ECHO, 50, '');
    return (FALSE) if ($search eq '');
    print "\r", cldown, "\n";
    my $sth = $self->{'dbh'}->prepare('SELECT * FROM bbs_listing_view WHERE bbs_id=? OR bbs_name=? OR bbs_hostname=?');



( run in 0.519 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )