Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
RokuMarkn
Level 7

Re: Command line Editing in Console?

EnTerr, I would note that the library you recommended (linenoise) uses ANSI escape sequences to clear the line, move the cursor, etc. This will not work on all terminals. It will almost certainly not work on any Windows telnet client, and may not work on other systems as well. I think terminal handling is probably the hardest part of producing a portable solution to this problem. Having spent over 30 years maintaining an open-source program that uses termcap/terminfo, I can say that it is not a trivial problem to make this work everywhere.

--Mark
0 Kudos
EnTerr
Level 9

Re: Command line Editing in Console?

"RokuMarkn" wrote:
EnTerr, I would note that the library you recommended (linenoise) uses ANSI escape sequences to clear the line, move the cursor, etc. This will not work on all terminals. It will almost certainly not work on any Windows telnet client, and may not work on other systems as well.

Wait... why do you say ANSI won't work "on any Windows telnet client"? I am confused.

VT100 and ANSI are things that have been supported like forever, i mean i remember since before Windows 95... like what was it, was it Windows 3.1, which had no tcp/ip stack so we had to run something called Trumpet WinSock as application on top of it and use it to modem dial into X.25, then into CompuServe and then into the Internet... oh, the memories of FidoNet, NCSA Mosaic and 20 000 ms pings! Since about that time i remember VT100 and ANSI have been reliable choices to use on Windows.

Once upon a time i was MCSE (microsoft certified something-something.. six exams) but my WIndows has been dusty last few years, so i'll defer to somebody fresher, say... @belltown? Any reasons to believe telnet in new Windowses has issue with ANSI/VT100?

I think terminal handling is probably the hardest part of producing a portable solution to this problem. Having spent over 30 years maintaining an open-source program that uses termcap/terminfo, I can say that it is not a trivial problem to make this work everywhere.

If said program was say a text editor or pager, more-or-less - striving to work on every *nix variety there is and with every crazy terminal - then i cannot even begin to fathom the difficulties. But that's not what we have here - all that we need for the debug console is to support telnet from 2 to 3 platforms - in order of importance that's Windows, OSX (and Linux). Which can be done as simple as speaking one thing - ANSI/VT100. Which Windows and OSX telnets already do. And so it happens, linenoise also speaks the same lowest common denominator...
0 Kudos
RokuMarkn
Level 7

Re: Command line Editing in Console?

