selectel / pyte

Simple VTXXX-compatible linux terminal emulator
http://pyte.readthedocs.org/
GNU Lesser General Public License v3.0
649 stars 101 forks source link

Charator "➜" makes cursor moves only one step, but in most fonts it is 2 #151

Open Neutree opened 2 years ago

Neutree commented 2 years ago

when use oh-my-zsh , in most mono fonts, the width of charactor is 2, but pyte only move cursor 1, for wcwidth('➜') => 1, is there any way to resolve this problem if I don't want to change the font(cause I didnt find the font which this charactor's width is 1)

image

Neutree commented 2 years ago

haha, to get the cursor width pixel, I used a stupid but works code

        cursor = screen.cursor
        self.cursor_x = cursor.x
        self.cursor_y = cursor.y
        # get the line text where the cursor is
        line = screen.display[self.cursor_y]
        # to get the actual charactors befor cursor.x
        x = self.cursor_x
        while 1:
            w = wcswidth(line[:x])
            if w > self.cursor_x:
                x -= 1
            elif w < self.cursor_x:
                x += 1
            else:
                break
        text = line[:x]
        char = line[x]
        # calculate the pixel width
        width_cursor_x = self.font.width(text)