Skip to content

Conversation

@staticfloat
Copy link
Contributor

This adds a (not-quite barebones) example of how to use Xterm.js with Terminado. Note that terminado_attach.js is extremely similar to attach.js, perhaps there's some way we can provide arguments to attach.js so that the file is completely unnecessary. I'm very much not a Javascript coder, as you can probably tell by my hacked-up index.html that begs, borrows and steals from things like fit.js to 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.

@staticfloat staticfloat mentioned this pull request Oct 5, 2016
@parisk
Copy link
Contributor

parisk commented Oct 5, 2016

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.

@Tyriar
Copy link
Member

Tyriar commented Oct 5, 2016

👍 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

@scopatz
Copy link

scopatz commented Oct 5, 2016

👎 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.

@Tyriar
Copy link
Member

Tyriar commented Oct 5, 2016

@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.

@scopatz
Copy link

scopatz commented Oct 5, 2016

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.

@Tyriar
Copy link
Member

Tyriar commented Oct 5, 2016

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;
Copy link
Member

@Tyriar Tyriar Oct 5, 2016

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 = ...

@staticfloat
Copy link
Contributor Author

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 attach plugin, should I include a demo index.html page?

Copy link
Contributor

@parisk parisk left a 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.

* should happen instantly or at a maximum
* frequency of 1 rendering per 10ms.
*/
Xterm.prototype.attach = function (socket, bidirectional, buffered) {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I rename Xterm.prototype.attach to Xterm.prototype.terminadoAttach, will I need to change the attach names on lines 9, 14, 19 and 24?

* @param {WebSocket} socket - The socket from which to detach the current
* terminal.
*/
Xterm.prototype.detach = function (socket) {
Copy link
Contributor

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?

@parisk
Copy link
Contributor

parisk commented Oct 8, 2016

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?

@staticfloat
Copy link
Contributor Author

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

@parisk
Copy link
Contributor

parisk commented Oct 8, 2016

Moving on with some functional tests.

@parisk
Copy link
Contributor

parisk commented Oct 8, 2016

@staticfloat do you have any ready example that I can use to test this out?

@staticfloat
Copy link
Contributor Author

staticfloat commented Oct 8, 2016

Documentation here: xtermjs/xtermjs.org#4

EDIT: @parisk you can use the documentation to create a minimal example. Note that the SingleTermManager created by Terminado will not restart itself after you kill a terminal it's spawned, so if you exit out of the bash subprocess created by Terminado, you'll need to restart the twisted server to get a new shell.

Copy link
Contributor

@parisk parisk left a 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.

}
term.on('resize', term._setSize);

socket.addEventListener('close', term.detach.bind(term, socket));
Copy link
Contributor

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.

term.on('resize', term._setSize);

socket.addEventListener('close', term.detach.bind(term, socket));
socket.addEventListener('error', term.detach.bind(term, socket));
Copy link
Contributor

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.

* should happen instantly or at a maximum
* frequency of 1 rendering per 10ms.
*/
exports.attach = function (term, socket, bidirectional, buffered) {
Copy link
Contributor

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.

@staticfloat
Copy link
Contributor Author

Done, and tested, this time with the console open to make sure there are no errors.

@takluyver
Copy link

👍 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.

@takluyver
Copy link

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 attach addon. Looking over that code, though, I don't think it can tell the server when the terminal has been resized, so I still like the option to have a slightly richer protocol.

@parisk
Copy link
Contributor

parisk commented Oct 17, 2016

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.

@parisk parisk merged commit b1c6ae8 into xtermjs:master Oct 17, 2016
@takluyver
Copy link

Thanks!

PRs welcome to add a link to terminado docs, or I'll get round to it sooner or later.

@parisk
Copy link
Contributor

parisk commented Nov 11, 2016

@staticfloat just letting you know that we mentioned you for this contribution in the 2.1 announcement. Thank you!

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

Successfully merging this pull request may close these issues.

5 participants