Connect via WebSocket

140 views
Skip to first unread message

fel...@felipegasper.com

unread,
Sep 10, 2017, 9:20:58 AM9/10/17
to chromium-hterm
Hello,

I’m trying out hterm after having used xterm.js for a while. hterm seems not to parse the input from my server-side shell very well; does this pattern look familiar to anyone?

It’s the same terminal server that serves up xterm.js reliably.

Thank you!



Here is the code:

Enter code here...hterm.defaultStorage = new lib.Storage.Memory();

var t = new hterm.Terminal();

var text_decoder = new TextDecoder();
var ws = new WebSocket("ws://localhost:32000");
ws
.binaryType = "arraybuffer";
ws
.onmessage = function(evt) {
    t
.print( text_decoder.decode(evt.data) );
};

t
.onTerminalReady = function() {
 
var io = t.io.push();

  io
.onVTKeystroke = function(str) {
    ws
.send(str);
 
};

  io
.sendString = function(str) {
    ws
.send(str);
 
};
};

t
.decorate(document.querySelector('#terminal'));

t
.io.println('Print a string and add CRLF');

t
.installKeyboard();


Auto Generated Inline Image 1

Mike Frysinger

unread,
Sep 10, 2017, 12:08:23 PM9/10/17
to fel...@felipegasper.com, chromium-hterm
pretty sure you want to use t.interpret instead of t.print in ws.onmessage
-mike



--
You received this message because you are subscribed to the Google Groups "chromium-hterm" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-hterm/b2f1300d-26c2-422a-9ea9-e64b92321425%40chromium.org.

Felipe Gasper

unread,
Sep 10, 2017, 12:12:47 PM9/10/17
to Mike Frysinger, chromium-hterm
Got it -- thanks! :)

-F

> On Sep 10, 2017, at 12:07 PM, Mike Frysinger <vap...@chromium.org> wrote:
>
> pretty sure you want to use t.interpret instead of t.print in ws.onmessage
> -mike
>
> On Sun, Sep 10, 2017 at 9:20 AM, <fel...@felipegasper.com> wrote:
> Hello,
>
> I’m trying out hterm after having used xterm.js for a while. hterm seems not to parse the input from my server-side shell very well; does this pattern look familiar to anyone?
>
> It’s the same terminal server that serves up xterm.js reliably.
>
> Thank you!
>
> <Auto.png>

Felipe Gasper

unread,
Sep 10, 2017, 12:15:18 PM9/10/17
to Mike Frysinger, chromium-hterm
Is that documented anywhere, btw?

-F

> On Sep 10, 2017, at 12:07 PM, Mike Frysinger <vap...@chromium.org> wrote:
>
> pretty sure you want to use t.interpret instead of t.print in ws.onmessage
> -mike
>
> On Sun, Sep 10, 2017 at 9:20 AM, <fel...@felipegasper.com> wrote:
> Hello,
>
> I’m trying out hterm after having used xterm.js for a while. hterm seems not to parse the input from my server-side shell very well; does this pattern look familiar to anyone?
>
> It’s the same terminal server that serves up xterm.js reliably.
>
> Thank you!
>
> <Auto.png>
>
> Here is the code:
>
> Enter code here...hterm.defaultStorage = new lib.Storage.Memory();
>
> var t = new hterm.Terminal();
>
> var text_decoder = new TextDecoder();
> var ws = new WebSocket("ws://localhost:32000");
> ws.binaryType = "arraybuffer";
> ws.onmessage = function(evt) {
> t.print( text_decoder.decode(evt.data) );
> };
>
> t.onTerminalReady = function() {
> var io = t.io.push();
>
> io.onVTKeystroke = function(str) {
> ws.send(str);
> };
>
> io.sendString = function(str) {
> ws.send(str);
> };
> };
>
> t.decorate(document.querySelector('#terminal'));
>
> t.io.println('Print a string and add CRLF');
>
> t.installKeyboard();
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "chromium-hterm" group.
> To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-hterm/b2f1300d-26c2-422a-9ea9-e64b92321425%40chromium.org.
>
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "chromium-hterm" group.
> To unsubscribe from this topic, visit https://groups.google.com/a/chromium.org/d/topic/chromium-hterm/Na2sJBDVJ_E/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to chromium-hter...@chromium.org.
> To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-hterm/CAAbOScnuTwqtWjMavenL90q7HAi%3DtniLPND0QS%3Df1ezJHGpF3A%40mail.gmail.com.

Mike Frysinger

unread,
Sep 10, 2017, 12:18:35 PM9/10/17
to Felipe Gasper, chromium-hterm
yes & no.  we don't currently have API docs other than JSDoc.  i can improve our embedding doc though to mention .interpret vs .print.
-mike

> To unsubscribe from this group and all its topics, send an email to chromium-hterm+unsubscribe@chromium.org.

Mike Frysinger

