Skip to content

Commit 0054780

Browse files
committed
wip
1 parent 74d997f commit 0054780

File tree

1 file changed

+24
-56
lines changed

1 file changed

+24
-56
lines changed

src/Generator.php

Lines changed: 24 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,8 @@ protected function compileTasksResults(array $results)
224224

225225
return [
226226
'count' => count($this->earlyTaskErrors) + $results->sum('count'),
227-
// 'warnings' => $results->flatMap->warnings,
228-
'warnings' => 0,
229-
// 'errors' => collect($this->earlyTaskErrors)->merge($results->flatMap->errors),
230-
'errors' => collect(),
227+
'warnings' => $results->flatMap->warnings,
228+
'errors' => collect($this->earlyTaskErrors)->merge($results->flatMap->errors),
231229
];
232230
}
233231

@@ -286,7 +284,7 @@ protected function makeContentGenerationClosures($pages, $request)
286284

287285
$request->setPage($page);
288286

289-
$this->outputProgress($page->url(), '<fg=blue;options=bold>GENERATING</>');
287+
$this->writeGeneratingLine($page->url());
290288

291289
try {
292290
$generated = $page->generate($request);
@@ -295,8 +293,7 @@ protected function makeContentGenerationClosures($pages, $request)
295293
return $e->consoleMessage();
296294
}
297295

298-
// Clear line, then output FAILED status with newline
299-
$this->clearLine();
296+
$this->clearCurrentLine();
300297
Partyline::outputComponents()->twoColumnDetail($page->url(), '<fg=red;options=bold>FAILED</>');
301298

302299
$errors[] = $e->consoleMessage();
@@ -314,8 +311,7 @@ protected function makeContentGenerationClosures($pages, $request)
314311
$warnings[] = $generated->consoleMessage();
315312
}
316313

317-
// Clear line, then output SUCCESS status with newline
318-
$this->clearLine();
314+
$this->clearCurrentLine();
319315
Partyline::outputComponents()->twoColumnDetail($page->url(), '<fg=green;options=bold>SUCCESS</>');
320316

321317
Blink::flush();
@@ -335,8 +331,8 @@ protected function outputTasksResults()
335331
Partyline::newLine();
336332
Partyline::outputComponents()->success("Generated {$successCount} content files");
337333

338-
// $results['warnings']->each(fn ($warning) => Partyline::outputComponents()->warn($warning));
339-
// $results['errors']->each(fn ($error) => Partyline::outputComponents()->error($error));
334+
$results['warnings']->each(fn ($warning) => Partyline::outputComponents()->warn($warning));
335+
$results['errors']->each(fn ($error) => Partyline::outputComponents()->error($error));
340336
}
341337

342338
protected function outputSummary()
@@ -345,13 +341,13 @@ protected function outputSummary()
345341

346342
$total = $this->taskResults['count'];
347343

348-
// if ($errors = count($this->taskResults['errors'])) {
349-
// Partyline::outputComponents()->warn("{$errors}/{$total} pages not generated");
350-
// }
351-
//
352-
// if ($warnings = count($this->taskResults['warnings'])) {
353-
// Partyline::outputComponents()->warn("{$warnings}/{$total} pages generated with warnings");
354-
// }
344+
if ($errors = count($this->taskResults['errors'])) {
345+
Partyline::outputComponents()->warn("{$errors}/{$total} pages not generated");
346+
}
347+
348+
if ($warnings = count($this->taskResults['warnings'])) {
349+
Partyline::outputComponents()->warn("{$warnings}/{$total} pages generated with warnings");
350+
}
355351
}
356352

357353
protected function entries()
@@ -515,51 +511,23 @@ protected function getToStringFormat(): string|\Closure|null
515511
}
516512

517513
/**
518-
* Output a two-column detail line without a trailing newline.
519-
* This allows the line to be overwritten later.
514+
* Outputs a "Generating" line to the terminal. Very similar output-wise to Laravel's
515+
* ->twoColumnDetail() method, but it allows for replacing the line later, for
516+
* success/error statuses.
520517
*/
521-
protected function outputProgress(string $first, string $second): void
522-
{
523-
// Extract the text from color tags
524-
preg_match('/<fg=([^;>]+);options=bold>([^<]+)<\/>/', $second, $matches);
525-
$color = $matches[1] ?? 'white';
526-
$text = $matches[2] ?? $second;
527-
528-
// ANSI color codes
529-
$colors = [
530-
'blue' => "\033[34;1m",
531-
'green' => "\033[32;1m",
532-
'red' => "\033[31;1m",
533-
'reset' => "\033[0m",
534-
'gray' => "\033[90m",
535-
];
518+
private function writeGeneratingLine(string $url): void
519+
{
520+
$dotsLen = max(1, 150 - strlen($url) - strlen('GENERATING') - 6);
536521

537-
// Format: " first .......... STATUS"
538-
// The actual visible width calculation
539-
$firstLen = strlen($first);
540-
$textLen = strlen($text);
541-
542-
// Calculate dots to match twoColumnDetail width
543-
// Subtract a bit more to account for spacing and ensure alignment
544-
$dotsLen = max(1, 150 - $firstLen - $textLen - 6);
545-
546-
$line = sprintf(" %s %s%s%s %s%s%s",
547-
$first,
548-
$colors['gray'],
549-
str_repeat('.', $dotsLen),
550-
$colors['reset'],
551-
$colors[$color] ?? '',
552-
$text,
553-
$colors['reset']
522+
$line = sprintf(" %s \033[90m%s\033[0m \033[34;1mGENERATING\033[0m",
523+
$url,
524+
str_repeat('.', $dotsLen)
554525
);
555526

556527
fwrite(STDERR, $line);
557528
}
558529

559-
/**
560-
* Clear the current line
561-
*/
562-
protected function clearLine(): void
530+
private function clearCurrentLine(): void
563531
{
564532
fwrite(STDERR, "\r\x1B[2K");
565533
}

0 commit comments

Comments
 (0)