Trace (I hope I spelled it correctly)
Last night you asked me what my trick was, that I used discussing my Forex
code, that controlled the placement of text on the screen.
Google VT100 escape sequences:
In that program I used 2 VT100 tricks and strictly formatted strings using
printf.
Here is one:
# clear screen
# vt100 clear screen ESC[2J
print chr(27) . '[2J';
Another
# goto top of window
# vt100 cursor home ESC[H
print chr(27) . '[H';
Attached is the perl code involved. Hope this helps.
There are some escape sequences where you can place the cursor before
printing text. I did not use that sequence.
Investigate from metacpan.org, Curses and related modules. Curses is a
layer of code that sits on top of the escape sequences your terminal
supports and gives you precise placement of text.
Julian
#!/usr/bin/perl
package bin::progra_001;
use strict;
use warnings;
use Common;
use TimeFrame;
use TimeFrame::Minute;
use TimeFrame::Hourly;
use TimeFrame::T120;
use TimeFrame::T240;
use TimeFrame::T720;
use TimeFrame::Daily;
use TimeFrame::Weekly;
use TimeFrame::Monthly;
use Cwd;
use Carp;
use Data::Dumper;
$| = 1;
sub myLog
{
my ($msg) = @_;
print $msg . "\n";
}
$SIG{__WARN__} = sub {
my ($sig) = @_;
myLog ("WARN :$sig:");
myLog (Carp->longmess);
exit 0;
};
$SIG{__DIE__} = sub {
my ($sig) = @_;
myLog ("DIE:$sig:");
myLog (Carp->longmess);
exit 0;
};
$SIG{TERM} = sub {
my ($sig) = @_;
print "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
exit 0;
};
$SIG{INT} = sub {
my ($sig) = @_;
print "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
exit 0;
};
sub usage
{
my ($msg) = @_;
print "Error: $msg\n";
print "usage: program_001.pl [--sleep=N] csv_file\n";
exit 0;
}
exit (script (@ARGV)) unless caller ();
sub script
{
my (@args) = @_;
my $csv_file;
my $sleepy_time;
foreach my $arg (@args)
{
if ($arg =~ m/^--sleep=(\d+)$/)
{
$sleepy_time = $1;
}
else
{
$csv_file = $arg;
last;
}
}
if (!defined $csv_file || !-f $csv_file)
{
usage ("Need a csv file");
}
# Accumulators
my $tfMinute = TimeFrame::Minute->new ();
my $tfHourly = TimeFrame::Hourly->new ();
my $tfT120 = TimeFrame::T120->new ();
my $tfT240 = TimeFrame::T240->new ();
my $tfT720 = TimeFrame::T720->new ();
my $tfDaily = TimeFrame::Daily->new ();
my $tfWeekly = TimeFrame::Weekly->new ();
my $tfMonthly = TimeFrame::Monthly->new ();
my $IN;
# clear screen
# vt100 clear screen ESC[2J
print chr(27) . '[2J';
my $count = 0;
# read in the data by the minute
open $IN, "<", $csv_file or die "Cannot open :$csv_file:";
while (<$IN>)
{
chomp;
my ($Date, $Open, $High, $Low, $Close, @dontcare) = split (/,/, $_);
my $ref = {
'Date' => $Date,
'Open' => $Open,
'High' => $High,
'Low' => $Low,
'Close' => $Close,
};
# feed the minute data into the timeframe accumulators
$tfMinute->incomingMinuteCandle ($ref);
$tfHourly->incomingMinuteCandle ($ref);
$tfT120->incomingMinuteCandle ($ref);
$tfT240->incomingMinuteCandle ($ref);
$tfT720->incomingMinuteCandle ($ref);
$tfDaily->incomingMinuteCandle ($ref);
$tfWeekly->incomingMinuteCandle ($ref);
$tfMonthly->incomingMinuteCandle ($ref);
# goto top of window
# vt100 cursor home ESC[H
print chr(27) . '[H';
print $tfMinute->getStatus () . "\n";
print $tfHourly->getStatus () . "\n";
print $tfT120->getStatus () . "\n";
print $tfT240->getStatus () . "\n";
print $tfT720->getStatus () . "\n";
print $tfDaily->getStatus () . "\n";
print $tfWeekly->getStatus () . "\n";
print $tfMonthly->getStatus () . "\n";
$count ++;
if (defined $sleepy_time)
{
if ($count >= 29)
{
sleep ($sleepy_time);
$count = 0;
}
}
}
close $IN;
print "\n\n\n\n\n\n\n\n\n\n\n\n\n\nDone\n";
return 0;
}
1;
__END__
_______________________________________________
Houston mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/houston
Website: http://houston.pm.org/