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

Unable to input multi-byte characters #73

Open
apstndb opened this issue Nov 6, 2024 · 4 comments
Open

Unable to input multi-byte characters #73

apstndb opened this issue Nov 6, 2024 · 4 comments
Labels
bug Something isn't working codes & keys help wanted Extra attention is needed

Comments

@apstndb
Copy link

apstndb commented Nov 6, 2024

I have noticed any wide(multi-byte?) characters can't be input.
Both of them can't success.

  • Paste emoji 😄 from clipboard.
  • Input Japanese characters using macOS Japanese Input Method
@maxlandon maxlandon added bug Something isn't working help wanted Extra attention is needed codes & keys labels Nov 16, 2024
@maxlandon
Copy link
Member

Hello,

This covers two different things: paste large characters, which probably involves a "bracketed paste" functionality that I have yet to implement (the last thing that is to be implemented in this library.)
For the Japanese characters, I must look into it, as I thought the character handling library I'm using (github.com/rivo/uniseg) would handle those just fine.
I will look into this soon,
thanks

@maxlandon
Copy link
Member

See here for the details concerning this:
https://github.com/rivo/uniseg?tab=readme-ov-file#monospace-width

@M09Ic
Copy link

M09Ic commented Nov 17, 2024

I encountered a similar issue, but it happened when inputting Unicode characters.

I finally traced the issue to readline/internal/keymap/dispatch.go, specifically the dispatchKeys function.

This function takes only the first byte of the input regardless of what characters are entered, which causes Unicode characters to be corrupted.

I attempted a simple fix, but I don't think this is the best solution.

func (m *Engine) dispatchKeys(binds map[string]inputrc.Bind) (bind inputrc.Bind, prefix bool, read, matched []byte) {
	for {
		// Read a single byte from the input buffer.
		// This mimics the way Bash reads input when the inputrc option `byte-oriented` is set.
		// This is because the default binds map is built with byte sequences, not runes, and this
		// has some implications if the terminal is sending 8-bit characters (extanded alphabet).
		key, empty := core.PeekKey(m.keys)
		if empty {
			break
		}

		read = append(read, key)

		match, prefixed := m.matchBind(read, binds)

		// If the current keys have no matches but the previous
		// matching process found a prefix, use it with the keys.
		if match.Action == "" && len(prefixed) == 0 {
			prefix = false
			m.active = m.prefixed
			m.prefixed = inputrc.Bind{}
			break
		}
		core.PopKey(m.keys)
		// From here, there is at least one bind matched, by prefix
		// or exactly, so the key we popped is considered matched.
		matched = append(matched, key)

		// If we matched a prefix, keep the matched bind for later.
		if len(prefixed) > 0 {
			prefix = true

			if match.Action != "" {
				m.prefixed = match
			}

			continue
		}

		// Or an exact match, so drop any prefixed one.
		prefix = false
		m.active = match
		m.prefixed = inputrc.Bind{}

		break
	}

	return m.active, prefix, read, matched
}

@apstndb apstndb changed the title Unable to input wide characters Unable to input multi-byte characters Nov 18, 2024
@maxlandon
Copy link
Member

maxlandon commented Feb 11, 2025

Hello @M09Ic,
I'm trying to solve this at the moment.
Wanted to know how did your fix do since tried: adjacent problems created or working fine ?

Your fix is temporarily added in the lastest release, since I've not found any immediate problem with it,
but the issue will stay open to see if other users have related/similar issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working codes & keys help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants