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

an issue with clear buffer #26

Closed
mohammadkarami2023 opened this issue Jan 23, 2024 · 11 comments · Fixed by #27
Closed

an issue with clear buffer #26

mohammadkarami2023 opened this issue Jan 23, 2024 · 11 comments · Fixed by #27
Labels
bug Something isn't working

Comments

@mohammadkarami2023
Copy link

I have used termqt in a tab inside a qdialog. whenever i reopen the dialog i use terminal.clear_buffer() to clear the screen but after some tries i get the following errors:
Traceback (most recent call last):

File ~/.local/lib/python3.8/site-packages/termqt/terminal_widget.py:658 in resize
self.resize(self.size().width(), self.size().height())

File ~/.local/lib/python3.8/site-packages/termqt/terminal_widget.py:451 in resize
self._save_cursor_state_stop_blinking()

File ~/.local/lib/python3.8/site-packages/termqt/terminal_widget.py:527 in _save_cursor_state_stop_blinking
self._switch_cursor_blink(CursorState.ON, False)

File ~/.local/lib/python3.8/site-packages/termqt/terminal_widget.py:522 in _switch_cursor_blink
self._paint_cursor()

File ~/.local/lib/python3.8/site-packages/termqt/terminal_widget.py:416 in _paint_cursor
c = self._buffer[ind_y][chr_x]

IndexError: deque index out of range

QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setPen: Painter not active
QPainter::setFont: Painter not active

@TerryGeng
Copy link
Owner

This is a good catch. paint_cursor doesn't check if the cursor is in the valid buffer region. I posted a quick fix #27. Would you please confirm it solves this bug?

On the other hand, I would suggest you reset the cursor position to (0, 0) after clearing the buffer to avoid the cursor position surprising you.

@TerryGeng TerryGeng added the bug Something isn't working label Jan 26, 2024
@mohammadkarami2023
Copy link
Author

thanks, clear buffer now works. another issue happens when the initial command fails. i get the following:
Traceback (most recent call last):

File ~/.local/lib/python3.8/site-packages/termqt/terminal_widget.py:545 in _stdout
need_draw = self._stdout_string(string)

File ~/.local/lib/python3.8/site-packages/termqt/terminal_buffer.py:1378 in _stdout_string
self.write_at_cursor(tst_buf)

File ~/.local/lib/python3.8/site-packages/termqt/terminal_buffer.py:1051 in write_at_cursor
self.write(text, pos=None, set_cursor=True, reset_offset=False)

File ~/.local/lib/python3.8/site-packages/termqt/terminal_buffer.py:1027 in write
buf[pos_y][pos_x] = t

IndexError: list assignment index out of range

@mohammadkarami2023
Copy link
Author

mohammadkarami2023 commented Jan 28, 2024

I also modified the last lines of start.py to test the functionality of clear_buffer. no exceptions happens but in the terminal the current dir is shown twice.

    terminal_io.stdout_callback = terminal.stdout
    terminal.stdin_callback = terminal_io.write
    terminal.resize_callback = terminal_io.resize
    terminal_io.spawn()
    terminal.clear_buffer()
    terminal_io.terminate()
    terminal_io.spawn()
    terminal.set_cursor_position(0, 0)
    terminal.clear_buffer()
    terminal.set_cursor_position(0, 0)
    sys.exit(app.exec())

Terminal looks like

mohammad@mypc:~/Downloads/termqt-240fda2253750944cc922b329ce2d72318de1b78$mohammad@mypc:~/Downloads/termqt-240fda2253750944cc922b329ce2d72318de1b78$

@TerryGeng
Copy link
Owner

Great to know!

Thanks again!

@TerryGeng
Copy link
Owner

Regarding the new issue of lines being displayed twice, I would think it is an issue with the shell itself (since the shell doesn't know the buffer is cleared). I may look into it a bit more today.

@mohammadkarami2023
Copy link
Author

mohammadkarami2023 commented Jan 30, 2024

Thanks, another problem is with command top. the output not shows the apps running

@mohammadkarami2023
Copy link
Author

oh i realized that there is no problem with command top but the font is black similar to the background.
also is there anyway to change the background of the widget?

@TerryGeng
Copy link
Owner

Why the foreground color is black in your case? I believe the default color is white. Can you investigate this?

@mohammadkarami2023
Copy link
Author

my foreground is white. when i execute top command in the bash, the summary of my resources are shown as white, but the processes have black font color

@mohammadkarami2023
Copy link
Author

it seems that the lines that get updated have black foreground color. in my case even the upper lines after a while become black as shown in the following pictures
test
test1

TerryGeng added a commit that referenced this issue Feb 5, 2024
1. Implemented `CSI d` (set cursor vertical absolute) command,
2. Correctly deals with `CSI m` with no arguments (means reset all styles),
3. Correctly recognizes `ESC ( <rest>` (select G0 charset) and discard it.

I don't think G0 charset selection will be needed in modern cases.

Fixed #26.
@TerryGeng
Copy link
Owner

TerryGeng commented Feb 5, 2024

I see. The issue is caused by the broken support for some escape sequences. I have pushed a new commit to #27. Would you have a look?

TerryGeng added a commit that referenced this issue Feb 5, 2024
1. Implemented `CSI d` (set cursor vertical absolute) command,
2. Correctly deals with `CSI m` with no arguments (means reset all styles),
3. Correctly recognizes `ESC ( <rest>` (select G0 charset) and discard it.

I don't think G0 charset selection will be needed in modern cases.

Fixed #26.
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.

2 participants