kamiyaa / joshuto

ranger-like terminal file manager written in Rust
https://crates.io/crates/joshuto
GNU Lesser General Public License v3.0
3.34k stars 151 forks source link

[feature] scroll preview with ctrl+up/ctrl+down; edit: `preview_cursor_move_up/down` was already existent ... I didnt know about it. #186

Closed alexzanderr closed 1 year ago

alexzanderr commented 1 year ago

Hello.

Love your project. Its blazingly fast.

Is there a way to scroll down/up the preview ? image

For example I want to:

In ranger, you could do that with:

If there is no way to do that right now, I would like to make a feature request.

Thanks.

alexzanderr commented 1 year ago

I've found a scroll_offset = 6 inside joshuto.toml.

Does this have a related context with the scrolling I'm talking about.

DLFW commented 1 year ago

Hi! Nope. The scroll_offset defines how many entries in the file list are kept at the border after/before the cursor when scrolling. Move the cursor down a long list of files and and you will see that Joshuto starts scrolling the file list when your cursor is 6 entries away from the bottom of the list. See commit msg.

I'm not completely sure but I think that the feature of scrolling the preview is not available in Joshuto right now.

alexzanderr commented 1 year ago

oh. okey. thanks for response

kamiyaa commented 1 year ago

Hey, this feature already exists with preview_cursor_move_up preview_cursor_move_down :)

You can learn more about it in the docs here: https://github.com/kamiyaa/joshuto/blob/main/docs/configuration/keymap.toml.md

alexzanderr commented 1 year ago

Ok. I've followed the instructions in the keymap.toml.md. This is my attempt:

[default_view]
keymap = [
    { keys = [ "ctrl+arrow_up"], command = "preview_cursor_move_up" },
    { keys = [ "ctrl+arrow_down"], command = "preview_cursor_move_down" },
# ....
]

When running the program doesnt work and says after exit:

