44
55namespace DragonCode \GithubNotifications \Data ;
66
7+ use Illuminate \Support \Str ;
8+
9+ use function Termwind \terminal ;
10+
711class NotificationData extends Data
812{
913 public int $ id ;
@@ -34,7 +38,13 @@ public function __construct(array $data, int $index)
3438 $ this ->organization = $ this ->get ($ data , 'repository.owner.login ' );
3539 $ this ->repository = $ this ->get ($ data , 'repository.name ' );
3640
37- $ this ->title = sprintf (
41+ $ this ->title = $ this ->title ($ index );
42+ $ this ->title .= $ this ->caption ($ data );
43+ }
44+
45+ protected function title (int $ index ): string
46+ {
47+ return sprintf (
3848 '<fg=gray>%d.</> %s: <fg=gray>%s #%d</> ' ,
3949 $ index ,
4050 $ this ->fullName ,
@@ -43,6 +53,20 @@ public function __construct(array $data, int $index)
4353 );
4454 }
4555
56+ public function caption (array $ data ): string
57+ {
58+ $ title = Str::length (strip_tags ($ this ->title ));
59+
60+ return Str::of (strip_tags ((string ) $ this ->get ($ data , 'subject.title ' )))
61+ ->trim ()
62+ ->squish ()
63+ ->limit ($ this ->terminalWidth () - $ title - 50 )
64+ ->prepend ('<fg=yellow>( ' )
65+ ->append (')</> ' )
66+ ->prepend (' ' )
67+ ->toString ();
68+ }
69+
4670 protected function issueId (array $ data ): int
4771 {
4872 if ($ values = $ this ->parseUrl ($ data )) {
@@ -60,4 +84,9 @@ protected function parseUrl(array $data): ?array
6084
6185 return null ;
6286 }
87+
88+ protected function terminalWidth (): int
89+ {
90+ return terminal ()->width ();
91+ }
6392}
0 commit comments