Skip to content

Commit 134e055

Browse files
Added notification header output to the console
1 parent aabded2 commit 134e055

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

app/Data/NotificationData.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace DragonCode\GithubNotifications\Data;
66

7+
use Illuminate\Support\Str;
8+
9+
use function Termwind\terminal;
10+
711
class 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

Comments
 (0)