❱  cargo run --all-features
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/joshuto`
Error: Keybindings ambiguous for preview_cursor_move_down
Error: Keybindings ambiguous for preview_cursor_move_down
Error: Keybindings ambiguous for preview_cursor_move_down

and also the command :preview_cursor_move_down its working, but my keymap seems that is not registered properly

alexzanderr commented 1 year ago
    { keys = [ "T" ], command = "preview_cursor_move_down" },

this works.

so the keymap its not registered

kamiyaa commented 1 year ago

The ambiguous error means you have multiple commands mapped to ctrl+arrow_down and joshuto doesn't know what to do

alexzanderr commented 1 year ago

ok here's the entire keymap toml

# ~/.config/joshuto/keymap.toml

[default_view]
keymap = [
    { keys = [ "ctrl+arrow_up"], command = "preview_cursor_move_up" },
    { keys = [ "ctrl+arrow_down"], command = "preview_cursor_move_down" },

    { keys = [ "T" ],       command = "new_tab" },
    { keys = [ "ctrl+t" ],      command = "new_tab" },
    { keys = [ "W" ],       command = "close_tab" },
    { keys = [ "ctrl+w" ],      command = "close_tab" },
    { keys = [ "q" ],       command = "close_tab" },
    { keys = [ "Q" ],       command = "quit --output-current-directory" },

    { keys = [ "R" ],       command = "reload_dirlist" },
    { keys = [ "z", "h" ],      command = "toggle_hidden" },
    { keys = [ "ctrl+h" ],      command = "toggle_hidden" },
    { keys = [ "\t" ],      command = "tab_switch 1" },
    { keys = [ "backtab" ],     command = "tab_switch -1" },

    { keys = [ "alt+1" ],       command = "tab_switch_index 1" },
    { keys = [ "alt+2" ],       command = "tab_switch_index 2" },
    { keys = [ "alt+3" ],       command = "tab_switch_index 3" },
    { keys = [ "alt+4" ],       command = "tab_switch_index 4" },
    { keys = [ "alt+5" ],       command = "tab_switch_index 5" },

    # arrow keys
    { keys = [ "arrow_up" ],    command = "cursor_move_up" },
    { keys = [ "arrow_down" ],  command = "cursor_move_down" },
    { keys = [ "arrow_left" ],  command = "cd .." },
    { keys = [ "arrow_right" ], command = "open" },
    { keys = [ "\n" ],      command = "open" },
    { keys = [ "home" ],        command = "cursor_move_home" },
    { keys = [ "end" ],     command = "cursor_move_end" },
    { keys = [ "page_up" ],     command = "cursor_move_page_up" },
    { keys = [ "page_down" ],   command = "cursor_move_page_down" },
    { keys = [ "ctrl+u" ],      command = "cursor_move_page_up 0.5" },
    { keys = [ "ctrl+d" ],      command = "cursor_move_page_down 0.5" },

    # vim-like keybindings
    { keys = [ "j" ],       command = "cursor_move_down" },
    { keys = [ "k" ],       command = "cursor_move_up" },
    { keys = [ "h" ],       command = "cd .." },
    { keys = [ "l" ],       command = "open" },
    { keys = [ "g", "g" ],      command = "cursor_move_home" },
    { keys = [ "G" ],       command = "cursor_move_end" },
    { keys = [ "r" ],       command = "open_with" },

    { keys = [ "H" ],       command = "cursor_move_page_home" },
    { keys = [ "L" ],       command = "cursor_move_page_middle" },
    { keys = [ "M" ],       command = "cursor_move_page_end" },

    { keys = [ "[" ],       command = "parent_cursor_move_up" },
    { keys = [ "]" ],       command = "parent_cursor_move_down" },

    { keys = [ "c", "d" ],      command = ":cd " },
    { keys = [ "d", "d" ],      command = "cut_files" },
    { keys = [ "y", "y" ],      command = "copy_files" },
    { keys = [ "p", "p" ],      command = "paste_files" },
    { keys = [ "p", "o" ],      command = "paste_files --overwrite=true" },

    { keys = [ "y", "n" ],      command = "copy_filename" },
    { keys = [ "y", "." ],      command = "copy_filename_without_extension" },
    { keys = [ "y", "p" ],      command = "copy_filepath" },
    { keys = [ "y", "d" ],      command = "copy_dirpath" },

    { keys = [ "delete" ],      command = "delete_files" },
    { keys = [ "d", "D" ],      command = "delete_files" },

    { keys = [ "a" ],       command = "rename_append" },
    { keys = [ "A" ],       command = "rename_prepend" },

    { keys = [ "f", "t" ],      command = ":touch " },

    { keys = [ " " ],       command = "select --toggle=true" },
    { keys = [ "t" ],       command = "select --all=true --toggle=true" },

    { keys = [ "w" ],       command = "show_tasks --exit-key=w" },
    { keys = [ "b", "b" ],      command = "bulk_rename" },
    { keys = [ "=" ],       command = "set_mode" },

    { keys = [ ":" ],       command = ":" },
    { keys = [ ";" ],       command = ":" },

    { keys = [ "'" ],       command = ":shell " },
    { keys = [ "m", "k" ],      command = ":mkdir " },
    { keys = [ "f2" ],      command = ":rename " },

    { keys = [ "/" ],       command = ":search " },
    { keys = [ "|" ],       command = ":search_inc " },
    { keys = [ "\\" ],      command = ":search_glob " },
    { keys = [ "S" ],       command = "search_fzf" },
    { keys = [ "C" ],       command = "subdir_fzf" },

    { keys = [ "n" ],       command = "search_next" },
    { keys = [ "N" ],       command = "search_prev" },

    { keys = [ "s", "r" ],      command = "sort reverse" },
    { keys = [ "s", "l" ],      command = "sort lexical" },
    { keys = [ "s", "m" ],      command = "sort mtime" },
    { keys = [ "s", "n" ],      command = "sort natural" },
    { keys = [ "s", "s" ],      command = "sort size" },
    { keys = [ "s", "e" ],      command = "sort ext" },

    { keys = [ "g", "r" ],      command = "cd /" },
    { keys = [ "g", "c" ],      command = "cd ~/.config" },
    { keys = [ "g", "d" ],      command = "cd ~/Downloads" },
    { keys = [ "g", "e" ],      command = "cd /etc" },
    { keys = [ "g", "h" ],      command = "cd ~/" },
    { keys = [ "?" ],       command = "help" }
]

[task_view]
keymap = [
    # arrow keys
    { keys = [ "arrow_up" ],    command = "cursor_move_up" },
    { keys = [ "arrow_down" ],  command = "cursor_move_down" },
    { keys = [ "home" ],        command = "cursor_move_home" },
    { keys = [ "end" ],     command = "cursor_move_end" },

    # vim-like keybindings
    { keys = [ "j" ],       command = "cursor_move_down" },
    { keys = [ "k" ],       command = "cursor_move_up" },
    { keys = [ "g", "g" ],      command = "cursor_move_home" },
    { keys = [ "G" ],       command = "cursor_move_end" },

    { keys = [ "w" ],       command = "show_tasks" },
    { keys = [ "escape" ],      command = "show_tasks" },
]

[help_view]

keymap = [
    # arrow keys
    { keys = [ "arrow_up" ],    command = "cursor_move_up" },
    { keys = [ "arrow_down" ],  command = "cursor_move_down" },
    { keys = [ "home" ],        command = "cursor_move_home" },
    { keys = [ "end" ],     command = "cursor_move_end" },

    # vim-like keybindings
    { keys = [ "j" ],       command = "cursor_move_down" },
    { keys = [ "k" ],       command = "cursor_move_up" },
    { keys = [ "g", "g" ],      command = "cursor_move_home" },
    { keys = [ "G" ],       command = "cursor_move_end" },

    { keys = [ "w" ],       command = "show_tasks" },
    { keys = [ "escape" ],      command = "show_tasks" },
]

there is only one command with the keymap: ctrl+arrow_down

file is located at: ~/.config/joshuto/keymap.toml

the bug is the same with:

alexzanderr commented 1 year ago

still getting the

❱  cargo run --all-features
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/joshuto`
Error: Keybindings ambiguous for preview_cursor_move_down
kamiyaa commented 1 year ago

So it looks like termion (the library that joshuto uses for input), it only supports Ctrl/Alt + a character https://docs.rs/termion/latest/termion/event/enum.Key.html

So Ctrl+arrow_up/arrow_down is currently not supported

https://gitlab.redox-os.org/redox-os/termion/-/issues/194

https://gitlab.redox-os.org/redox-os/termion/-/merge_requests/175

alexzanderr commented 1 year ago

Well... I would like to propose a migration for the terminal backend to crossterm.

I've used crossterm before and the reason for migrating to crossterm was exactly the same as this one. Termion lacks Ctrl+non-ascii.

I can make a PR and also create a new issue for this situation. You decide.

alexzanderr commented 1 year ago

Oh, just saw that there is a PR waiting for that feature in termion. Well ... we can make separate features and let the users decide which backend to use.

# ...
default = ["termion-backend"]
termion-backend = []
crossterm-backend = []
# ...
alexzanderr commented 1 year ago

temporarily, i can use this

    { keys = [ "j"], command = "preview_cursor_move_up" },
    { keys = [ "k"], command = "preview_cursor_move_down" },

thanks for help.