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

Efficient way to erase characters in a specific area? #51

Closed
laurent22 opened this issue Oct 1, 2017 · 4 comments
Closed

Efficient way to erase characters in a specific area? #51

laurent22 opened this issue Oct 1, 2017 · 4 comments

Comments

@laurent22
Copy link
Contributor

laurent22 commented Oct 1, 2017

I'm not sure if this already part of the API and I missed it, but is there any way to erase a specific part of the terminal without moving around other characters?

eg. for example I have this:

0123
5678
9012

And want to have this (erase the two characters in the middle):

0123
5  8
9012

I found a way by doing this:

term.moveTo(2,2);
term.delete(2);
term.insert(2);

But that seems a bit inefficient. Is there a better way?

@cronvel
Copy link
Owner

cronvel commented Oct 1, 2017

@laurent22 Not really, except if you want to erase from your actual cursor to the end of line (eraseLineAfter()).

More efficient: term.moveTo( 2 , 2 , ' ' ) ; or term.moveTo( 2 , 2 , ' '.repeat( 2 ) ) ;

Also it could be interesting to have a higher-level function for erasing region, but it would definitively do something similar behind the scene.

What is your use-case? You may want to use the ScreenBuffer.

@laurent22
Copy link
Contributor Author

Great, thanks I missed that it was possible to do moveTo(x, y, chars).

A function like erase(x, y, width, height) would be quite convienent. I can provide a pull request if you're interested?

Also another question, the insert(x) function actually inserts space characters, is that right? Or does it take the character it's inserting from somewhere else? (It wasn't clear from the documentation)

Yes I had a look at ScreenBuffer but since what I want to do is quite custom (multiple scrollable lists and a text input below), I thought I'd try first with something lower level to have more flexibility. It's possible I'm reinventing the wheel though!

cronvel added a commit that referenced this issue Oct 2, 2017
@cronvel
Copy link
Owner

cronvel commented Oct 2, 2017

@laurent22 Hi, as you can see, I have added the .eraseArea( x , y , [width] , [height] ) method that does exactly what you want.

For the .insert() method, it directly maps to a terminal capability. So I cannot tell you if it actually adds space characters, or if a terminal has an internal empty cell state. However since empty areas act as spaces when we copy/paste them, that's not really important.

@laurent22
Copy link
Contributor Author

Brilliant, thanks a lot for the eraseArea function!

@cronvel cronvel closed this as completed Nov 11, 2017
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

2 participants