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

TextArea code editor freezes the app #5151

Closed
Klavionik opened this issue Oct 22, 2024 · 13 comments · Fixed by #5154
Closed

TextArea code editor freezes the app #5151

Klavionik opened this issue Oct 22, 2024 · 13 comments · Fixed by #5154
Labels
bug Something isn't working

Comments

@Klavionik
Copy link

Hey again. :)

Mounting the TextArea code editor with any code other than the comment freezes my terminal. I tried several versions of Textual, I tried running it both on Mac and Linux and using Python 3.10 and 3.12. It freezes every time. I then tried an example from the docs and it freezes too.

An MRE:

from textual.app import App, ComposeResult
from textual.widgets import TextArea

# OK_TEXT = "# OK"
FAIL_TEXT = "x = 1"


class CodeApp(App):
    def compose(self) -> ComposeResult:
        yield TextArea.code_editor(FAIL_TEXT, language="python")


if __name__ == "__main__":
    app = CodeApp()
    app.run()

If you replace usage of FAIL_TEXT with OK_TEXT, it doesn't freeze. Somehow it doesn't freeze with FAIL_TEXT too if you set show_line_numbers=False.

I tried investigating it a bit myself and I found out that the freeze happens because of the while True loop in rich.segment.Segment._split_cells: it keeps counting pos down and never stops. I'm not sure why, though. And I still don't know why the comment works alright even with the line numbers.

Textual Diagnostics

Versions

Name Value
Textual 0.83.0
Rich 13.9.2

Python

Name Value
Version 3.12.3
Implementation CPython
Compiler GCC 11.4.0
Executable /home/jediroman/Desktop/textarea-mre/.venv/bin/python

Operating System

Name Value
System Linux
Release 5.15.0-122-generic
Version #132-Ubuntu SMP Thu Aug 29 13:45:52 UTC 2024

Terminal

Name Value
Terminal Application WezTerm (20230712-072601-f4abf8fd)
TERM xterm-256color
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=105, height=25
legacy_windows False
min_width 1
max_width 105
is_terminal True
encoding utf-8
max_height 25
justify None
overflow None
no_wrap False
highlight None
markup None
height None
Copy link

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@darrenburns
Copy link
Member

Hi, thanks for the report. I can't reproduce this.

Could you please share the full error output?

@TomJGooding
Copy link
Contributor

TomJGooding commented Oct 22, 2024

@darrenburns This freeze only seems to happen with the latest rich version 13.9.2.

I suspect related to Textualize/rich#3532?

@darrenburns
Copy link
Member

darrenburns commented Oct 22, 2024

Yeah, I tried with Rich 13.9.2 and Textual v0.83.0 (and main). There must be some specific condition causing the crash. The width of the TextArea maybe? 🤷

Edit: tried with various sizes and can't reproduce 🤔
Edit2: This is almost certainly an environment issue on my part 🤦 No idea what's happening...
Edit3: pip freeze says rich==13.9.2, and poetry show says rich==13.9.2.
Edit4: Got it!

@darrenburns darrenburns added the bug Something isn't working label Oct 22, 2024
@willmcgugan
Copy link
Collaborator

I'll look in to this today.

@darrenburns
Copy link
Member

darrenburns commented Oct 22, 2024

Ok apparently this bug only happens if the first character in the text area is e.g. w, x, y or z.

a is fine.

It seems to be when line_numbers=True and soft_wrap=False. Also, seems unrelated to it actually being the "code editor". It happens with syntax highlighting off too.

Will has a PR which fixes it but we don't know why 😂

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

@TomJGooding
Copy link
Contributor

Bizarre! After testing working through the alphabet, "o" doesn't seem to crash but "p" does...

@TomJGooding
Copy link
Contributor

After being nerd sniped by this, I couldn't help trying to dig a bit deeper. I found this line in rich/rich/cells.py:

_is_single_cell_widths = re.compile("^[\u0020-\u006f\u00a0\u02ff\u0370-\u0482]*$").match

This might explain why this only seems to occur with certain characters, since this doesn't seem to include lowercase p-z?

@willmcgugan
Copy link
Collaborator

Bravo, Tom!

@darrenburns
Copy link
Member

Thank you Tom, I will sleep tonight!!

@willmcgugan
Copy link
Collaborator

How did you get there so fast @TomJGooding ? We were bamboozled by this.

@TomJGooding
Copy link
Contributor

Haha, definitely a team effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants