Git Product home page Git Product logo

Comments (9)

sleibrock avatar sleibrock commented on July 22, 2024

This might not be entirely supported yet, since the EraseNPreviousChars(n) function erases N amount of characters at a time. You can see how the backspace function is implemented a few lines down on that file here

case keyBackspace:
if t.pos == 0 {
return
}
t.eraseNPreviousChars(1)

I am not super familiar enough with the keyboard I/O code personally, but I don't think ssh-chat is contextually aware of what your user locale is going to be exactly. The server side is responsible for key inputs and rendering the readline functionality, but its probable that ssh-chat doesn't have enough contextual information for each user to be able to do this. To ssh-chat, when you enter a 2-byte character, ssh-chat sees exactly 2-bytes. It doesn't process whether or not that might be a rune, it only handles it at an individual byte level.

from ssh-chat.

shazow avatar shazow commented on July 22, 2024

Hi @jonnyliang, I'm not able to reproduce this. It may be an issue with your terminal, or compatibility between your terminal and how we handle unicode character width counting:

image

What terminal are you using? Could you try a modern terminal like kitty or alacritty?

from ssh-chat.

sheng-ri avatar sheng-ri commented on July 22, 2024

I reproduce it. That is terminal compatibility issue.
In alacritty,it works perfect.
In cmd/powershell/windows temiernal, It will leave char after chinese in buffer(I guess)

(Delete chinese from the end of input)
image
(Delete chinese from the middle of input.And enf of input " g g" is display after delete)
image

Versions

Client version: Ubuntu 22.04
Server version:Windows 11
ssh-chat version: 1.10,1.11-rc5

from ssh-chat.

shazow avatar shazow commented on July 22, 2024

Yea, that's a terminal issue unfortunately, they don't count character width the same way as modern terminals. There's no way to support both.

from ssh-chat.

jonnyliang avatar jonnyliang commented on July 22, 2024

Hi @jonnyliang, I'm not able to reproduce this. It may be an issue with your terminal, or compatibility between your terminal and how we handle unicode character width counting:

image

What terminal are you using? Could you try a modern terminal like kitty or alacritty?

You are right, this a terminal issue unfortunately, it will leave half of a char when I using XSHELL 5. it work by using alacritty! thanks!

from ssh-chat.

jonnyliang avatar jonnyliang commented on July 22, 2024

Yea, that's a terminal issue unfortunately, they don't count character width the same way as modern terminals. There's no way to support both.
By the way, I fixed the problem on my local code as below, it seems work well on alacritty and XSHELL,but I not sure its ok.

//
_, _, left, _ := t.moveCursorToPos(t.pos)
copy(t.line[t.pos:], t.line[n+t.pos:])
t.line = t.line[:len(t.line)-n]
if t.echo {
t.writeLine(t.line[t.pos:])
for i := 0; i < left; i++ {
t.queue(space)
}
t.advanceCursor(left)
....

from ssh-chat.

jonnyliang avatar jonnyliang commented on July 22, 2024

reproduce on alacritty~!
截图_1675848773743

from ssh-chat.

shazow avatar shazow commented on July 22, 2024

If you have a patch that fixes this and doesn't break other things, please make a PR and I'll take a look. :)

from ssh-chat.

jonnyliang avatar jonnyliang commented on July 22, 2024

I just modified content of two functions,Hope for better solution!

ssh-chat/sshd/terminal/terminal.go


func (t *Terminal) moveCursorToPos(pos int) (up, down, left, right int) {
  ...
  return up, down, left, right
}

func` (t *Terminal) eraseNPreviousChars(n int) {
        if n == 0 {
                return
        }

        if t.pos < n {
                n = t.pos
        }
        t.pos -= n
        //t.moveCursorToPos(t.pos)
       //-----------fixed begin------------------------------ 
        up, _, left, _ := t.moveCursorToPos(t.pos) 
        if left ==0{
            if up == 1{left =up}
        }
        //-----------fixed end------------------------------ 
        copy(t.line[t.pos:], t.line[n+t.pos:])
        t.line = t.line[:len(t.line)-n]
        if t.echo {
                t.writeLine(t.line[t.pos:])
                for i := 0; i < left; i++ { // left  replace n 
                        t.queue(space)
                }
                t.advanceCursor(left)
                t.moveCursorToPos(t.pos)
        }
}

from ssh-chat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.