Skip to content

Commit

Permalink
fix: Don't set newLineWritten to true unless verbosity allows output (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnySjoblom authored Jan 9, 2025
1 parent 36a4a53 commit 6291298
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Illuminate/Console/OutputStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ public function write(string|iterable $messages, bool $newline = false, int $opt
#[\Override]
public function writeln(string|iterable $messages, int $type = self::OUTPUT_NORMAL): void
{
$this->newLinesWritten = $this->trailingNewLineCount($messages) + 1;
$this->newLineWritten = true;
if ($this->output->getVerbosity() >= $type) {
$this->newLinesWritten = $this->trailingNewLineCount($messages) + 1;
$this->newLineWritten = true;
}

parent::writeln($messages, $type);
}
Expand Down
17 changes: 17 additions & 0 deletions tests/Console/OutputStyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,21 @@ public function testDetectsNewLineOnWriteln()
$style->writeln('Foo');
$this->assertTrue($style->newLineWritten());
}

public function testDetectsNewLineOnlyOnOutput()
{
$bufferedOutput = new BufferedOutput();

$style = new OutputStyle(new ArrayInput([]), $bufferedOutput);

$style->setVerbosity(OutputStyle::VERBOSITY_NORMAL);

$style->writeln('Foo', OutputStyle::VERBOSITY_VERBOSE);
$this->assertFalse($style->newLineWritten());

$style->setVerbosity(OutputStyle::VERBOSITY_VERBOSE);

$style->writeln('Foo', OutputStyle::VERBOSITY_VERBOSE);
$this->assertTrue($style->newLineWritten());
}
}

0 comments on commit 6291298

Please sign in to comment.