3

I'm working on a console application. My application uses urwid lib. In some cases, I need to show very long hyperlinks as short text inside table columns. I want to open links in the browser when I click on the text inside the column.

So, my question is:

It is possible to print text as a hyperlink to the console?

Can you provide a small example of how to print text as a hyperlink using python?

Kato
  • 30
  • 5
Danila Ganchar
  • 7,271
  • 11
  • 35
  • 59
  • 7
    That depends on your console, it has nothing to do with Python. FWIW, konsole, the standard KDE console, supports hyperlinks. If you print a URL to the console, it will get underlined if you hover over it, and if you right-click on it a menu pops up, and one of the menu options is "Open link". – PM 2Ring Nov 04 '16 at 09:38
  • 3
    You just print it syntactically correct. To identify the hyperlink is the job of the terminal application. – Klaus D. Nov 04 '16 at 09:38
  • I tried in xubuntu terminal. The link can be opened by right-clicking the link. – Nurjan Nov 04 '16 at 09:40
  • 1
    Does this answer your question? https://stackoverflow.com/a/53658415/357578 – rdrey Jul 11 '19 at 19:49

3 Answers3

3

Yes, using some tools, like gNewt or Curses, you could create a button and 'on click' do an action (like open a browser to a given url).

gNewt : http://gnewt.sourceforge.net/

nCurses : https://docs.python.org/3.7/library/curses.html

Otherwise, it's the terminal application that will manage the text you give it, and if it doesn't implement uri's recognition your program won't work as you'd like.

Loïc
  • 10,366
  • 1
  • 26
  • 42
  • 1
    It should be! Using widgets : http://urwid.org/reference/widget.html see `set_text()` and `mouse_event()` – Loïc Nov 04 '16 at 09:59
2

No, some consoles do recognize urls and convert them to a clickable hyperlink. All you can do is make it easy to recognize for console applications by putting a http:// in your url.

Also see How does bash recognize a link?

Community
  • 1
  • 1
vriesdemichael
  • 306
  • 2
  • 12
0

This is completely not a Python question, bash itself doesn't recognize links. But some terminal emulators do. As example Gnome terminal recognize link with 'http://google.com' or 'www.google.com', but not simple 'google.com'. http:// or www indicate what this is link. Probably most other terminal emu will do same but I can't say which exactly.

Community
  • 1
  • 1