As far as I'm aware, Windows cmd windows do not support ANSI escape sequences. In fact there is no sequence of characters that you can send to a cmd window that makes it do cursor movement, line clearing, etc. The running program has to call API functions to do those things. However there may be third-party terminal emulators that run on Windows that do support ANSI. Theoretically even on Linux one could be using a terminal emulator that doesn't support ANSI; at one time there were hundreds of incompatible physical terminals and emulators. I agree that today its rare to find one that doesn't support ANSI/VT100, but the point is that the issue is the emulator, not the OS. Two people could be running the same version of Linux but have different ANSI support because of the terminals they're using. Even two terminals that ostensibly both support ANSI may differ in subtle ways such as how they handle line wrap which might mess things up (there are at least 3 different ways for a terminal to do line wrapping and it's a headache to make it work correctly for all terminals).

--Mark
0 Kudos
belltown
Level 7

Re: Command line Editing in Console?

"RokuMarkn" wrote:
EnTerr, I would note that the library you recommended (linenoise) uses ANSI escape sequences to clear the line, move the cursor, etc. This will not work on all terminals. It will almost certainly not work on any Windows telnet client.

The Windows Telnet client uses ANSI terminal mode by default. (It also has options to use VT100, VT52, or Microsoft's VTNT).

It looks like there's some confusion here between the Windows cmd shell and the Windows Telnet Client. The Windows command shell, cmd.exe (actually the Console Host, ConHost.exe, which supports both cmd.exe and Powershell), does not support ANSI escape sequences (although Microsoft is adding support for them in Windows 10 to bring them forward into the 20th century). However, the Windows Telnet Client, a console program that runs under cmd and Powershell, etc, does support ANSI escape characters. It was designed that way specifically to allow Windows computers to communicate with other non-Windows systems, many of which have been using ANSI or VT100 terminal emulation since the dark ages.

I don't know exactly which subset of the ANSI escape sequences are supported by Windows Telnet, but I do know that the few used by linenoise are supported. I've been able to type ANSI sequences into Telnet and see them take effect. The one I've used the most is ESC [ 2 J (clear screen). Before PurpleBug, I even went as far as to include a little subroutine in my code to have the Roku send the sequence, so I just had to type cls() at the debugger prompt to clear the screen:


'
' Clear screen - use while stopped within the Roku Debugger
'
Sub cls ()
' Send the ANSI clear screen escape sequence: ESC [ 2 J
Print Chr(&h1B); "[2J"
End Sub

Notwithstanding the above, I have no idea how trivial or non-trivial it would be to implement something like linenoise in the Roku Debugger, since I don't have access to the Roku Debugger code, obviously. I'll leave that to the experts to determine. And I'm only speaking from a Windows perspective here. And I can't speak as to the various incompatibility issues that may be present with different terminal clients on different versions of different OS's.

P.S. If you want to have some fun with ANSI escape sequences on the Roku, go to http://artscene.textfiles.com/vt100/. Download any of the listed files into your package directory (my favorite is http://artscene.textfiles.com/vt100/trekvid.vt), then run the following code:

Sub Main ()
vt = ReadAsciiFile ("pkg:/ansi/trekvid.vt")
Stop
Print vt
Stop
End Sub

In Telnet, when you get to the first breakpoint, type "s", and watch a politically-incorrect Star Trek vessel flying through space firing its phasers and displaying naughty sayings.
https://github.com/belltown/
0 Kudos
RokuMarkn
Level 7

Re: Command line Editing in Console?

Ah, ok, I knew cmd didn't support ANSI but I didn't realize that telnet did. It seems insane to require the ANSI logic to be in every program that uses it rather than having it in the terminal.

--Mark
0 Kudos
belltown
Level 7

Re: Command line Editing in Console?

"RokuMarkn" wrote:
Ah, ok, I knew cmd didn't support ANSI but I didn't realize that telnet did. It seems insane to require the ANSI logic to be in every program that uses it rather than having it in the terminal.

--Mark

Insane? Microsoft? Never! Microsoft deletes 'teen girl' AI after it became a Hitler-loving sex robot within 24 hours
https://github.com/belltown/
0 Kudos
EnTerr
Level 9

Re: Command line Editing in Console?

"belltown" wrote:
Insane? Microsoft? Never! Microsoft deletes 'teen girl' AI after it became a Hitler-loving sex robot within 24 hours

Hmm, that's some harsh language from somebody whose name is Belltown, ain't it? :twisted:
On a side note - hey you linux-heads, did you hear there be a "real" bash for Windows now (an Ubuntu subsystem, not Cygwin or VM)?
0 Kudos
quartern
Level 7

Re: Command line Editing in Console?

Typically one looks to the target to implement the history ...
if you are an old emacs user, you can use the shell feature to initiate a telnet session. Then just navigate up to last command, edit or re-execute it
not quite history but if eclipse is too much this might do

(emacs shell mode was better for me than emacs telnet mode - may be able to even define the prompt pattern in telnet config for it to be better)
Private apps: IsraTV (replaces IsraIBA, IsraNews2, IsraI24, Isra10, Isra20)
Users - to report issues with the app (not content of streams please) send me a tweet - @quartern_roku and follow (so we can DM)
0 Kudos
belltown
Level 7

Re: Command line Editing in Console?

FYI - the latest PurpleBug release (1.0.0.10) has a few minor changes including a right-click menu in the main section of each connection tab, useful for floating tabs, which don't have their own top menu bar. You can use the menu to re-connect a failed connection, or access other functions such as: close tab, un-float tab, auto scroll, auto wrap, etc. See Help->View Release Notes.
https://github.com/belltown/
0 Kudos
Komag
Level 9

Re: Command line Editing in Console?

A great tool keeps getting better! Smiley Very Happy 8-)
0 Kudos