Reputation: 1344
I am opening a .txt
file with my PyCharm IDE that contains multiple links among several other lines of text (actually these are logs from a continuously running script).
Like so:
----------------------- session start, Tuesday 12.10.2021, 12:48:53
>> some logs... -- 12:49:34
link: https://www.example.com/p/CU5Hn-RsSB9
>> more logs... -- 12:49:34
Now for convenience I would like to be able to click on that link rather than copy/pasting it to my browser - it seems like this should be a possible setting somewhere in PyCharm: But I cannot seem to find it and also not find any information on it on the web.
Anybody knows how to make links clickable in .txt
files opened in PyCharm?
Upvotes: 2
Views: 1536
Reputation: 101
For this problem, I also searched and got some solutions, but all of them are not convenient at all.
My solution is just to save .txt file as .html file, then the problem solved.
Upvotes: 0
Reputation: 130
For me, it looks like you can display a clickable link to a file, provided :
for example, your file is "main.py"
and your project root is "/Users/puiseux/GitHub/myproject"
then the two lines
>>> filename = "/Users/puiseux/GitHub/myproject/main.py"
>>> print('File "%s", line %d' % (filename, 12))
will display a clickable link to the line 12 of file "main.py"
File "/Users/puiseux/GitHub/crypto/main.py", line 12
If you do not fulfill one of three conditions, it does not work
Upvotes: 1
Reputation: 12900
The ideal solution you are asking for would be configuring clickable URL links in the editor window but that is not currently supported by PyCharm.
That kind of configuration is hardcoded in the PyCharm IDE. For example, URLs are clickable if they're inside a Python comment or a Markdown file, but they can't be turned on/off; only the colors highlights can be configured (and thus the corresponding dialogues in the settings are an integral part of PyCharm that can't be changed.) Neither is there any way to create new file types with those configurations. You can see one such example by going to File
>
Settings
>
Editor
>
Color Scheme
>
Markdown
and checking the Auto Link
item in the list.
In these cases the alternative to your specification would be installing a plugin that implements the functionality. I searched the JetBrains Marketplace but I think no plugin is currently available that implements what you want. (A few are close, like TxtReader or Awesome Console but these still rely on sending the file/output to the console, they don't make the links clickable in the editor window.)
Having said that, the closest native alternative using vanilla PyCharm (without installing plugins) would be running the Terminal as an External tool to read the .txt
file. This has the desirable advantage of opening the file inside the IDE and since PyCharm supports several terminals you get the flexibility of using the terminal specific settings you prefer.
Here's an example of configuring PyCharm's External Tool to open the .txt
using Window's CMD. (Using the command line arguments /c more
is terminal specific. Also notice the use of the $FilePath$
and $ProjectFileDir$
PyCharm specific macros.)
After your External Tool is configured you can use it by right clicking on the open file in the editor window or in the Project files view. In the terminal you can see the .txt
file having the clickable URL.
Another alternative could be configuring the IDE's External Tool to launch a 3rd party text editor to open the .txt
file; but the main drawback of that approach is it would open the file outside PyCharm.
Upvotes: 2