New in Symfony 4.3: Console Hyperlinks
December 19, 2018 • Published by Javier Eguiluz
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
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.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
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
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".
> 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.