[Bps-public-commit] r9901 - in RT-Client-Console: trunk/bin trunk/lib/RT/Client trunk/lib/RT/Client/Console trunk/lib/RT/Client/Console/Session trunk/lib/RT/Client/Console/Session/Ticket

dams at bestpractical.com dams at bestpractical.com
Tue Dec 11 19:59:54 EST 2007


Author: dams
Date: Tue Dec 11 19:59:53 2007
New Revision: 9901

Modified:
   RT-Client-Console/   (props changed)
   RT-Client-Console/trunk/bin/rtconsole
   RT-Client-Console/trunk/lib/RT/Client/Console.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/KeyHandler.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/Root.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Attachments.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/CustFields.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Header.pm
   RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Links.pm

Log:
 r25 at pundit:  dams | 2007-12-12 00:59:44 +0000
 . by default, STDERR => /dev/null, unless --debug is set
 . remove GLOBAL_HEAP
 . better UI (thx maddingue)
 . added quit feature, and _quit signals


Modified: RT-Client-Console/trunk/bin/rtconsole
==============================================================================
--- RT-Client-Console/trunk/bin/rtconsole	(original)
+++ RT-Client-Console/trunk/bin/rtconsole	Tue Dec 11 19:59:53 2007
@@ -17,6 +17,7 @@
 		   'config-file=s',
 		   'generate-config',
 		   'help',
+		   'debug'
 		  ) or usage();
 $options{help} and usage();
 
@@ -27,6 +28,12 @@
 			 );
 }
 
+# Unless debug is set, we redirect STDERR => /dev/null
+if (!$options{debug}) {
+	close STDERR;
+	open STDERR, ">>/dev/null";
+}
+
 my $config = {};
 exists $options{$_} and $config->{connection}{$_} = $options{$_} foreach (qw(server user pass));
 exists $options{$_} and $config->{server}{$_} = $options{$_} foreach (qw(queues));
@@ -84,6 +91,7 @@
 							 rt_password => $config->{connection}{pass},
 							 queue_ids => \@queues,
 							);
+	endwin;
 } otherwise {
 	use Curses;
 	endwin;
@@ -139,11 +147,15 @@
 
 Generates the config file
 
-=item --version
+=item --help
 
-=item --usage
+Print this help
 
-=item --help
+=item --debug
+
+Outputs errors and debug messages on STDERR. enable this to see what's going
+wrong. I recommend redirecting STDERR to a temp file to avoid breaking the
+display
 
 =back
 

Modified: RT-Client-Console/trunk/lib/RT/Client/Console.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console.pm	Tue Dec 11 19:59:53 2007
@@ -14,24 +14,6 @@
 }
 
 # global heap to keep an application-level state
