Hello monks!

I've written a tool for use with the SGUIL IDS interface. The tool allows you to copy and paste an alert directly into the prompt, which the script then parses for relevant info, retrieves output for you, and then takes you back to the prompt for the next input. When copy and pasting from SGUIL, the fields are tab separated, which makes for very easy parsing, however I've been trying to use Term::ReadLine to allow for pressing the up-arrow to access input history, editing a previous input, etc. When using Term::ReadLine for this, I've gotten the history part to work, but when pasting an alert, all the tabs are removed and so all the fields are smashed together without even a single space in between. This makes it impossible to parse, and defeats the entire purpose.

I tried changing the EditingMode to 'vi', and this fixes the pasting problem, and allows me to see the input history, but editing doesn't work anymore (backspace, delete, left/right arrows don't work).

Does anyone know how to get this to work so that I can both paste a SGUIL alert and preserve tabs, AND have access to the history and editing previous inputs?

Here is my code so far:

Here is sample input, paste into the prompt: 169 sensor-eth1 10.185133100 2016-03-22 16:49:31 1.2.3.4 80 192.168.10.10 49883 6 ET INFO PDF Using CCITTFax Filter

#!/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 prom +pt 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-arro +w!\n"; my @fields = split(/\t/, $mquery); $query = "$fields[3] $fields[4] $fields[6]"; } else { print "Looks bad, but I have history!\n"; $query = $mquery; } }

In reply to Using Term::ReadLine and pasting input with tabs by crux_capacitor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.