App-mirai

 view release on metacpan or  search on metacpan

lib/App/mirai/Tickit.pm  view on Meta::CPAN

package App::mirai::Tickit;
$App::mirai::Tickit::VERSION = '0.003';
use strict;
use warnings;
use utf8;

use Tickit::DSL qw(:async);
use Tickit::Utils qw(substrwidth textwidth);
use App::mirai::Tickit::TabRibbon;
use App::mirai::Tickit::Widget::Logo;
use Future;
use POSIX qw(strftime);

use JSON::MaybeXS;
use File::Spec;

my %widget;

sub user_path { File::Spec->catpath($_[0]->{user_path}, $_[1]) }
sub share_path { File::Spec->catpath($_[0]->{share_path}, $_[1]) }

sub load_styles {
	my ($self) = shift;
	for my $base (qw(user_path share_path)) {
		for my $path (map $self->$base($_), $ENV{TERM} . '.style', 'default.style') {
			if(-r $path) {
				Tickit::Style->load_style_file($path);
				return $self;
			}
		}
	}

	# Fallback styles
	Tickit::Style->load_style(<<'EOF');
Breadcrumb {
 powerline: 1;
 highlight-bg: 238;
}
MenuBar { bg: 'blue'; fg: 'hi-yellow'; rv: 0; highlight-fg: 'black'; }
Menu { bg: '232'; fg: 'white'; rv: 0; }
Table { highlight-bg: '238'; highlight-fg: 'hi-yellow'; highlight-b: 0; }
FileViewer { highlight-b: 0; }
GridBox { col-spacing: 1; }
EOF
	$self
}

sub new { my $class = shift; bless {@_}, $class }

=head2 stack_table

Creates a table representing a stack trace.

Activating a row in this table will open a file viewer for the given
file and line.

=cut

sub stack_table {
	my ($stack) = @_;
	my $tbl;
	my $truncate = sub {
		my ($row, $col, $item) = @_;
		my $def = $tbl->{columns}[$col];
		return $item unless textwidth($item) > $def->{value};
		substrwidth $item, textwidth($item) - $def->{value};
	};
	$tbl = table {
		my ($row, $data) = @_;
		my ($item) = @$data;
		my ($pkg, $file, $line) = @$item;
		add_widgets {
			fileviewer {
			} $file,
			  'tabsize' => 4,
			  line => $line - 1,
			  'parent:label' => $file;
			  'parent:top' => 3,
			  'parent:left' => 3;
		} under => $widget{desktop};
	} data => $stack,
	  item_transformations => [sub {
	  	my ($row, $item) = @_;
		Future->wrap([ @{$item}[1,2] ])
	  } ],
	  failure_transformations => sub { ' ' },
	  view_transformations => [$truncate],
	  columns => [
		{ label => 'File' },
		{ label => 'Line', align => 'right', width => 6 },
	], 'parent:expand' => 1;
}

=head2 future_details

Opens a panel with details of the given L<Future>.

=cut

sub future_details {



( run in 0.913 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )