New in Symfony 4.3: Console Hyperlinks

Symfony 4.3 will be released in May 2019. This is the first article of the series that shows the most important new features introduced by this Symfony version.


Contributed by
Gabriel Ostrolucký
in #29168.

Creating advanced Console interfaces is important for lots of applications, even those which are not Console based but include some commands to perform certain tasks.

Rendering clickable hyperlinks is one of the most important missing features of Console apps and commands. Although most of the terminal emulators auto-detect URLs and allow to click on them with some key combination, it's not possible to render clickable text that points to some arbitrary URL.

However, some terminal emulators led by iTerm2 and GNOME Terminal, are working on a new specification to add support for this feature. That's why Symfony 4.3 added support for hyperlinks in the Console using the following syntax:

1
2
3
// hyperlink syntax: <href=THE_LINK_URL> THE_LINK_TEXT </>
$output->writeln('<href=https://symfony.com>Symfony Homepage</>');
$output->writeln('<href=https://github.com/symfony/symfony/issues/29585>View Issue</>');

If your terminal emulator is compatible, this is how you'll see these links:

Thanks to this new feature, we've started to improve the developer experience of some Symfony features, such as the links displayed in the VarDumper console output.

If your terminal does not support hyperlinks, they will be rendered as normal and non-clickable text and you won't see their URLs. That's why it's recommended to check out the growing list of terminal emulators that support hyperlinks before using this feature in your own apps and commands.

Comments

Great feature!

It isn't currently supported by Windows console, but there is an issue open to add it. Give it some love to get it off the backlog: https://github.com/Microsoft/console/issues/204
cool ! 👍
nice !
Cool feature Gabi
Very cool feature! Tnx.
Hmm... I have mixed feelings about this. PuTTY has good reasons to not allow OSC escape sequences (https://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/osc.html) and even if this is "only" allowing to open the local browser with an arbitrary URL, that URL could lead to a malicious webpage. The terminal stream potentially becomes insecure. Furthermore browsers show the target URL in the status bar and allow you to copy the link so that you can decide by yourself what to do with it or if you trust it, but as far as I can see there's no such feature in the terminal clients supports OSC URLs.

Users that don't want to use this feature or whose long used terminal client doesn't support OSC URLs won't be able to see the origin URL. They are locked out which doesn't feel very Symfony'ish. So I would at least recommend to add a global command line option to disable them and display them instead, e.g. in the form "URL - TITLE".
Your putty link deals only with escape sequences which can execute an arbitrary local command

> there's no such feature in the terminal clients supports OSC URLs

There is, check the screenshot in https://github.com/symfony/symfony/pull/29168

> Users that don't want to use this feature or whose long used terminal client doesn't support OSC URLs won't be able to see the origin URL

True, I already raised this concern once, it needs to be handled on case by case basis. I don't think global switch is good thing. Hopefully not providing it will push other terminals to support this sooner. I'm Terminator user which doesn't support this yet myself.

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.