#!/usr/bin/perl use strict; use warnings; #Term::ReadLine stuff use Term::ReadLine; #use Term::ReadLine::Perl5; use Term::ReadLine::readline; #&readline::rl_set('EditingMode', 'vi'); my $term = Term::ReadLine->new('Query'); my $attribs = $term->Attribs; $term->ornaments(0); my $query = ""; while (1) { #readline prompt. uncomment this and comment out the standard prompt to switch #my $prompt = "Enter query [$query] (+ to append, go to run query, x to leave, h for help)> "; #my $mquery = $term->readline($prompt); #standard prompt print "\nEnter query [$query] (+ to append, go to run query, x to leave, h for help)> "; chomp(my $mquery = <>); last if $mquery eq "x"; next if $mquery eq ""; if ($mquery =~ m/^.*....-..-.. ..:..:..\t\d{1,3}\..{1,3}\..{1,3}\..{1,3}\t\d+\t\d{1,3}\..{1,3}\..{1,3}\..{1,3}\t\d+\t\d+\t.*$/) { #parse values out of the pasted alert #regex above matches a SGUIL alert print "Looks good, I can parse this but no history, or up-arrow!\n"; my @fields = split(/\t/, $mquery); $query = "$fields[3] $fields[4] $fields[6]"; } else { print "Looks bad, but I have history!\n"; $query = $mquery; } }