# HG changeset patch
# User igor
# Date 1205096062 -7200
# Node ID 9e6359b7ad553268ac31659a3daf33baba30a4a5
# Parent  658b4ea105c194c707b4fdcac88a926276601734
Исправлена ошибка с смешением выводв сеансов
Добавлена поддержка таблуяции (tab completion)
l3config.pm перенесён в /etc/lilalo/ ; возможно не окончательно
Имя сервера для l3-upload не прописывается теперь жёстко в коде, а берётся из конфигурационного файла

diff -r 658b4ea105c1 -r 9e6359b7ad55 install
--- a/install	Sun Mar 09 02:38:56 2008 +0200
+++ b/install	Sun Mar 09 22:54:22 2008 +0200
@@ -21,7 +21,8 @@
 url_lilalo="http://xgu.ru/lilalo"
 url_l3bashrc="${url_lilalo}"/l3bashrc
 url_l3agent="${url_lilalo}"/l3-agent
-url_l3config="${url_lilalo}"/l3config.pm
+url_l3config_pm="${url_lilalo}"/l3config.pm
+url_l3config="${url_lilalo}"/l3-config
 url_l3prompt="${url_lilalo}"/l3prompt
 url_perl_modules=${url_lilalo}/
 perl_modules="Term-VT102 Text-Iconv"
@@ -89,9 +90,11 @@
     do
         user_home=`get_user_home "$user"`
         mkdir -p ${user_home}/${lilalo_home}
-        cp l3config.pm /usr/local/bin
+        mkdir /etc/lilalo/
+        cp l3config.pm /etc/lilalo/
         cp l3-agent /usr/local/bin
-        chmod 755 /usr/local/bin/l3-agent
+        cp l3-config /usr/local/bin
+        chmod 755 /usr/local/bin/l3-{agent,config}
         cp l3bashrc ${user_home}/${lilalo_home}
         cp l3prompt ${user_home}/${lilalo_home}
         chmod 755 ${user_home}/${lilalo_home}/l3prompt
@@ -167,7 +170,7 @@
 step "Installing dependencies" apt_get_install_deps
 step "Downloading l3bashrc" ${wget} ${url_l3bashrc} 
 step "Downloading l3prompt" ${wget} ${url_l3prompt} 
-step "Downloading l3-agent" '${wget} ${url_l3agent}; ${wget} ${url_l3config}'
+step "Downloading l3-agent" '${wget} ${url_l3agent}; ${wget} ${url_l3configpm}; ${wget} ${url_l3config}'
 step "Downloading perl modules for l3-agent" '{ for i in ${perl_modules}; do ${wget} ${url_perl_modules}/$i.tar.gz; done; }'
 step "Installing perl modules for l3-agent" '{ for i in ${perl_modules}; do tar xvfz $i.tar.gz; cd $i*[^z]; perl Makefile.PL; make; make install; cd ..; done; }'
 step "Installing l3bashrc to users home directories" install_to_users_homes $install_l3bashrc_for_this_users
diff -r 658b4ea105c1 -r 9e6359b7ad55 l3-agent
--- a/l3-agent	Sun Mar 09 02:38:56 2008 +0200
+++ b/l3-agent	Sun Mar 09 22:54:22 2008 +0200
@@ -15,7 +15,7 @@
 use Time::Local 'timelocal_nocheck';
 use IO::Socket;
 
-use lib "/usr/local/bin";
+use lib "/etc/lilalo";
 use l3config;
 
 
@@ -250,9 +250,7 @@
     my $cline_re2_v3 = qr/$cline_re2_v3_base$/sx;
 
 
-
-    my $vt = Term::VT102->new ( 'cols' => $Config{"terminal_width"}, 
-                                'rows' => $Config{"terminal_height"});
+    my %vt;     # Хэш виртуальных терминалов. По одному на каждый сеанс
     my $cline_vt = Term::VT102->new (
                                 'cols' => $Config{"terminal_width"}, 
                                 'rows' => $Config{"terminal_height"});
@@ -282,6 +280,12 @@
         $file =~ m@.*/([^/]*)\.script$@;
         $local_session_id = $1;
 