unread,
Sep 10, 2017, 12:47:44 PM9/10/17
to Felipe Gasper, chromium-hterm
actually double checking docs, don't be confused by t.print and t.io.print.  the latter is probably what you want to be using and takes care of going through interpret.  if you're hitting the terminal directly, you need to differentiate between .print and .interpret (and making sure you're sending UTF8 encoded content).
-mike

Felipe Gasper

unread,
Sep 10, 2017, 1:50:51 PM9/10/17
to Mike Frysinger, chromium-hterm
Does hterm not grok binary, then? I’m implementing ZMODEM in JavaScript.

-F

> On Sep 10, 2017, at 12:47 PM, Mike Frysinger <vap...@chromium.org> wrote:
>
> actually double checking docs, don't be confused by t.print and t.io.print. the latter is probably what you want to be using and takes care of going through interpret. if you're hitting the terminal directly, you need to differentiate between .print and .interpret (and making sure you're sending UTF8 encoded content).
> -mike
>
> On Sun, Sep 10, 2017 at 12:07 PM, Mike Frysinger <vap...@chromium.org> wrote:
> pretty sure you want to use t.interpret instead of t.print in ws.onmessage
> -mike
>
> On Sun, Sep 10, 2017 at 9:20 AM, <fel...@felipegasper.com> wrote:
> Hello,
>
> I’m trying out hterm after having used xterm.js for a while. hterm seems not to parse the input from my server-side shell very well; does this pattern look familiar to anyone?
>
> It’s the same terminal server that serves up xterm.js reliably.
>
> Thank you!
>
> <Auto.png>
>
> Here is the code:
>
> Enter code here...hterm.defaultStorage = new lib.Storage.Memory();
>
> var t = new hterm.Terminal();
>
> var text_decoder = new TextDecoder();
> var ws = new WebSocket("ws://localhost:32000");
> ws.binaryType = "arraybuffer";
> ws.onmessage = function(evt) {
> t.print( text_decoder.decode(evt.data) );
> };
>
> t.onTerminalReady = function() {
> var io = t.io.push();
>
> io.onVTKeystroke = function(str) {
> ws.send(str);
> };
>
> io.sendString = function(str) {
> ws.send(str);
> };
> };
>
> t.decorate(document.querySelector('#terminal'));
>
> t.io.println('Print a string and add CRLF');
>
> t.installKeyboard();
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "chromium-hterm" group.
> To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-hterm/b2f1300d-26c2-422a-9ea9-e64b92321425%40chromium.org.
>
>
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "chromium-hterm" group.
> To unsubscribe from this group and all its topics, send an email to chromium-hter...@chromium.org.
> To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-hterm/CAAbOSckjGpi%2BTh8wTfTGCj_yZ5%3Dyk6JMzzMRHvW1E_rU2cs4Xg%40mail.gmail.com.

Mike Frysinger

unread,
Sep 10, 2017, 2:18:11 PM9/10/17
to Felipe Gasper, chromium-hterm
that question doesn't exactly make sense.  if you're handling the zmodem traffic, why would hterm be processing the output ?  your zmodem module would be capturing it all.

hterm itself expects content to be UTF-8 encoded because humans are reading it.  when the VT layers see ASCII, it'll interpret it as a normal terminal emulator will.  but not all binary data streams are valid UTF-8.  if you do send invalid UTF-8 content, hterm won't throw exceptions, just ignore bytes or not process it as you might expect.

are you writing the zmodem parser from scratch ?  last time i looked, there weren't really any off the shelf zmodem JS libraries.
-mike

> To unsubscribe from this group and all its topics, send an email to chromium-hterm+unsubscribe@chromium.org.

Felipe Gasper

unread,
Sep 10, 2017, 2:54:57 PM9/10/17
to chromiu...@chromium.org, Mike Frysinger, chromium-hterm
Ah, yes. Sorry, wasn't thinking.

Yes, I wrote a ZMODEM implementation in JS. As far as I know it's the only one out there.

https://github.com/FGasper/zmodemjs

I'm still polishing, but you can have a look.

-FG
>> chromium-hter...@chromium.org.
>> > To view this discussion on the web visit
>https://groups.google.com/a/
>> chromium.org/d/msgid/chromium-hterm/CAAbOSckjGpi%2BTh8wTfTGCj_yZ5%
>> 3Dyk6JMzzMRHvW1E_rU2cs4Xg%40mail.gmail.com.
>>
>>

--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Mike Frysinger

unread,
Sep 11, 2017, 7:26:50 AM9/11/17
to Felipe Gasper, chromium-hterm
zmodem is something i'd like to integrate into hterm at some point ;)
-mike


>> > To view this discussion on the web visit
>https://groups.google.com/a/
>> chromium.org/d/msgid/chromium-hterm/CAAbOSckjGpi%2BTh8wTfTGCj_yZ5%
>> 3Dyk6JMzzMRHvW1E_rU2cs4Xg%40mail.gmail.com.
>>
>>

Reply all
Reply to author
Forward
0 new messages