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

Add linewrap option 'auto' #1507

Merged
merged 8 commits into from
Jul 30, 2022
Merged

Conversation

jonakeys
Copy link
Contributor

@jonakeys jonakeys commented Jun 12, 2022

This resolves the feature request #1246 It adds the possibility to set 'auto' as linewrap option so jrnl automatically determines the width of the terminal/columns.

I chose to do the check while outputting information. The downside is that when using the debug flag it outputs a line for every entry. But it could also be done earlier when the config file is being read. Would that be better? If so, I'll modify the code to do so.

Fixes #1246

Checklist

  • I have read the contributing doc.
  • I have included a link to the relevant issue number.
  • I have checked to ensure there aren't other open pull requests
    for the same issue.
  • I have written new tests for these changes, as needed.

Copy link
Member

@micahellison micahellison left a comment

Choose a reason for hiding this comment

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

I have a small nitpick on the except clause, and I think this also needs some tests, either a unit test or a BDD test. Let us know if you'd like any help with that.

jrnl/Entry.py Outdated
if columns == "auto":
try:
columns = os.get_terminal_size()[0]
except: # noqa: E722
Copy link
Member

Choose a reason for hiding this comment

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

Could you use except OSError here? The docs for get_terminal_size say that's the exception that fires when it can't get the terminal size for standard out, I'd like to avoid generic exceptions.

@jonakeys
Copy link
Contributor Author

Thanks for your remarks! I can easily specify the except clause.
But for the tests I need some help. I can create a test for the 'auto' linewrap option. But how do I create a test that checks if the get_terminal_size fires the exception?

@micahellison
Copy link
Member

We're working on the finishing touches of the 3.0 beta and are going to prioritize that now, but I'll get back to this PR to review in a week or so. Thanks for your work so far on it!

@jonakeys
Copy link
Contributor Author

That's no problem, I'm happy to contribute where I can.
And ofcourse the v3.0 has full focus now for you as maintainers. Good luck!

Copy link
Member

@micahellison micahellison left a comment

Choose a reason for hiding this comment

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

One minor issue - this is broken with the "fancy" format. Could you take a look? It has its own code in jrnl/plugins/fancy_exporter.py. Thanks!

tests/bdd/features/config_file.feature Show resolved Hide resolved
@wren wren added the enhancement New feature or request label Jul 30, 2022
Copy link
Member

@micahellison micahellison left a comment

Choose a reason for hiding this comment

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

Thanks for making this change. It's working well for me. I don't like seeing the same code in multiple places at once, but this is a more of a problem with jrnl's architecture than with your PR. We eventually want to refactor the Journal/Entry classes as mentioned in #1184 to separate presentation from data travel, and that's way outside of the scope of this PR.

@micahellison micahellison merged commit 80bfff3 into jrnl-org:develop Jul 30, 2022
@jonakeys
Copy link
Contributor Author

You're welcome, glad I can contribute! I'm also not a fan of duplicate code myself. But to fix it would need to create a function in a shared file with another import as consequence. That wouldn't be beautiful too. When the refactoring takes place, it will resolve issues like this indeed.

@jonakeys jonakeys deleted the auto-linewrap branch July 30, 2022 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow for automatic line wrapping based on detected console width
3 participants