pbot-vm: output postprocessing: escape control characters/unprintable characters

This commit is contained in:
Pragmatic Software 2022-04-07 18:24:57 -07:00
parent 690c5f5c44
commit 3d311296eb
2 changed files with 24 additions and 3 deletions

View File

@ -360,9 +360,30 @@ sub postprocess_output($self) {
}
$self->{output} = $boutput;
# bell
my @beeps = qw/*BEEP* *BING* *DING* *DONG* *CLUNK* *BONG* *PING* *BOOP* *BLIP* *BOP* *WHIRR*/;
$self->{output} =~ s/\007/$beeps[rand @beeps]/g;
# known control characters
my %escapes = (
"\e" => '<esc>',
"\f" => '<ff>',
# \r and \n are disabled so the bot itself processes them, e.g. when
# web-pasting, etc. feel free to uncomment them if you like (add them
# to the group in the substitution regex as well).
# "\r" => '<cr>',
# "\n" => '<nl>',
# \t is left alone
);
$self->{output} =~ s/([\e\f])/$escapes{$1}/gs;
# other unprintables
my %disregard = ( "\n" => 1, "\r" => 1, "\t" => 1 );
$self->{output} =~ s/([\x00-\x1f])/$disregard{$1} ? $1 : sprintf('\x%X', ord $1)/gse;
}
sub show_output($self) {

View File

@ -25,8 +25,8 @@ use PBot::Imports;
# These are set by the /misc/update_version script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 4528,
BUILD_DATE => "2022-04-06",
BUILD_REVISION => 4530,
BUILD_DATE => "2022-04-07",
};
sub initialize {}