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

Alt+Enter newline shortcut #3

Merged
merged 3 commits into from
Nov 27, 2020
Merged

Alt+Enter newline shortcut #3

merged 3 commits into from
Nov 27, 2020

Conversation

goolord
Copy link
Contributor

@goolord goolord commented Aug 2, 2020

in most messaging apps, shift+enter enters a newline character. this pr adds that behavior.
currently i'm unable to test if this behaves as intended because running gurk panics for me

@boxdot
Copy link
Owner

boxdot commented Aug 2, 2020

Thank you! I had the same implementation but it does not work: crossterm-rs/crossterm#400.

off-topic: If you have the line number where it panics, I might be able to fix it.

@goolord
Copy link
Contributor Author

goolord commented Aug 2, 2020

I'll create a seperate issue about the panic.
What about Alt+Enter? That's how my terminal allows entering newlines

edit: and the sequence is supported

edit 2: ah, the panic mentioned earlier is solved at #7

@boxdot
Copy link
Owner

boxdot commented Aug 3, 2020

What about Alt+Enter? That's how my terminal allows entering newlines

Sounds good!

@goolord goolord force-pushed the master branch 4 times, most recently from 588a4da to a7ac6ad Compare August 3, 2020 13:24
@goolord
Copy link
Contributor Author

goolord commented Aug 3, 2020

Ok, I write very little rust but hopefully nothing looks off. The solution is a little janky, crossterm reads Alt+Enter as '\r', so all of the logic is actually in draw_chat. Even though this eliminated the need for the key modifiers, I left the put_char function factored out because I think it's nice.

@goolord goolord changed the title Shift+Enter newline shortcut Alt+Enter newline shortcut Aug 3, 2020
@boxdot
Copy link
Owner

boxdot commented Aug 4, 2020

Ok, I write very little rust but hopefully nothing looks off.

No worries. :) I appreciate the contribution a lot.

The solution is a little janky, crossterm reads Alt+Enter as '\r', so all of the logic is actually in draw_chat. Even though this eliminated the need for the key modifiers, I left the put_char function factored out because I think it's nice.

I like the factored out function. I was thinking that now, in the current implementation, we send \r to the Signal server. I guess we could replace \r just by \n in the input field on input? Then there is no need for special handling in ui, right?

@goolord
Copy link
Contributor Author

goolord commented Aug 4, 2020

I'm not familiar enough with tui to know why this is, but the '\n' (and '\r') character doesn't actually visually create a newline, instead each index in lines: Vec<String> is rendered as a new line.. it ends up being fine I think because it helps in calculating the y position of the input cursor. Also, I just pushed a commit which fixes a few bugs that were introduced by rendering '\n' characters

src/ui.rs Show resolved Hide resolved
src/ui.rs Show resolved Hide resolved
@boxdot boxdot self-requested a review November 27, 2020 16:19
Copy link
Owner

@boxdot boxdot left a comment

Choose a reason for hiding this comment

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

Private life got me, new job, etc... ☔ I am really sorry for being not responsive.

@boxdot boxdot merged commit 6f7b845 into boxdot:master Nov 27, 2020
@boxdot
Copy link
Owner

boxdot commented Feb 2, 2022

@goolord I hope you are fine with me changing this behavior. With #131, Alt+Enter will be remapped to switch between the multi-line and single-line modes.

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.

2 participants