Davejkane / riv

Riv - The Rust Image Viewer
MIT License
100 stars 10 forks source link

Feat command mode #58

Closed NickHackman closed 5 years ago

NickHackman commented 5 years ago

Features

Known bugs:

Future Fixes

@gurgalex Here's how I'm handling it, few bugs I wanted to iron out before setting up the pull request

NickHackman commented 5 years ago

@Davejkane, @gurgalex potential future issues based off of work done in command mode and discussed in #57

Future Feature Issues

Any other ideas? I feel like these are good first issues that require some work, but not like a crazy amount where they need to understand how the app functions as a whole.

edit: moved from a sub comment into main discussion.

gurgalex commented 5 years ago

Good First Issue Add the delete command to command mode, which should follow the format :delete /path/to/image regex or :d /path/to/image otherwise delete current image from self.paths.images. Don't actually delete the file

Maybe untrack?. I'd like to reserve the word delete or remove for actually deleting an mage from storage. Yes, the fn name currently is called remove_image, so possibly need to rename that sometime.

NickHackman commented 5 years ago

Update on progress:

Opening code for review

NickHackman commented 5 years ago

@Davejkane thanks for the advice/review! in the future I'm going to have a more cross platform mindset compared to currently as that seems like a big issue. In addition to that a more proactive mindset as well some of the code I wrote in this was quick and dirty/sketchy. I'm going to iron out these issues ASAP :smiley:

Yeah... this seemed like it wouldn't be too bad going in, but quickly became this behemoth.

I think that we should remove all the normal mode features from src/program/mod.rs -> src/program/normal_mode.rs or something along those lines to better layout the project, just a thought though

Davejkane commented 5 years ago

As far as I'm concerned, there's just a couple of things left. And that's the "colon is not necessarily shift+semi-colon" issue. And then there were some actions that appeared to be unprocessed and so I'm not sure if they would apply to the dot operator, but it could be that I've misunderstood a change there.

gurgalex commented 5 years ago

@Davejkane @NickHackman Layout independent : could be resolved with a mixture of keycodes and scancodes.

Use keycodes for detecting when the OS generates a LSHIFTMOD or RSHIFTMOD. Match the scancode for a ; on a QWERTY keyboard.

KeyDown event struct

From sdl2 docs

SDL_Scancode values are used to represent the physical location of a keyboard key on the keyboard.

SDL_Keycode values are mapped to the current layout of the keyboard and correlate to an SDL_Scancode.

Which one to use is left to the application: scancodes are suited in situations where controls are layout-dependent (eg. the "WASD" keys as left-handed arrow keys), whereas keycodes are better suited to situations where controls are character-dependent (eg. the "I" key for Inventory).

NickHackman commented 5 years ago

@Davejkane Little confused what you're referring to, what operations were being unprocessed?

@gurgalex Thanks

Thanks so much for the input it has helped monumentally, and sorry that this has taken so long :heart:

Davejkane commented 5 years ago

I'm not sure I'm with you there @gurgalex. The problem isn't that semi-colon is sometimes in a different place, the problem is that colon is not always shift+semi-colon. For example, on a French keyboard (AZERTY) it is an unshifted key, whereas on a German keyboard (QWERTZ), it is shift+comma. So I'm not sure what you are suggesting would work.

NickHackman commented 5 years ago

Yeah, going to use scancode which uses the virtual mapping, going to convert that then check to see if it matches afterwards. I think that's keyboard independent.

Davejkane commented 5 years ago

@NickHackman I see that I've misunderstood something there with the unprocessed actions. So just ignore that comment. Just the colon key to handle and then I'm happy.

gurgalex commented 5 years ago

@Davejkane

I'm not sure I'm with you there @gurgalex. The problem isn't that semi-colon is sometimes in a different place, the problem is that colon is not always shift+semi-colon. For example, on a French keyboard (AZERTY) it is an unshifted key, whereas on a German keyboard (QWERTZ), it is shift+comma. So I'm not sure what you are suggesting would work.

