| 1 | package Yakuake::Sessions::TraitFor::TabTitles; | ||
| 2 | |||
| 3 | use namespace::autoclean; | ||
| 4 | |||
| 5 | use Class::Usul::Constants qw( EXCEPTION_CLASS OK ); | ||
| 6 | use Class::Usul::Functions qw( throw ); | ||
| 7 | use Cwd qw( getcwd ); | ||
| 8 | use File::DataClass::Types qw( NonEmptySimpleStr ); | ||
| 9 | use Unexpected::Functions qw( Unspecified ); | ||
| 10 | use Moo::Role; | ||
| 11 | use Class::Usul::Options; | ||
| 12 | |||
| 13 | requires qw( config config_dir loc next_argv set_tab_title_for_session ); | ||
| 14 | |||
| 15 | # Public methods | ||
| 16 | sub set_tab_title : method { | ||
| 17 | my ($self, $title, $tty_num) = @_; | ||
| 18 | |||
| 19 | $title //= $self->next_argv || $self->config->tab_title; | ||
| 20 | $tty_num //= $ENV{TTY}; | ||
| 21 | |||
| 22 | $self->set_tab_title_for_session( "${tty_num} ${title}" ); | ||
| 23 | return OK; | ||
| 24 | } | ||
| 25 | |||
| 26 | sub set_tab_title_for_project : method { | ||
| 27 | my $self = shift; | ||
| 28 | my $title = $self->next_argv | ||
| 29 | or throw class => Unspecified, args => [ 'tab title' ]; | ||
| 30 | my $appbase = $self->next_argv || getcwd; | ||
| 31 | my $tty_num = $ENV{TTY}; | ||
| 32 | |||
| 33 | $self->set_tab_title( $title, $tty_num ); | ||
| 34 | $self->config_dir->catfile( "project_${tty_num}" )->println( $appbase ); | ||
| 35 | return OK; | ||
| 36 | } | ||
| 37 | |||
| 38 | 1; | ||
| 39 | |||
| 40 | __END__ |