Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oliver-sanders
Copy link
Member

@oliver-sanders oliver-sanders commented Feb 14, 2025

Requested in: https://cylc.discourse.group/t/feature-request-cylc-tui-searching-job-out-job-err-files/1122/2

  • 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.

tui-external-editor

Check List

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Applied any dependency changes to both setup.cfg (and conda-environment.yml if present).
  • Tests are included - very difficult to test
  • Changelog entry included if this is a change that can affect users
  • Cylc-Doc pull request opened if required at cylc/cylc-doc/pull/797.
  • If this is a bug fix, PR should be raised against the relevant ?.?.x branch.

@oliver-sanders oliver-sanders self-assigned this Feb 14, 2025
@oliver-sanders oliver-sanders added this to the 8.5.0 milestone Feb 14, 2025
@oliver-sanders oliver-sanders force-pushed the tui-open-log-in-external-tool branch from 3a22611 to 4eb3f7d Compare February 14, 2025 15:42
@oliver-sanders oliver-sanders force-pushed the tui-open-log-in-external-tool branch from 4eb3f7d to 853af33 Compare February 14, 2025 15:51
@oliver-sanders oliver-sanders marked this pull request as ready for review February 14, 2025 15:51
Comment on lines 507 to 500
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)
Copy link
Member Author

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.

@oliver-sanders oliver-sanders force-pushed the tui-open-log-in-external-tool branch from 853af33 to f0695a9 Compare February 14, 2025 16:12
@@ -0,0 +1 @@
Tui: Add ability to open log files in external tools. Configure your `$EDITOR`, `$GEDITOR` or `$PAGER` options to configure which tool is used.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much "configure".

Suggested change
Tui: Add ability to open log files in external tools. Configure your `$EDITOR`, `$GEDITOR` or `$PAGER` options to configure which tool is used.
Tui: Add ability to open log files in external tools. Configure your `$EDITOR`, `$GEDITOR` or `$PAGER` options to choose which tool is used.

@hjoliver
Copy link
Member

For coverage, I think you could test this with a fake editor that just reads the file the in, then exits?

@oliver-sanders oliver-sanders force-pushed the tui-open-log-in-external-tool branch from f0695a9 to c51d584 Compare February 18, 2025 16:57
* 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.
@oliver-sanders oliver-sanders force-pushed the tui-open-log-in-external-tool branch from c51d584 to 38b4c09 Compare February 18, 2025 16:57
@oliver-sanders
Copy link
Member Author

For coverage, I think you could test this with a fake editor that just reads the file the in, then exits?

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants