-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tui: open log files in external application #6611
base: master
Are you sure you want to change the base?
tui: open log files in external application #6611
Conversation
3a22611
to
4eb3f7d
Compare
4eb3f7d
to
853af33
Compare
cylc/flow/tui/overlay.py
Outdated
with tempfile.NamedTemporaryFile('w+') as temp_file: | ||
# write the text into a temp file | ||
temp_file.write(text) | ||
temp_file.seek(0, 0) | ||
|
||
# make the file readonly to avoid confusion | ||
os.chmod(temp_file.name, stat.S_IRUSR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the approach we used to use cylc view
. Dump the text into a temp file and mark it as readonly so that people don't think they can edit it.
Note, we can't reliably edit the file locally because it might not be a local file.
853af33
to
f0695a9
Compare
For coverage, I think you could test this with a fake editor that just reads the file the in, then exits? |
f0695a9
to
c51d584
Compare
* Allow log files to be open in external applications. * Tui will suspend whilst the external tool is open, and resume once it has closed. * Options implemented are `$EDITOR`, `$GEDITOR`, `$PAGER` and `vim` as a backup.
c51d584
to
38b4c09
Compare
I've added an integration test that mocks out the command itself. This isn't really testing very much, but I think it's about all we can do without actually driving an interactive terminal session. |
Co-authored-by: Hilary James Oliver <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, but I think you could go a little bit further to avoid giving the user an editor that they don't know how to use (it is famously traumatic to end up in vim if you're not a vim user...)
- use the value of
$EDITOR
etc. - and possibly also check that each editor (via environment or default) exists on the system
- and if none are available print a help message on what environment vars to configure
That is exactly what this PR is doing?
If the editor is not installed, then they will see the "command not found" error message in the terminal for a few seconds before Tui restores. I don't think we need to be too concerned by users configuring Note, I don't think we need to go any further than interfaces like $ EDITOR=foobar git commit
hint: Waiting for your editor to close the file... error: cannot run foobar: No such file or directory
I have already provided |
I meant print it in the choose-your-editor screen:
Yeah, I saw that. That's fine, I just thought it would be slightly nicer to check if the command exists in
EDITOR can be configured centrally as a default, in which case it is quite possible for it to be an editor that the user doesn't know how to use.
Obviously I love vim and think everyone should be forced to use it, but (a) it is possible for vim not to be installed; and (b) vim is notoriously difficult for the uninitiated. (Famously some years back at NIWA a new vim user repeatedly, accidentally, and irreversibly encrypted his files with a control sequence that performed the encryption using some part of the sequence as the key and then saved the encrypted file and exited the editor 🤣 ) |
IMO it's clearer this way (serves as functional documentation for how to configure). I'm not really sure what you're asking for in the other comments. IMO this PR goes far enough (this was only worth the investment if it could be done quickly). |
Functional documentation is nice, but it's of secondary importance in a UI to functional obviousness. Many users are only vaguely aware, or unaware, of the content of those variables, and some are likely undefined. We could still print a line underneath on how to configure.
|
How about this: I have It is fine to have diff --git a/cylc/flow/tui/overlay.py b/cylc/flow/tui/overlay.py
index a2fb85f3e..c109bb1e9 100644
--- a/cylc/flow/tui/overlay.py
+++ b/cylc/flow/tui/overlay.py
@@ -41,6 +41,7 @@ from functools import partial
import os
import re
import shlex
+from shutil import which
import stat
from subprocess import Popen
import sys
@@ -551,19 +552,25 @@ def log(app, id_=None, list_files=None, get_log=None):
(
'pack',
urwid.Button(
- label,
+ command,
align='left',
on_press=partial(open_in_editor, command=command),
),
)
- for label, command in (
- ('$EDITOR', os.environ.get('EDITOR', 'vim')),
- ('$GEDITOR', os.environ.get('GEDITOR', 'gvim -f')),
- ('$PAGER', os.environ.get('PAGER', 'less')),
- ('vim', 'vim'),
+ for command in set(
+ opt for opt in (
+ os.environ.get('EDITOR', 'vim'),
+ os.environ.get('GEDITOR', 'gvim -f'),
+ os.environ.get('PAGER', 'less'),
+ 'vim'
+ ) if which(opt.split()[0])
)
),
]),
+ urwid.Text(
+ "(Configure apps to open logs via"
+ " $EDITOR, $GEDITOR, $PAGER)"
+ ),
urwid.Divider(),
text_widget,
]), |
Applied suggestion with changes:
|
Requested in: https://cylc.discourse.group/t/feature-request-cylc-tui-searching-job-out-job-err-files/1122/2
$EDITOR
,$GEDITOR
,$PAGER
andvim
as a backup.Check List
CONTRIBUTING.md
and added my name as a Code Contributor.setup.cfg
(andconda-environment.yml
if present).?.?.x
branch.