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

Flickering #240

Open
iganinja opened this issue Apr 12, 2023 · 20 comments
Open

Flickering #240

iganinja opened this issue Apr 12, 2023 · 20 comments

Comments

@iganinja
Copy link

Hi

I'm using cpp-terminal to program a small text editor where I want to perform some programming experiments, and also to contribute to the library as a user. I'm glad the cpp-terminal exists, it's easy to "paint" things in a multiplatform way, and I have some stuff already running in Windows, Linux and RPI3. So thanks to all contributors!

My question is, and sorry if this is not the correct place to ask it, what's the supposed behavior of the library related to flickering? I'm using the Window class in order to render the final string, which I print with std::cout and std::flush. I draw the whole terminal, by the way. That is, I get terminal size at the beginning and use it to configure the Window instance.

I'm updating the library frequently (I mean, pulling it from its repository), and yesterday it was flickering like crazy, specially in Windows. Some minutes ago I updated the library again and now it seems it has no flickering at all.

So, I understand that it should not flicker if I use the Window class as I mentioned. Is this correct?

Thanks in advance.

@flagarde
Copy link
Collaborator

flagarde commented Apr 13, 2023

@iganinja Hello, thanks for your nice words. Some changes has been done related to resizing and maybe this create new issues. Would you mind give some codes to test ? What do you call flickering, something like redrawing (sorry my english is not so good)?

Does this happen when you change the size of your terminal? have you tried to use the new way provided by #234 (in https://github.com/jupyter-xeus/cpp-terminal/blob/master/examples/menu.cpp). The API has changed quite a lot and it is still not fixed; pulling gives you the new features but would need to change your code too, that's why there is not official new version. I'm just proposing some change and @MCWertGaming is the maintainer of the package

@iganinja
Copy link
Author

Hi @flagarde, thanks for your answer.

I have this currently:

image

(Yeah, colors are horrible, but they will be configurable 😂 )

I'm waiting to input with Term::Platform::read_raw(), then update things accordingly, create the string with Window::render() and show it with std::cout + std::flush . Wait 100ms and start again.

With flickering I mean that whole screen was blinking, some frames were drawn black, or the screen filling was noticeable. That was happening until I pulled cpp-terminal code from master yesterday, now it does not blink at all, even if I don't do the 100ms waiting. So I guess the problem is solved, but my question was that cpp-terminal being used the way I use it, should not blink/flicker at all, shouldn't it?

When I change the size of the terminal strange artifacts occur and also some blinking, but this doesn't bother me, it's normal even in graphical applications. After I stop resizing everything works perfectly. I didn't try the new way provided in the link you mention, I use the Window class for the moment.

@flagarde
Copy link
Collaborator

flagarde commented Apr 13, 2023

@iganinja I know they were some bug before the last merge in windows. Please note that key can be NO_KEY so you should add a test case for this. The reason is that read_raw return Event that can be other things than Key. But it is allowed to cast Event to Key and in the case the event is not a key, the key is then NO_KEY.

I recommend you to use the same trick than in menu.cpp in the example. Maybe you don't have to do the wait by yourself. You could use read_event that return only when it received event (key, change screen size ...). read_raw is more an internal function

@flagarde
Copy link
Collaborator

@iganinja This is fixed ?

@iganinja
Copy link
Author

Hi!
I tested it with my program in Windows: it flickers a little bit in a line. In Linux it seems rock solid, no flickering at all.

@flagarde
Copy link
Collaborator

flagarde commented May 26, 2023

@iganinja thx for the feedback. We can let this open then.. Not sure if it's a problem from the library of from Window$. Maybe there is some hack we could use I remember some discussion about this.

Are you using cout or Term::terminal<< ?

@iganinja
Copy link
Author

std::cout. Perhaps I have somewhat older version? I didn't touch it in weeks.

@certik
Copy link
Collaborator

certik commented May 28, 2023

@iganinja nice Turbo Pascal style menus. :) It would be nice to have them as widgets in cpp-terminal eventually.

@TobiasWallner
Copy link
Contributor

I noticed flickering too in my application as you described on Windows but not on Linux. I figured it was probably an issue with the frame rate of the console or when the console triggers a new redraw of the screen. I guessed that the Windows console maybe has a higher frame rate so it is more likely to trigger a redraw just after the ClearScreen command. So I got rid of ClearScreen and rewrote the rendering of my screen elements so that they do not need a clear screen before printing.

Maybe that helps

@flagarde
Copy link
Collaborator

flagarde commented Jul 3, 2023

I wonder if it's not the contrary the console in windows is poorly optimized. Are you using Term::terminal or cout. I heard somewhere cout is not buffered or things like this in windows or a very small buffer

@TobiasWallner
Copy link
Contributor

TobiasWallner commented Jul 4, 2023

I notized it with both. but part of my change from not using ClearScreen anymore also involves of just rendering and printing the few characters that actually change instead of re-rendering and drawing the whole screen. So maybe because my newer solution needs less memory or buffer space as you suggest fixed it.

@flagarde
Copy link
Collaborator

flagarde commented Jul 4, 2023

@TobiasWallner Your solution is general or a bit hacky? If it's a general one I think this could be incorporated into this library as it would be a very nice addition 😀

@TobiasWallner
Copy link
Contributor

it is general to my application but probably specific in terms of your library.

It is only applies to the design elemts of my projet like grids, labels, editable text fields, comman lines and the like.

The idea is that each element has functions that change something, like inserting a character or moveing the cursor. They will do that + give you a render of the changes which is just a move to the one character and the new value.

@flagarde
Copy link
Collaborator

flagarde commented Jul 4, 2023

I see, so it seems the problem is the clearscreen ?

@TobiasWallner
Copy link
Contributor

yes I think so

@flagarde
Copy link
Collaborator

flagarde commented Jul 7, 2023

@TobiasWallner I'm trying to implement a more system base API to wrtite to console. I have been told the C C++ Windows is quite buggy and not so efficient sometimes. I already did a first step with file.hpp but need to improve it. Maybe this will improve performance. I have seen an other way to improve performance I will do a PR for this

I didn't benchmark as i'm doind on virtualbox so the results it's maybe not what one should expect but I can see it by eyes so lets implement and check on other system

@TobiasWallner
Copy link
Contributor

I could run a benchmark natively if you want me too.

@flagarde
Copy link
Collaborator

flagarde commented Jul 8, 2023

@TobiasWallner Would be great or to have a program with benching on this repo :)

@TobiasWallner
Copy link
Contributor

TobiasWallner commented Jul 22, 2023

Your solution is general or a bit hacky? If it's a general one I think this could be incorporated into this library as it would be a very nice addition

I was wondering, you do have a class that stores one frame, the window class, right?
Could we calculate the difference of of two windows? - which is then a map of all things that changed? and then just print that to reduce the ammount of data that gets printed every time?

could look like this:

newFrame = render();
diff = newFrame - prevFrame;
Term::cout << diff;
prevFrame = newFrame;

@certik
Copy link
Collaborator

certik commented Jul 22, 2023

We already do the diff, although the diff is quite "primitive":

std::string Term::Window::render(const std::size_t& x0, const std::size_t& y0, bool term)
, we need to minimize the change needed to output, so that it flickers less.

However, the demos that we have don't seem to flicker for me.

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

4 participants