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

Disable line wrap #983

Merged
merged 10 commits into from
Mar 17, 2023
Merged

Disable line wrap #983

merged 10 commits into from
Mar 17, 2023

Conversation

o2sh
Copy link
Owner

@o2sh o2sh commented Mar 15, 2023

@o2sh o2sh changed the title Feat/line wrap Disable line wrap Mar 15, 2023
Comment on lines 138 to 144
// Disable line wrapping
write!(self.writer, "\x1B[?7l")?;

write!(self.writer, "{buf}")?;

// Re-enable line wrapping
write!(self.writer, "\x1B[?7h")?;
Copy link
Owner Author

@o2sh o2sh Mar 17, 2023

Choose a reason for hiding this comment

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

@spenserblack

I believe this approach is relatively safe. My main concern was to avoid leaving the user's terminal in a modified state if an error occurred, with line wrapping still disabled. However, based on this diff, the only situation where that might happen is if the program panics at line 141.

What are your thoughts on this?

Another option could be to implement the Drop trait to Printer<W> and include write!(self.writer, "\x1B[?7h")? in it. However, that might be excessive 🤔 . What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, this looks good to me! Since Drop::drop doesn't return a Result, the call to write! would have to unwrap, right? Probably best to keep potentially panicking code out of drop 🙂

Any reason not to make it one call to write! instead of 3?

Copy link
Owner Author

Choose a reason for hiding this comment

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

No, this looks good to me! Since Drop::drop doesn't return a Result, the call to write! would have to unwrap, right? Probably best to keep potentially panicking code out of drop 🙂

Very well, that reassures me 😩

Any reason not to make it one call to write! instead of 3?

You're right it's better if we merge them into one -> ddba00b

Comment on lines 138 to 144
// Disable line wrapping
write!(self.writer, "\x1B[?7l")?;

write!(self.writer, "{buf}")?;

// Re-enable line wrapping
write!(self.writer, "\x1B[?7h")?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

No, this looks good to me! Since Drop::drop doesn't return a Result, the call to write! would have to unwrap, right? Probably best to keep potentially panicking code out of drop 🙂

Any reason not to make it one call to write! instead of 3?

@spenserblack
Copy link
Collaborator

Didn't mean to duplicate comments. That's an odd behavior of GitHub 🤔 😆

@o2sh
Copy link
Owner Author

o2sh commented Mar 17, 2023

Thanks for the review @spenserblack

I didn't expect this issue to be resolved with a one-line PR. 😅

@o2sh o2sh merged commit 71ea9c1 into main Mar 17, 2023
@o2sh o2sh deleted the feat/line-wrap branch March 17, 2023 23:03
@o2sh o2sh mentioned this pull request Mar 18, 2023
1 task
@spenserblack
Copy link
Collaborator

Just thought of something: how does Ctrl+C handle this? If onefetch is taking a long time (like in a massive repo) a user might try to terminate the process. Could that potentially leave the terminal in a "no wrap" state?

@o2sh
Copy link
Owner Author

o2sh commented Mar 20, 2023

That's a good point. But since we disable line wrapping only after generating the output, we should be fine. If the user decides to halt the program, it is likely to happen during the commit traversal or language stat computation stages.

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.

None yet

2 participants