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 an option for ignore layout #274

Open
Monirzadeh opened this issue Dec 19, 2019 · 12 comments
Open

add an option for ignore layout #274

Monirzadeh opened this issue Dec 19, 2019 · 12 comments

Comments

@Monirzadeh
Copy link

hi
i use two layout on my system. lf not detect my shortcut in second layout.
can you add an option in lfrc to ignore keyboard layout (not in commands like rename)?

@gokcehan
Copy link
Owner

@Monirzadeh I'm not sure I understood what you want exactly but I don't think it's possible the way terminals work. We simply read the key from termbox, and termbox I think simply reads the key from the terminal. I don't think even terminals have access to the keyboard layout and simply read the key from the operating system. Where did you get this idea?

@Monirzadeh
Copy link
Author

Monirzadeh commented Dec 20, 2019

for example y key in english represent ‍ غ in Persian
i try to yank a file in Persian i get unknown mapping: غ
so if lf can ignore keyboard layout, y key mean y in any language

this extension has an option for this situation. if you active
option > Advance Options > Ignore keyboard layout
program ignore your language and work correctly

other language has this problem too. i link some other language keyboard layout here
English keyboard
korean keyboard
Persian keyboard
German keyboard

you can use command to acsses English and Russia language (change layout with capslock)

setxkbmap -option grp:caps_toggle "us,ru" -option grp_led:caps &

if you don't get my point say it, i can explain by more detaile or send a screen cast

@gokcehan
Copy link
Owner

@Monirzadeh I think I understand your point, but I don't think it's possible. The extension you provided seems to be a browser extension and browsers can somehow have access to keyboard layouts. Do you have an example of this feature implemented in a terminal application?

I think you should be able to remap current defaults to the keys sent by the terminal:

map y  # unmaps the current default y
map <type y key in your terminal> copy  # maps copy command to your y key

@Monirzadeh
Copy link
Author

Monirzadeh commented Dec 22, 2019

@Monirzadeh I think I understand your point, but I don't think it's possible. The extension you provided seems to be a browser extension and browsers can somehow have access to keyboard layouts. Do you have an example of this feature implemented in a terminal application?

I think you should be able to remap current defaults to the keys sent by the terminal:

map y  # unmaps the current default y
map <type y key in your terminal> copy  # maps copy command to your y key

i am not sure it can be helpful or not
i use sxhkd as hotkey daemon ,if i use this command

setxkbmap -option grp:caps_toggle "us,ru" -option grp_led:caps &

sxhkd ignore my layout and execute my keybinding

@MahouShoujoMivutilde
Copy link
Contributor

I think I understand your point, but I don't think it's possible.

@gokcehan
One way to achieve something like this would be an option like langmap in (neo)vim.

From docs:

This option allows switching your keyboard into a special language
	mode.  When you are typing text in Insert mode the characters are
	inserted directly.  When in Normal mode the 'langmap' option takes
	care of translating these special characters to the original meaning
	of the key.  This means you don't have to change the keyboard mode to
	be able to execute Normal mode commands.

E.g. in my neovim config for russian layout i simply have

" handle russian in normal/selection/etc modes (interpret ш as i, etc)
    " note that :help langmap seems to be slightly wrong
        " , ; and \ as characters need to be escaped with 2 backslashes, not 1
        " " (double quotes) also needs to be escaped in 'translate TO' (after ;) side, but only with one \

    set langmap=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ,фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz,юЮ;.>,бБ;\\,<,эхъ;'[],ЭХЪ;\"{}

Or, if you want just the alphabet, and don't want to deal with escaping stuff

set langmap=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ,фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz

" which means 
" interpret 
"    Ф as A
"    ф as a
"    И as B
"    и as b
"    ...etc

" so something like вфц is interpreted as daw (Delete Around Word), and works correctly.

Also, there is a plugin for ranger that does similar thing.

@MahouShoujoMivutilde
Copy link
Contributor

As a temporary workaround (really far from perfect, yes) i wrote this script.

It generates from this

map <c-n> fzf_rg_select
map o &mimeopen $f
map zh set hidden!
# etc

This

map <c-т> push <c-n>
map щ push o
map яр push zh

It translates to cyrillic by default, but it is trivial to adapt for other layouts, see usage.

@Monirzadeh
Copy link
Author

Monirzadeh commented Jul 11, 2020

As a temporary workaround (really far from perfect, yes) i wrote this script.

It generates from this

map <c-n> fzf_rg_select
map o &mimeopen $f
map zh set hidden!
# etc

This

map <c-т> push <c-n>
map щ push o
map яр push zh

It translates to cyrillic by default, but it is trivial to adapt for other layouts, see usage.

hi thanks for your response i test this command and it is work for some command but some of them not working
for example command not working in Persian layout

map م push l

i get unknown mapping: م

@Monirzadeh
Copy link
Author

Monirzadeh commented Jul 11, 2020

for now i change that from

map م push l

to

map "م" push l

to fix that

@MahouShoujoMivutilde
Copy link
Contributor

MahouShoujoMivutilde commented Jul 11, 2020

@Monirzadeh Thanks, added, didn't even knew you could quote keys. Also fixed bug where mappings like map M push :mkdir<space> were ignored.

@Monirzadeh
Copy link
Author

Monirzadeh commented Jun 29, 2022

@gokcehan Is it possible to lf get keycodes instead of keysyms?
If we can define keycode than lf ignore layout.

@hikkidev
Copy link

@gokcehan check this thread philj56/tofi#41

@MahouShoujoMivutilde
Copy link
Contributor

Sadly, it's not that simple.

Tcell (which is lf's tui backend) doesn't seem to be dealing with keycodes according to dev gdamore/tcell#152 (comment)

There is some mentions of keycodes in code

https://github.com/gdamore/tcell/blob/68adf4676d0747934bbaa073a656ed3005972d1f/key.go#L64-L71

...but those aren't real keycodes:

example code
package main

import (
	"fmt"
	"os"

	"github.com/gdamore/tcell/v2"
	"github.com/gdamore/tcell/v2/encoding"

	"github.com/mattn/go-runewidth"
)

func emitStr(s tcell.Screen, x, y int, str string) {
	for _, c := range str {
		var comb []rune
		w := runewidth.RuneWidth(c)
		if w == 0 {
			comb = []rune{c}
			c = ' '
			w = 1
		}
		s.SetContent(x, y, c, comb, tcell.StyleDefault)
		x += w
	}
}

// Press ESC to exit.
func main() {
	encoding.Register()

	s, e := tcell.NewScreen()
	if e != nil {
		fmt.Fprintf(os.Stderr, "%v\n", e)
		os.Exit(1)
	}
	if e := s.Init(); e != nil {
		fmt.Fprintf(os.Stderr, "%v\n", e)
		os.Exit(1)
	}

	for {
		switch ev := s.PollEvent().(type) {
		case *tcell.EventResize:
			s.Sync()
		case *tcell.EventKey:
			if ev.Key() == tcell.KeyEscape {
				s.Fini()
				os.Exit(0)
			} else {
				s.Clear()
				emitStr(s, 0, 0, fmt.Sprintf("name: %v, key: %v, rune: %v", ev.Name(), ev.Key(), ev.Rune()))
				s.Show()
			}
		}
	}
}
12.28.17.2022.mp4

So different layouts produce different runes and names, but key is just 256 unless you press modifiers / tab / enter / etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants