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

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

Open
Neutree opened this issue Mar 16, 2022 · 1 comment

Comments

@Neutree
Copy link

Neutree commented Mar 16, 2022

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
Copy link
Author

Neutree commented Mar 16, 2022

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)

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

No branches or pull requests

1 participant