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

Theme is lost when running .open() multiple times #1323

Closed
LucianBuzzo opened this issue Mar 11, 2018 · 8 comments
Closed

Theme is lost when running .open() multiple times #1323

LucianBuzzo opened this issue Mar 11, 2018 · 8 comments
Labels
good first issue help wanted type/enhancement Features or improvements to existing features

Comments

@LucianBuzzo
Copy link
Contributor

If you call .open() a second time, the terminal will lose its theme. This is due to the theme option being set to null here https://github.com/xtermjs/xterm.js/blob/3.2.0/src/Terminal.ts#L700
You can get around this by setting the theme option again, but its not very intuitive.

Details

  • Browser and browser version: whatsmybrowser.org/b/YWN4JTB
  • OS version: OS X 10.13.3
  • xterm.js version: 3.2.0

Steps to reproduce

  1. Instantiate a new xterm instance and open it on a DOM element
  2. Remove the dom element
  3. Open the instance using a new DOM element
@Tyriar
Copy link
Member

Tyriar commented Mar 11, 2018

Hmm, I guess I put that there to prevent getOption('theme') working as it could be invalid. The real bug here is probably the fact that you are able to call open twice, @LucianBuzzo what's you use case for needing it twice?

@LucianBuzzo
Copy link
Contributor Author

@Tyriar I would consider calling .open() twice a feature! Its a valuable part of how I'm using xterm.

On https://dashboard.resin.io/ we use xterm.js 2.7.x for our webterminal. On the dashboard you are able to open a webterminal session, navigate away to another page (removing the DOM element) and then come back to the webterminal page (adding a new DOM element) and resume your session where you left off. This functionality still works using xterm 3.2.0, you just need to set the theme again after calling .open().

The ability to 'unattach' the xterm instance from the DOM and then 're-attach' it at a later date is a really powerful tool. I understand that it's not a common use case though.

@Tyriar
Copy link
Member

Tyriar commented Mar 22, 2018

@LucianBuzzo well VS Code and Hyper both do this so I think we should support it. I guess we'll just support fixing everything up when open is called a second time (as opposed to adding a close method which undoes open and disables a bunch of stuff as a result). We can also add a note to the open jsdoc indicating it can be called twice. Open to PRs.

@LucianBuzzo
Copy link
Contributor Author

@Tyriar So AFAIK the only thing that you need to do is set the theme option again. Can you expand a little bit on why the theme is set to null in the first place? Does it get modified somehow when its passed to the renderer?

@Tyriar
Copy link
Member

Tyriar commented Mar 22, 2018

@LucianBuzzo I did that because the theme option is passed onto ColorManager and then that is the source of truth. Colors can be invalidated which could lead to confusion (eg. setting a color to "redd" will use the default color as "redd" isn't valid).

This is what VS Code does atm, I haven't actually seen a problem with the theme because I only ever call open once and if I need to reattach I just pull it off the container and put it back onto another one.

https://github.com/Microsoft/vscode/blob/af21dc79255e351a45fd4ad00a92699acaaa130c/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts#L364-L368

Perhaps this should be the recommended way as it's fairly simple?

@Tyriar Tyriar added type/enhancement Features or improvements to existing features and removed type/feature labels Apr 4, 2018
@Tyriar
Copy link
Member

Tyriar commented Jan 11, 2019

Maybe we should also offer a close method, if open is called a second time without close being called, it can trigger close at the start of the function?

@leojh
Copy link

leojh commented Sep 20, 2019

This looks like it was fixed on issue #2174 commit: 322ae13 but now it's back in 4.0.1: https://github.com/xtermjs/xterm.js/blob/4.0.1/src/Terminal.ts line 608

@Tyriar
Copy link
Member

Tyriar commented Sep 23, 2019

This should get fixed in #2435

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue help wanted type/enhancement Features or improvements to existing features
Projects
None yet
Development

No branches or pull requests

3 participants