-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Feature request: export React component #260
Comments
This is really a really interesting scenario. We try to keep xterm.js as self-contained and lightweight as possible, since it has already enough of functionality and complexity in it. I think though that creating an xtermjs/xterm-react repository and an xterm-react npm module hat would just wrap xterm.js in a React component could do the job. How does that sound? |
That would be great :) |
I would really like to work on that but I found a few issues with adjusting the code without making it too patchy. The problem is that xtem.js relays heavily on interactions with the DOM, so separating the view logic is extremely difficult. I'd like to make a feature request to separate the logic and DOM handling in a way that will allow different components to take over rendering. I suggest something in the lines of extracting Terminal.UI from Terminal, which would be responsible for attaching events to the DOM, creating and updating elements, etc. Terminal would wait for Terminal.UI to trigger events, such as keypress and scroll, that way it would be decoupled from rendering completely. I think you started going in that direction with the Viewport, but I believe a full separation is in order. I'd like to hear your thoughts on this, and I'd like to help with it in case you think it's relevant. I believe that for the complexity of code in this project, some separation of concerns could really help in future development and maintenance, and I'm a big fan of the single responsibility principle 😄 |
Not everything in this list is difficult to work with, for example if I don't use the Anything in Viewport and CompositionHelper, but that's obvious :) From the xterm.js file these are the main methods which should be separated: 'bell' and 'application-mode' should trigger events instead of interacting with UI logic. I believe this is most of it, but we do need to watch out for uses of UI element in the code (e.g. this.viewport and this.element should never be used directly by the core module. Hope this help. P.S. Hope this helps |
It might be good to look into #266 before trying to tackle this |
If we separate between the core logic and the UI logic, the core can be initialized without worrying about the dom and only when needed the view can be initialized, passing it a terminal core instance to work with. |
I'm trying a test the mouse events to see that I didn't break anything, and I can't find a terminal application with full mouse support with includes mouse move, for example. What are you guys are testing this library against to verify that mouse events are working properly? |
I actually created an npm package for a react-xterm component. |
Thanks @farfromrefug! It would be great if we didn't start with "tabula rasa". |
This is something that would be better done by the community imo, I'm closing off to reduce our issue count but I encourage someone to put this together. |
Hope you don't mind me commenting on a closed issue but I've been working on a custom React renderer to work with xtermjs. It provides a number of elements (such as (still very much a WIP but it works as a proof of concept at the moment) |
@alex-saunders thanks for calling it out, good to have a link in this issue in case people are looking 👌 |
Hi. I was able to set up a react component with almost no code and using the "new" hooks system. However, it is rather tightly coupled with node-pty for usage in electron scenarios. I can't share any code right now, as it's an closed, internal project, but I encourage everyone to take a new shot at the problem using a hook-based solution - it's worth it! |
Would be really useful if xterm.js would export a React component for easily embedding in React apps. It could just be a simple wrapper around the existing code.
The text was updated successfully, but these errors were encountered: