-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add Terminado example
#303
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
Conversation
|
In general the content of this PR is quite nice and interesting, but I believe it is out of scope in specific parts. While a terminado add-on would be useful, I do not think that a terminado demo should be inside this repository. My proposal
I think this is the best idea, in order to preserve the scope and purpose of this repository, while helping people that want to use xterm.js with Terminado. |
|
👍 to moving the demo to a guide in http://xtermjs.org/docs/ 👎 to adding this as an addon, that means we need to maintain it until the end of time |
I don't think that is what that means. It just means that as long as it is useful, your users can actually find it. Feel free to deprecate it in the future if the state of the art moves on. |
|
@scopatz since addons hook into private APIs by design this limits the ability to evolve the code base, since addons are essentially part of the API (or at least will be when they're documented). The main point here is that it seems like very simple hook up code as well that could be covered pretty well with just a tutorial. |
|
I think it is OK to break addons as needed, and then people can submit patches to fix them. They are explicitly not part of the core. Folks can always roll back to last working version, if needed. My point is that without an addon, the user is forced to do this work. I am not a hugely experienced web or JS dev, and it was complex enough that after about 8 hours trying to get xtermjs work over the past couple of days, I gave up. I would really appreciate anything that makes the user experience less painful. |
|
I was looking at the code on my phone and I think I missed some, after another look I know what you mean. It doesn't actually touch any private APIs which is the main thing I was concerned about. So 👍 for the addon. |
| */ | ||
| exports.attach = function (term, socket, bidirectional, buffered) { | ||
| bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional; | ||
| term.socket = socket; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parisk related to my comments on the PR, we should come up with some namespacing convention to prevent variable collisions with other addons. Something like:
// _ prefix for private, followed by addon name
term._terminado = {};
term._terminado.socket = socket;
term._terminado._flushBuffer = function () {
...
// addon name prefix
Xterm.prototype.terminadoAttach = ...|
Great, if you think it's better to have it as a separate addon, I can definitely do that. In the same spirit as the |
parisk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM in general. Requesting tiny naming changes.
I need to make some functional tests though as well.
addons/terminado/terminado.js
Outdated
| * should happen instantly or at a maximum | ||
| * frequency of 1 rendering per 10ms. | ||
| */ | ||
| Xterm.prototype.attach = function (socket, bidirectional, buffered) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please rename this to terminadoAttach or something similar, in order to avoid clashes with the attach addon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addons/terminado/terminado.js
Outdated
| * @param {WebSocket} socket - The socket from which to detach the current | ||
| * terminal. | ||
| */ | ||
| Xterm.prototype.detach = function (socket) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please rename this to terminadoDetach or something similar, in order to avoid clashes with the attach addon?
|
Do you plan to open a PR at https://github.com/xtermjs/xtermjs.org with a more complete documentation about how to connect to a terminado back-end? |
Yes |
|
Moving on with some functional tests. |
|
@staticfloat do you have any ready example that I can use to test this out? |
|
Documentation here: xtermjs/xtermjs.org#4 EDIT: @parisk you can use the documentation to create a minimal example. Note that the |
parisk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting a few changes, as the demo in the documentation raised some errors.
addons/terminado/terminado.js
Outdated
| } | ||
| term.on('resize', term._setSize); | ||
|
|
||
| socket.addEventListener('close', term.detach.bind(term, socket)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to term.terminadoDetach please.
addons/terminado/terminado.js
Outdated
| term.on('resize', term._setSize); | ||
|
|
||
| socket.addEventListener('close', term.detach.bind(term, socket)); | ||
| socket.addEventListener('error', term.detach.bind(term, socket)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to term.terminadoDetach please.
addons/terminado/terminado.js
Outdated
| * should happen instantly or at a maximum | ||
| * frequency of 1 rendering per 10ms. | ||
| */ | ||
| exports.attach = function (term, socket, bidirectional, buffered) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe renaming exported functions to terminadoAttach and terminadoDetach as well would be a better option, to reduce confusion.
|
Done, and tested, this time with the console open to make sure there are no errors. |
|
👍 to having something like this to make things easy for people coming from the Python world. I'd like to add a link from the Terminado docs once this and the associated doc PR are done. |
|
For that matter, if it makes life easier, we could add an option to terminado to send/receive data in the format supported by the existing |
|
Everything seems to be working great. Thanks for implementing this! @takluyver let's keep the scope of this PR to where it is right now and add extra functionality down the road in an as-needed base. |
|
Thanks! PRs welcome to add a link to terminado docs, or I'll get round to it sooner or later. |
|
@staticfloat just letting you know that we mentioned you for this contribution in the 2.1 announcement. Thank you! |
This adds a (not-quite barebones) example of how to use
Xterm.jswithTerminado. Note thatterminado_attach.jsis extremely similar toattach.js, perhaps there's some way we can provide arguments toattach.jsso that the file is completely unnecessary. I'm very much not a Javascript coder, as you can probably tell by my hacked-upindex.htmlthat begs, borrows and steals from things likefit.jsto hopefully cut down on the amount of code needed to get you up and running on Python.If you think this can be made simpler, (I definitely think it can) then feel free to just close this PR and remake your own based upon this, I just thought this might be useful for those that want to use a Python backend instead of a node.js one.