-my %GLOBAL_HEAP = ( curses => { 
-							    need_clear => 0,
-							   },
-					rt => { 
-						  },
-					server => {
-							   id_to_queue => {},
-							   name_to_queue => {},
-							  },
-					ui => {
-						   tab => {
-								   current => undef,
-								   total => 0,
-								  },
-						  },
-				  );
-sub GLOBAL_HEAP { \%GLOBAL_HEAP }
-
 sub run {
 	my ($class, @args) = @_;
 	my %params = validate( @args, { curses_handler => { isa => 'Curses' },
@@ -61,12 +43,23 @@
 	
 }
 
+{
+
+my $need_cls = 0;
 sub cls {
     my ($class) = @_;
-	$class->GLOBAL_HEAP->{curses}{need_clear} = 1;
+	$need_cls = 1;
+	return;
+}
+sub need_cls {
+	return $need_cls;
+}
+sub reset_cls {
+	$need_cls = 0;
 	return;
 }
 
+}
 
 sub draw_keys_label {
 	my ($class, %params) = @_;

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session.pm	Tue Dec 11 19:59:53 2007
@@ -1,5 +1,8 @@
 package RT::Client::Console::Session;
 
+use strict;
+use warnings;
+
 use base qw(RT::Client::Console);
 
 use POE;
@@ -17,6 +20,13 @@
 		$kernel->alias_set($name);
 		$kernel->call($name, 'init');
 	};
+	$args{inline_states}{_unalias} = sub {
+		my ($kernel, $heap) = @_[ KERNEL, HEAP ];
+		my @aliases = $kernel->alias_list();
+		foreach my $alias (@aliases) {
+			$kernel->alias_remove($alias);
+		}
+	};
 	$sessions{$name} = {
 						poe_object => POE::Session->create(%args),
 						displayed => 1,
@@ -40,7 +50,8 @@
 
 sub create_modal {
 	my ($class, %args) = @_;
-	
+
+	my $title = "[ $args{title} ]";	
 	my $text = $args{text} . "\n";
 	$args{keys}{c} ||= { text => 'cancel',
 						 code => sub { return 1 },
@@ -51,7 +62,7 @@
 	}
 	my $height = scalar( () = $text =~ /(\n)/g) + 1;
 	use List::Util qw(max);
-	my $width = max (map { length } (split(/\n/, $text), $args{title}));
+	my $width = max (map { length } (split(/\n/, $text), $title));
 
 	my ($screen_w, $screen_h);
 
@@ -60,7 +71,7 @@
 	
 	use Curses::Widgets::Label;
 	my $label = Curses::Widgets::Label->new({
-											 CAPTION     => $args{title},
+											 CAPTION     => $title,
 											 CAPTIONCOL  => 'yellow',
 											 BORDER      => 1,
 											 LINES       => $height,
@@ -88,7 +99,8 @@
 				if ($args{keys}{$keystroke}{code}->()) {
 					# stop modal mode
 					pop @modal_sessions;
-					$kernel->post('key_handler', 'draw_all');
+					$class->remove($modal_session_name);
+					$kernel->post('key_handler', 'compute_keys');
 				} else {
 					$kernel->yield('draw');
 				}
@@ -120,6 +132,18 @@
 sub remove {
 	my ($class, $session_name) = @_;
 	delete $sessions{$session_name};
+	$poe_kernel->call($session_name, '_quit');
+	$poe_kernel->call($session_name, '_unalias');
+
+}
+
+sub remove_all {
+	my ($class) = @_;
+	my %sessions = $class->get_sessions();
+	my @sessions_names = keys(%sessions);
+	foreach (@sessions_names) {
+		$class->remove($_);
+	}
 }
 
 1;

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/KeyHandler.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/KeyHandler.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/KeyHandler.pm	Tue Dec 11 19:59:53 2007
@@ -26,6 +26,11 @@
 														 InputEvent => 'handler',
 														);
 		},
+		_quit => sub {
+ 			my ($kernel, $heap) = @_[ KERNEL, HEAP];
+			# release the Curses wheel
+			undef $heap->{console};
+		},
  		handler => sub {
  			my ($kernel, $heap, $keystroke) = @_[ KERNEL, HEAP, ARG0];
 			if ($keystroke ne -1) {
@@ -35,12 +40,11 @@
  					$keystroke = '<' . uc(keyname($keystroke)) . '>';
  				}
  				print STDERR "handler got $keystroke\n";
-				my @modal_sessions = $class->get_modal_sessions();
-				if (@modal_sessions) {
- 					print STDERR "modal handler : " . @modal_sessions . "\n";
-					$kernel->call(@modal_sessions, 'key_handler', $keystroke);
-# 					$kernel->yield('compute_keys');
- 					$kernel->yield('draw_all');
+				my $modal_session = ($class->get_modal_sessions())[-1];
+				if ($modal_session) {
+ 					print STDERR "modal handler : " . $modal_session . "\n";
+					$kernel->call($modal_session, 'key_handler', $keystroke);
+ 					$kernel->call('key_handler', 'draw_all');
 				} elsif (exists $heap->{key_to_action}->{$keystroke}) {
  					my $action = $heap->{key_to_action}->{$keystroke};
  					print STDERR "action : $action, event : $action->{event}\n";
@@ -72,11 +76,11 @@
  		draw_all => sub {
  			my ($kernel, $heap) = @_[ KERNEL, HEAP ];
 			noutrefresh();
-# 			if ($class->GLOBAL_HEAP->{curses}{need_clear}) {
-# 				clear();
-#				$class->GLOBAL_HEAP->{curses}{need_clear} = 0;
-#				$kernel->yield('draw_all');
-# 			} else {
+ 			if ($class->need_cls) {
+ 				clear();
+				$class->reset_cls();
+				$kernel->yield('draw_all');
+ 			} else {
 				my %sessions = $class->get_sessions();
 				while (my ($session_name, $struct) = each %sessions) {
 					$struct->{displayed} and 
@@ -85,7 +89,7 @@
 				foreach my $modal_session ($class->get_modal_sessions()) {
 					$kernel->call($modal_session, 'draw');
 				}
-#			}
+			}
 			doupdate();
  		}
 	},

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Root.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Root.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Root.pm	Tue Dec 11 19:59:53 2007
@@ -37,15 +37,16 @@
 			my @available_list = ();
 			use RT::Client::Console::Cnx;
 			my $rt_handler = RT::Client::Console::Cnx->get_cnx_data()->{handler};
+			push @available_list, ['q', 'quit', 'quit'];
 			if (!$rt_handler) {
 				push @available_list, ['s', 'connect to RT server', 'connect_server'];
 			} else {
-				push @available_list, ['d', 'disconnect from RT server', 'disconnect_server'];
+				push @available_list, ['d', 'disconnect', 'disconnect_server'];
 				push @available_list, ['o', 'open a ticket', 'open_ticket'];
 				if (defined RT::Client::Console::Session::Ticket->get_current_id()) {
-					push @available_list, ['c', 'close current ticket', 'close_ticket'];
-					push @available_list, ['p', 'prev. ticket', 'prev_ticket'];
-					push @available_list, ['n', 'next ticket', 'next_ticket'];
+					push @available_list, ['c', 'close current tab', 'close_tab'];
+					push @available_list, ['p', 'prev. tab', 'prev_tab'];
+					push @available_list, ['n', 'next tab', 'next_tab'];
 				}
 			}
 			return @available_list;
@@ -82,6 +83,10 @@
 #			#refresh;
 #			$label->draw($class->get_curses_handler());
 		},
+		quit => sub {
+			my ($kernel, $heap) = @_[ KERNEL, HEAP ];
+			RT::Client::Console::Session->remove_all();
+		},
 		create_tab_bar => sub {
 			use RT::Client::Console::Session::TabBar;
 			RT::Client::Console::Session::TabBar->create();
@@ -106,13 +111,13 @@
 			print STDERR "root.pm : opening ticket\n";
 			RT::Client::Console::Session::Ticket->load();
 		},
-		close_ticket => sub {
+		close_tab => sub {
 			RT::Client::Console::Session::Ticket->get_current_ticket()->unload();
 		},
-		next_ticket => sub {
+		next_tab => sub {
 			RT::Client::Console::Session::Ticket->next_ticket();
 		},
-		prev_ticket => sub {
+		prev_tab => sub {
 			RT::Client::Console::Session::Ticket->prev_ticket();
 		},
 	}

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket.pm	Tue Dec 11 19:59:53 2007
@@ -155,7 +155,6 @@
 	if ($self->get_current_id() == $self->id()) {
 		if (@tickets_list > 0) {
 			$self->set_current_ticket($tickets_list[-1]);
-			$self->cls();
 		} else {
 			$self->set_current_id(undef);
 			$self->cls();

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Attachments.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Attachments.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Attachments.pm	Tue Dec 11 19:59:53 2007
@@ -20,10 +20,10 @@
 			my ($screen_w, $screen_h);
 			$class->get_curses_handler()->getmaxyx($screen_h, $screen_w);
 
-			$heap->{'pos_x'} = 0;
-			$heap->{'pos_y'} = 1+5+5+1;
-			$heap->{width} = $screen_w * 2 / 3 - 2;
-			$heap->{height} = $screen_h - 5 - 7 - 4;
+			$heap->{pos_x } = 0;
+			$heap->{pos_y } = 1 + 7 + 6;  # tabs-bar + headers + custhdrs
+			$heap->{width } = $screen_w * 2 / 3 - 2;  # - border
+			$heap->{height} = $screen_h - $heap->{pos_y} - 2 - 2;
 
 		},
 		available_keys => sub {
@@ -36,30 +36,28 @@
 			$heap->{current}++;
 			$heap->{current} > $heap->{total} - 1
 			  and $heap->{current} = $heap->{total} - 1;
-			$kernel->post('key_handler', 'draw_all');
 		},
 		prev_attachment => sub {
 			my ( $kernel, $heap) = @_[ KERNEL, HEAP ];
 			$heap->{current}--;
 			$heap->{current} < 0
 			  and $heap->{current} = 0;
-			$kernel->post('key_handler', 'draw_all');
 		},
 		draw => sub {
 			my ($kernel, $heap) = @_[ KERNEL, HEAP ];
 			my $label;
 
-			if (!defined($heap->{attachments}{$ticket_id})) {
+			if (!defined($heap->{attachments})) {
 				$class->_generate_job($kernel, $heap, $ticket_id);
 			}
-			defined($heap->{attachments}{$ticket_id}) or return;
+			defined($heap->{attachments}) or return;
 			my $total = $heap->{total};
 			$total > 0 or return;
 			$heap->{current} ||= 0;
 
 			my $idx = $heap->{current};
 
-			my $attachment = $heap->{attachments}{$ticket_id}->[$idx];
+			my $attachment = $heap->{attachments}->[$idx];
 
 			my $text = '...loading...';
 			my $user_details = '';
@@ -75,7 +73,7 @@
 					  = _get_user_details( rt  => $rt_handler,
 										   id  => $user_id,
 										 );
-					$user_details = "By : $user_real_name ($user_name) <$user_email>";
+					$user_details = "By: $user_real_name ($user_name) <$user_email>";
 					
 				} catch Exception::Class::Base with {
 					my $e = shift;
@@ -84,7 +82,8 @@
 				
 				$text = $class->as_text($attachment);
 			}
-			my $title = 'Attachment ' . ($idx + 1) . " / $total - $user_details";
+			my $title = '[ Attachment ' . ($idx + 1) . " / $total - $user_details ]";
+			$title =~ s/\s+/ /g;
 
 			use Curses::Widgets::ListBox;
 #my $widget = Curses::Widgets::ListBox->new({
@@ -122,7 +121,7 @@
 			# draw keys
 			my @keys = $kernel->call("ticket_attachments_$ticket_id" => 'available_keys');
 			$class->draw_keys_label( Y => $heap->{'pos_y'} + $heap->{height} + 1 ,
-									 X => $heap->{'pos_x'} + 1,
+									 X => $heap->{'pos_x'} + 5,
 									 COLUMNS => $heap->{width} - 2,
 									 VALUE => \@keys,
 									 BACKGROUND  => 'black'
@@ -169,7 +168,7 @@
 
 sub _generate_job {
 	my ($class, $kernel, $heap, $ticket_id) = @_;
-	$heap->{attachments}{$ticket_id} = [];
+	$heap->{attachments} = [];
 
 	my @ids;
 	my $idx = 0;
@@ -191,7 +190,7 @@
 			code => sub {
 				my $attachment = $iterator->();
 				defined $attachment or return;
-				push @{$heap->{attachments}{$ticket_id}}, $attachment;
+				push @{$heap->{attachments}}, $attachment;
 				$idx++ or $kernel->post('key_handler', 'draw_all');
 				return 1;
 			},

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/CustFields.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/CustFields.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/CustFields.pm	Tue Dec 11 19:59:53 2007
@@ -19,9 +19,9 @@
 			my ($screen_w, $screen_h);
 			$class->get_curses_handler()->getmaxyx($screen_h, $screen_w);
 
-			$heap->{'pos_x'} = 0;
-			$heap->{'pos_y'} = 8;
-			$heap->{width} = $screen_w * 2 / 3;
+			$heap->{pos_x } = 0;
+			$heap->{pos_y } = 1 + 7;  # tabs-bar + headers
+			$heap->{width } = $screen_w * 2 / 3 - 2;  # - border
 			$heap->{height} = 4;
 
 		},
@@ -30,7 +30,7 @@
 		},
 		change_custfields => sub {
 			my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
-			$class->create_modal( title => ' Change Custom fields ',
+			$class->create_modal( title => 'Change Custom fields',
 								  text => '',
 								  keys => {
 										  },
@@ -73,8 +73,10 @@
 										   COLUMNS     => $heap->{width},
 										   LINES       => $heap->{height},
 										   
-										   BORDER      => 0,
-										   BORDERCOL   => 'blue',
+										   BORDER      => 1,
+										   BORDERCOL   => 'yellow',
+										   CAPTION     => '[ Custom fields ]',
+										   CAPTIONCOL  => 'yellow',
 										   FOREGROUND  => 'white',
 										   BACKGROUND  => 'blue',
 										   DERIVED     => 1,
@@ -89,8 +91,8 @@
 
 			# draw keys
 			my @keys = $kernel->call("ticket_custfields_$id" => 'available_keys');
-			$class->draw_keys_label( Y => $heap->{'pos_y'} + $heap->{height} -1 ,
-									 X => $heap->{'pos_x'} + 1,
+			$class->draw_keys_label( Y => $heap->{'pos_y'} + $heap->{height} + 1,
+									 X => $heap->{'pos_x'} + 5,
 									 COLUMNS => $heap->{width} - 2,
 									 VALUE => \@keys,
 								   );

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Header.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Header.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Header.pm	Tue Dec 11 19:59:53 2007
@@ -19,9 +19,9 @@
 			my ($screen_w, $screen_h);
 			$class->get_curses_handler()->getmaxyx($screen_h, $screen_w);
 
-			$heap->{'pos_x'} = 0;
-			$heap->{'pos_y'} = 1;
-			$heap->{width} = $screen_w * 2 / 3 - 2;
++			$heap->{pos_x } = 0;
++			$heap->{pos_y } = 1;  # tabs-bar
++			$heap->{width } = $screen_w * 2 / 3 - 2;  # - border
 			$heap->{height} = 5;
 
 		},
@@ -32,7 +32,7 @@
 			my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
 			use RT::Client::Console::Session::Ticket;
 			my $ticket = RT::Client::Console::Session::Ticket->get_current_ticket();
-			$class->create_modal( title => ' Change ticket headers ',
+			$class->create_modal( title => 'Change ticket headers',
 								  text => '',
 								  keys => {
 										   s => { text => 'change subject',
@@ -140,7 +140,7 @@
 										   
 										   BORDER      => 1,
 										   BORDERCOL   => 'yellow',
-										   CAPTION     => $ticket->subject(),
+										   CAPTION     => '[ ' . $ticket->subject() . ' ]',
 										   CAPTIONCOL  => 'yellow',
 										   FOREGROUND  => 'white',
 										   BACKGROUND  => 'blue',
@@ -157,7 +157,7 @@
 			# draw keys
 			my @keys = $kernel->call("ticket_header_$id" => 'available_keys');
 			$class->draw_keys_label( Y => $heap->{'pos_y'} + $heap->{height} + 1,
-									 X => $heap->{'pos_x'} + 1,
+									 X => $heap->{'pos_x'} + 5,
 									 COLUMNS => $heap->{width} - 2,
 									 VALUE => \@keys,
 								   );

Modified: RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Links.pm
==============================================================================
--- RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Links.pm	(original)
+++ RT-Client-Console/trunk/lib/RT/Client/Console/Session/Ticket/Links.pm	Tue Dec 11 19:59:53 2007
@@ -19,10 +19,10 @@
 			my ($screen_w, $screen_h);
 			$class->get_curses_handler()->getmaxyx($screen_h, $screen_w);
 	
-			$heap->{'pos_x'} = $screen_w * 2 / 3 + 1;
-			$heap->{'pos_y'} = 1;
-			$heap->{width} = $screen_w - ($screen_w * 2 / 3);
-			$heap->{height} = $screen_h - 3;
+			$heap->{pos_x } = $screen_w * 2 / 3 + 1;
+			$heap->{pos_y } = 1;  # tabs-bar
+			$heap->{width } = $screen_w - $heap->{pos_x} - 2;  # - border
+			$heap->{height} = $screen_h - $heap->{pos_y} - 2 - 2;  # - status - border
 		},
 		available_keys => sub {
 			return (['l', 'change links', 'change_links']);
@@ -72,9 +72,9 @@
 													  
 												  }
 												},
-										   R => { text => 'change refered',
+										   R => { text => 'change referred',
 												  code => sub {
-													  if (my $new_children = $class->input_ok_cancel(' Change refered ', join(', ', map {$_->id() } @{$heap->{refere}}), 500)) {
+													  if (my $new_children = $class->input_ok_cancel(' Change referred ', join(', ', map {$_->id() } @{$heap->{refered}}), 500)) {
 														  return 1; # stop modal mode
 													  }
 													  
@@ -169,8 +169,10 @@
 													   COLUMNS     => $heap->{width},
 													   LINES       => $heap->{height},
 
-													   BORDER      => 0,
+													   BORDER      => 1,
 													   BORDERCOL   => 'blue',
+													   CAPTION     => '[ Relations ]',
+													   CAPTIONCOL  => 'yellow',
 													   FOREGROUND  => 'white',
 													   BACKGROUND  => 'blue',
 													   DERIVED     => 1,
@@ -186,8 +188,8 @@
 
 			# draw keys
 			my @keys = $kernel->call("ticket_links_$id" => 'available_keys');
-			$class->draw_keys_label( Y => $heap->{'pos_y'} + $heap->{height} - 1,
-									 X => $heap->{'pos_x'},
+			$class->draw_keys_label( Y => $heap->{'pos_y'} + $heap->{height} + 1,
+									 X => $heap->{'pos_x'} + 5,
 									 COLUMNS => $heap->{width},
 									 VALUE => \@keys,
 								   );



More information about the Bps-public-commit mailing list