Skip to content

Commit 20e4894

Browse files
committed
[Console][VarDumper] Ignore href for PhpStorm terminal emulator
1 parent 79a050b commit 20e4894

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

Formatter/OutputFormatterStyle.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
5454
private $background;
5555
private $href;
5656
private $options = array();
57+
private $handlesHrefGracefully;
5758

5859
/**
5960
* Initializes output formatter style.
@@ -185,6 +186,10 @@ public function apply($text)
185186
$setCodes = array();
186187
$unsetCodes = array();
187188

189+
if (null === $this->handlesHrefGracefully) {
190+
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR');
191+
}
192+
188193
if (null !== $this->foreground) {
189194
$setCodes[] = $this->foreground['set'];
190195
$unsetCodes[] = $this->foreground['unset'];
@@ -199,7 +204,7 @@ public function apply($text)
199204
$unsetCodes[] = $option['unset'];
200205
}
201206

202-
if (null !== $this->href) {
207+
if (null !== $this->href && $this->handlesHrefGracefully) {
203208
$text = "\033]8;;$this->href\033\\$text\033]8;;\033\\";
204209
}
205210

Tests/Formatter/OutputFormatterStyleTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,19 @@ public function testOptions()
9797
$this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
9898
}
9999
}
100+
101+
public function testHref()
102+
{
103+
$prevTerminalEmulator = getenv('TERMINAL_EMULATOR');
104+
putenv('TERMINAL_EMULATOR');
105+
106+
$style = new OutputFormatterStyle();
107+
108+
try {
109+
$style->setHref('idea://open/?file=/path/SomeFile.php&line=12');
110+
$this->assertSame("\e]8;;idea://open/?file=/path/SomeFile.php&line=12\e\\some URL\e]8;;\e\\", $style->apply('some URL'));
111+
} finally {
112+
putenv('TERMINAL_EMULATOR'.($prevTerminalEmulator ? "=$prevTerminalEmulator" : ''));
113+
}
114+
}
100115
}

Tests/Formatter/OutputFormatterTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,17 @@ public function testFormatterHasStyles()
241241
/**
242242
* @dataProvider provideDecoratedAndNonDecoratedOutput
243243
*/
244-
public function testNotDecoratedFormatter(string $input, string $expectedNonDecoratedOutput, string $expectedDecoratedOutput)
244+
public function testNotDecoratedFormatter(string $input, string $expectedNonDecoratedOutput, string $expectedDecoratedOutput, string $terminalEmulator = 'foo')
245245
{
246-
$this->assertEquals($expectedDecoratedOutput, (new OutputFormatter(true))->format($input));
247-
$this->assertEquals($expectedNonDecoratedOutput, (new OutputFormatter(false))->format($input));
246+
$prevTerminalEmulator = getenv('TERMINAL_EMULATOR');
247+
putenv('TERMINAL_EMULATOR='.$terminalEmulator);
248+
249+
try {
250+
$this->assertEquals($expectedDecoratedOutput, (new OutputFormatter(true))->format($input));
251+
$this->assertEquals($expectedNonDecoratedOutput, (new OutputFormatter(false))->format($input));
252+
} finally {
253+
putenv('TERMINAL_EMULATOR'.($prevTerminalEmulator ? "=$prevTerminalEmulator" : ''));
254+
}
248255
}
249256

250257
public function provideDecoratedAndNonDecoratedOutput()
@@ -256,6 +263,7 @@ public function provideDecoratedAndNonDecoratedOutput()
256263
array('<question>some question</question>', 'some question', "\033[30;46msome question\033[39;49m"),
257264
array('<fg=red>some text with inline style</>', 'some text with inline style', "\033[31msome text with inline style\033[39m"),
258265
array('<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', "\033]8;;idea://open/?file=/path/SomeFile.php&line=12\033\\some URL\033]8;;\033\\"),
266+
array('<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', 'some URL', 'JetBrains-JediTerm'),
259267
);
260268
}
261269

0 commit comments

Comments
 (0)