Skip to content

feat: adjust gridtk list output to fit terminal width#15

Merged
183amir merged 7 commits intomainfrom
183amir/adjust-gridtk-list
Mar 7, 2025
Merged

feat: adjust gridtk list output to fit terminal width#15
183amir merged 7 commits intomainfrom
183amir/adjust-gridtk-list

Conversation

@183amir
Copy link
Copy Markdown
Collaborator

@183amir 183amir commented Oct 23, 2024

Fixes #13. By default, gridtk list outputs a table which migh not fit the terminal width.
This PR adds options to adjust the output using the --wrap and --truncate flags. The --wrap
flag wraps the output to fit the terminal width, while the --truncate flag
truncates the output to fit the terminal width.


📚 Documentation preview 📚: https://gridtk--15.org.readthedocs.build/en/15/

183amir and others added 5 commits October 23, 2024 10:59
Fixes #13

Adjust the `gridtk list` output to fit terminal width and add a `--full-output` option.

* **src/gridtk/cli.py**
  - Update the `list_jobs` function to adjust column widths based on terminal size.
  - Add logic to truncate long content with ellipses in the `list_jobs` function.
  - Add a new option `--full-output` to the `list_jobs` command to view the full output without truncation.

* **tests/test_gridtk.py**
  - Add unit tests to verify the new behavior of the `gridtk list` command.
  - Add unit tests to verify the `--full-output` option for the `gridtk list` command.

* **README.md**
  - Update the documentation to reflect the new behavior of the `gridtk list` command.
  - Add information about the `--full-output` option for the `gridtk list` command.

* **.devcontainer.json**
  - Add a devcontainer configuration file with tasks for testing, building, and launching the project.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/idiap/gridtk/issues/13?shareId=XXXX-XXXX-XXXX-XXXX).
…mmand for improved readability

Also, adjust max column widths for output formatting to accommodate new options
* truncates with only 2 dots
* dynamically adjusts the command column to use all the width of the terminal
@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 29, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/gridtk
  cli.py
  manager.py
  models.py
Project Total  

This report was generated by python-coverage-comment-action

@183amir 183amir marked this pull request as ready for review October 29, 2024 23:30
@183amir 183amir requested a review from Yannick-Dayer October 29, 2024 23:30
Copy link
Copy Markdown
Member

@Yannick-Dayer Yannick-Dayer left a comment

Choose a reason for hiding this comment

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

I must have missed the mail for that review.

This is a nice feature!

When testing it however, I noticed issues with both --wrap and --truncate options when using a small terminal width (<=87 for truncate, and <=95 for wrap). The total width somehow exceeds the width of the terminal and wraps some full lines (like the header separator).

list --wrap with width 95
With a terminal width of 95 and the --wrap option. Notice the - of the header separator and the t of submit.

I think this is due to tabulate adding some horizontal padding to some columns despite specifying their maxcolwidths parameters.

@183amir
Copy link
Copy Markdown
Collaborator Author

183amir commented Nov 26, 2024

Yes, I have found the output of tabulate quite unpreditable regarding this. Not sure what to do here.

@Yannick-Dayer
Copy link
Copy Markdown
Member

One solution to prevent overflows would be to force the padding to 0 (tabulate.MIN_PADDING = 0), but this results in a table that is smaller than it needs and feels more cramped (it leaves a lot of space unused due to most columns ending under their maxcolwidths).

Screenshot from 2024-11-26 22-10-43

@183amir
Copy link
Copy Markdown
Collaborator Author

183amir commented Nov 27, 2024

could you show a before and after photo? I am not sure I understand what changed.

@183amir 183amir requested a review from Yannick-Dayer March 7, 2025 13:02
Copy link
Copy Markdown
Member

@Yannick-Dayer Yannick-Dayer left a comment

Choose a reason for hiding this comment

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

Sorry, I dropped that.
I did test it and it works great except in the cases stated above.

If the issue with smaller terminal width is not too bad for you, I'm approving it and you can merge.

@183amir 183amir changed the title Adjust gridtk list output to fit terminal width feat: adjust gridtk list output to fit terminal width Mar 7, 2025
@183amir 183amir merged commit f324491 into main Mar 7, 2025
@183amir 183amir deleted the 183amir/adjust-gridtk-list branch March 7, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adjust gridtk list output to fit terminal width

2 participants