+        if (not defined($vt{$local_session_id})) {
+            $vt{$local_session_id} = Term::VT102->new ( 
+                                        'cols' => $Config{"terminal_width"}, 
+                                        'rows' => $Config{"terminal_height"});
+        }
+
         #Если файл только что появился, 
         #пытаемся найти и загрузить информацию о соответствующей ему сессии
         if (!$Script_Files{$file}) {
@@ -413,7 +417,7 @@
                 # Output
                 if (!$last_cl{"suppress_output"} || $last_cl{"err"}) {
                     for (my $i=0; $i<$Config{"terminal_height"}; $i++) {
-                        my $line= $vt->row_plaintext($i);
+                        my $line= $vt{$local_session_id}->row_plaintext($i);
                         next if !defined ($line) ; #|| $line =~ /^\s*$/;
                         $line =~ s/\s*$//;
                         $line .= "\n" unless $line =~ /^\s*$/;
@@ -424,7 +428,7 @@
                     $last_cl{"output"}= "";
                 }
 
-                $vt->reset();
+                $vt{$local_session_id}->reset();
 
 
                 # Save 
@@ -538,7 +542,7 @@
                 # Output
                 if (!$last_cl{"suppress_output"} || $last_cl{"err"}) {
                     for (my $i=0; $i<$Config{"terminal_height"}; $i++) {
-                        my $line= $vt->row_plaintext($i);
+                        my $line= $vt{$local_session_id}->row_plaintext($i);
                         next if !defined ($line) ; #|| $line =~ /^\s*$/;
                         $line =~ s/\s*$//;
                         $line .= "\n" unless $line =~ /^\s*$/;
@@ -549,7 +553,7 @@
                     $last_cl{"output"}= "";
                 }
 
-                $vt->reset();
+                $vt{$local_session_id}->reset();
 
 
                 # Changing encoding 
@@ -575,7 +579,7 @@
             $last_output_length+=length($_);
             #if (!$cl{"suppress_output"} || $last_output_length < 5000) {
             if ($last_output_length < 50000) {
-                $vt->process("$_"."\n") 
+                $vt{$local_session_id}->process("$_"."\n") 
             }
             else
             {
diff -r 658b4ea105c1 -r 9e6359b7ad55 l3-backend
--- a/l3-backend	Sun Mar 09 02:38:56 2008 +0200
+++ b/l3-backend	Sun Mar 09 22:54:22 2008 +0200
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 
 use strict;
-use lib '.';
+use lib '/etc/lilalo/';
 use l3config;
 use IO::Socket;
 use POSIX qw(:sys_wait_h);
diff -r 658b4ea105c1 -r 9e6359b7ad55 l3-cgi
--- a/l3-cgi	Sun Mar 09 02:38:56 2008 +0200
+++ b/l3-cgi	Sun Mar 09 22:54:22 2008 +0200
@@ -6,7 +6,7 @@
 use utf8;
 
 BEGIN {
-    chdir("/home/devi/cvs/lilalo");
+    chdir("/etc/lilalo");
     require l3config;
     l3config::init_config();
 };
diff -r 658b4ea105c1 -r 9e6359b7ad55 l3-cgi-lite
--- a/l3-cgi-lite	Sun Mar 09 02:38:56 2008 +0200
+++ b/l3-cgi-lite	Sun Mar 09 22:54:22 2008 +0200
@@ -5,7 +5,7 @@
 use utf8;
 
 BEGIN {
-    chdir("/home/devi/cvs/lilalo");
+    chdir("/etc/lilalo/");
     require l3config;
     l3config::init_config();
 };
diff -r 658b4ea105c1 -r 9e6359b7ad55 l3-frontend
--- a/l3-frontend	Sun Mar 09 02:38:56 2008 +0200
+++ b/l3-frontend	Sun Mar 09 22:54:22 2008 +0200
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use POSIX qw(strftime);
-use lib '.';
+use lib '/etc/lilalo';
 use l3config;
 use utf8;
 
@@ -380,6 +380,11 @@
 
 
     my $current_command=0;
+    my $prev_i;
+
+    my $tab_seq =0 ; # номер команды в последовательности tab-completion
+                     # отличен от нуля только для тех последовательностей, 
+                     # где постоянно нажимается клавиша tab
 
 COMMAND_LINE_PROCESSING:
     for my $i (@Command_Lines_Index) {
@@ -390,6 +395,12 @@
 
         my $cl = \$Command_Lines[$i];
 
+        # Запоминаем предыщуюу команду
+        # Она нам потребуется, в частности, для ввода tab_seq рпи обработке tab_completion
+        my $prev_cl;
+        $prev_cl = \$Command_Lines[$prev_i] if defined($prev_i);
+        $prev_i = $i;
+
         next if !$cl;
 
         for my $filter_key (keys %filter) {
@@ -403,6 +414,7 @@
 
         $$cl->{err} ||=0;
 
+
         # Класс команды
 
         $$cl->{"class"} =   $$cl->{"err"} eq 130 ?  "interrupted"
@@ -460,6 +472,25 @@
         }
         $$cl->{short_output} = $output;
 
+# Обработка команд с одинаковым временем
+# Скорее всего они набраны с помощью tab-completion
+        if (defined($prev_cl)) {
+           if ($$prev_cl->{time} == $$cl->{time}) {
+            $tab_seq++;
+           } 
+           else {
+            $tab_seq=0;
+           };
+           $$prev_cl->{tab_seq}=$tab_seq;
+
+# Обработка команд с одинаковым номером в истории
+# Скорее всего они набраны с помощью Ctrl-C
+           if ($$prev_cl->{history} == $$cl->{history}) {
+            $$prev_cl->{break}=1;
+           }
+        }
+
+
 #Обработка пометок
 #  Если несколько пометок (notes) идут подряд, 
 #  они все объединяются
@@ -588,12 +619,6 @@
         last if $current_command > $Config{"start_from_command"} + $Config{"commands_to_show_at_a_go"};
 
 
-# Пропускаем команды, с одинаковым временем
-# Это не совсем правильно.
-# Возможно, что это команды, набираемые с помощью <completion>
-# или запомненные с помощью <ctrl-c>
-
-        next if $Stat{LastCommand} == $cl->{time};
 
 # Пропускаем строки, которые противоречат фильтру
 # Если у нас недостаточно информации о том, подходит строка под  фильтр или нет, 
@@ -760,7 +785,13 @@
         $this_day_result .= "<div class='cline'>" . $cline ;      #cline
         $this_day_result .= "<span title='Код завершения ".$cl->{"err"}."'>\n"
                          .  "<img src='".$Config{frontend_ico_path}."/error.png'/>\n"
-                         .  "</span>\n" if $cl->{"err"};
+                         .  "</span>\n" if ($cl->{"err"} and not $cl->{tab_seq} and not $cl->{break});
+        $this_day_result .= "<span title='Tab completion ".$cl->{tab_seq}."'>\n"
+                         .  "<img src='".$Config{frontend_ico_path}."/tab.png'/>\n"
+                         .  "</span>\n" if $cl->{tab_seq};
+        $this_day_result .= "<span title='Ctrl-C pressed'>\n"
+                         .  "<img src='".$Config{frontend_ico_path}."/break.png'/>\n"
+                         .  "</span>\n" if ($cl->{break} and not $cl->{tab_seq});
         $this_day_result .= "</div>\n";                             #cline
 
 # OUTPUT
diff -r 658b4ea105c1 -r 9e6359b7ad55 l3-upload
--- a/l3-upload	Sun Mar 09 02:38:56 2008 +0200
+++ b/l3-upload	Sun Mar 09 22:54:22 2008 +0200
@@ -2,7 +2,7 @@
 #
 
 use CGI;
-$upload_dir = "/var/www/xguru/l3shot";
+$upload_dir = "/var/www/l3shot";
 $query = new CGI;
 
 $filename = $query->param("photo"); 
diff -r 658b4ea105c1 -r 9e6359b7ad55 l3bashrc
--- a/l3bashrc	Sun Mar 09 02:38:56 2008 +0200
+++ b/l3bashrc	Sun Mar 09 22:54:22 2008 +0200
@@ -182,7 +182,6 @@
     unset `set | grep '^_l3_.*=' | sed 's/=.*//'`
 }
 
-
 l3shot()
 {
     if [ -x "`which xwd`" ]
@@ -193,7 +192,7 @@
         [ -d ${_l3_home} ] || mkdir -p ${_l3_home}
         xwd -out "$_l3_home/$shot_name" \
         && echo Screenshot is written to ${_l3_home}/${shot_name} \
-        && curl -s -F photo=@$_l3_home/$shot_name http://xgu.ru/l3-upload
+        && curl -s -F photo=@$_l3_home/$shot_name http://`l3-config backend_address`/l3-upload
     else
         {
             echo
@@ -228,7 +227,7 @@
             cp $source /tmp/$target
         fi
         echo Uploaded file name is ${target}
-        curl -s -F photo=@/tmp/$target http://xgu.ru/l3-upload && rm -f /tmp/$target
+        curl -s -F photo=@/tmp/$target http://`l3-config backend_address`/l3-upload && rm -f /tmp/$target
     fi
 }
 
diff -r 658b4ea105c1 -r 9e6359b7ad55 l3files/break.png
Binary file l3files/break.png has changed
diff -r 658b4ea105c1 -r 9e6359b7ad55 l3files/tab.png
Binary file l3files/tab.png has changed