Right, so scancodes return the QWERTY key which corresponds to the physical location of the key pressed regardless of OS keyboard mapping. So, a keypress on an AZERTY or QWERTZ in the same physical location will return the same scancode. (Assuming the hardware mapping isn't different)

Davejkane commented 5 years ago

Actually, one last thing! If the bar is hidden because it is toggled off with the t key, then entering command mode should force it to be rendered.

Davejkane commented 5 years ago

Also, something has been broken with move and delete image. The length of the images vector isn't updated, so the program crashes when moving to the last image. I'm going to have to do a bit more QA on this to see if anything else is broken.

gurgalex commented 5 years ago

@NickHackman

the following results in a panic.

Enter command mode (:)

type ng (no space)

Press Enter

thread 'main' panicked at 'byte index 3 is out of bounds of `ng`', src/libcore/str/mod.rs:2010:9
Davejkane commented 5 years ago

@gurgalex, I'm still not sure I understand what you mean. Are you suggesting that a German user types in Ö to enter command mode? Because that would be what they would be doing to use the key that is physically in place where an American keyboard has semi-colon.

gurgalex commented 5 years ago

Are you suggesting that a German user types in Ö to enter command mode? Because that would be what they would be doing to use the key that is physically in place where an American keyboard has semi-colon.

@Davejkane Yes.

Davejkane commented 5 years ago

Also, @NickHackman no stress and no rush at all. It's totally fine and normal that things break on a big change like this.

Davejkane commented 5 years ago

@gurgalex I think a German should type colon like everyone else to get into command mode, otherwise we'll be making lots of user manuals.

NickHackman commented 5 years ago

@gurgalex That's not reproducible on my end. Maybe pull again, that was an issue created by me messing up the merging, I fixed that in the latest push.

gurgalex commented 5 years ago

@gurgalex I think a German should type colon like everyone else to get into command mode, otherwise we'll be making lots of user manuals.

@NickHackman Okay, in that case. Matching on TextInput {text: ":", ..} should work instead.

https://docs.rs/sdl2/0.32.2/sdl2/event/enum.Event.html#variant.TextInput

gurgalex commented 5 years ago

@NickHackman You're right. I wasn't using the latest changes.

@gurgalex That's not reproducible on my end. Maybe pull again, that was an issue created by me messing up the merging, I fixed that in the latest push.

Davejkane commented 5 years ago

So sorry @NickHackman, but the command for changing the destination folder isn't handling tilde properly. It creates a folder in the current directory called ~ which is difficult to cd into 😂

NickHackman commented 5 years ago

@Davejkane oh dang, my bad, fixing that asap

gurgalex commented 5 years ago

@NickHackman

Command mode does not trigger if the infobar is set to hidden.

We may need to have two bars (an infobar and a command bar).

The command bar renders over the infobar (or just the image if hidden).

gurgalex commented 5 years ago

Nevermind, it does trigger when hidden. Just was confused about what I had inputted (errors were not shown in input due to hidden bar)

Suggestion about a command bar still may be useful for showing input and errors.

NickHackman commented 5 years ago

@gurgalex now it for sure is visible, just in case.

gurgalex commented 5 years ago

@Davejkane @NickHackman Do you think equivalent command mode operations should be repeatable with . (such as :help) -> Action::Help

gurgalex commented 5 years ago

Vim seems to use @: for repeating the last operation in command mode. https://vim.fandom.com/wiki/Repeat_last_change

gurgalex commented 5 years ago

We could address this later though.

NickHackman commented 5 years ago

@gurgalex that sounds like maybe a different PR, but I like the idea

Davejkane commented 5 years ago

@NickHackman wow, I'm impressed you got through so many tweaks. One of the big ones left is still that when I move or delete an image, the len of the images vector isn't being updated, meaning that then visiting the last file causes an out of bounds panic.

NickHackman commented 5 years ago

@Davejkane I don't think I wrote that bug, but fixed :+1:

edit: Yeah, sorry that is certainly my fault

Davejkane commented 5 years ago

It was working fine before the new max_viewable logic. And as far as I can tell, it isn't fixed. I just tried to delete the last image when I had 4 images, and it crashed the program.

NickHackman commented 5 years ago

@Davejkane I'm confused, that's not reproducible on my end. You updated your local repo after the push right?

Davejkane commented 5 years ago

OK, just tried again and that seems to be fine, think pulling the branch didn't work. The program now seems to be exiting with this error message now Error: "SDL2 error: Text has zero width" when I hit q or esc. I promise that's my last gripe.

NickHackman commented 5 years ago

Honestly guys thank you so much for all the help, I didn't handle so many edge cases that would've come back to haunt me in the near future. I think we ironed at least a large majority of them, can never say they're all gone, but all the ones that I've tested for are gone. I'm honestly really happy with the result and the level of code quality :smile:

It was a joy working with you both on this, and I hope to contribute to the project more in the future :heart:

Probably going to do #53 after this

Davejkane commented 5 years ago

I like the behaviour of the keep folder as it is right now. As a user I'll probably make a keep folder on my desktop and jump around in different folders using new glob, and it's nice that the keep folder doesn't move with me.

I've just got a last little bit of QA to do before my blessing.

NickHackman commented 5 years ago

@Davejkane okay, I'll remove that

Davejkane commented 5 years ago

In the readme, it says that the command ? or help will toggle fullscreen. Please correct that.

~I'm also a little surprised that toggling the help bar with h, and toggling it with the command mode aren't linked, so one can't undo the other. Also, the plain h command no longer works when there are no images loaded on initial load, even if I then newglob to get a bunch of pictures, h doesn't work.~

Scrap that, hadn't seen you fixed it to question mark. 👍

Davejkane commented 5 years ago

@gurgalex are you happy with this PR now? (please approve if so)

gurgalex commented 5 years ago

@Davejkane

Doing some testing to see if this is functioning.

I like the behaviour of the keep folder as it is right now. As a user I'll probably make a keep folder on my desktop and jump around in different folders using new glob, and it's nice that the keep folder doesn't move with me.

gurgalex commented 5 years ago

Seems fine to me. Even though I'm not seeing a commit that undid the changes for a moving ./keep directory.

Davejkane commented 5 years ago

I'll do the merge.