Skip to content

Commit

Permalink
Merge pull request #1335 from Dunbaratu/fixes_1328_esc_in_telnet
Browse files Browse the repository at this point in the history
Fixes #1328 esc in telnet
  • Loading branch information
erendrake committed Dec 31, 2015
2 parents 1682fdc + f4df765 commit 87ec1e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/kOS.Safe/Compilation/KS/KSScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public override bool IsCommandComplete(string command)

foreach (ParseError err in parseTree.Errors)
{
System.Console.WriteLine("eraseme: err msg: " + err.Message);
if (err.Message.StartsWith("Unexpected token 'EOF'"))
{
if (err.Message.Contains("Expected CURLYCLOSE") ||
Expand Down
26 changes: 16 additions & 10 deletions src/kOS/UserIO/TerminalVT100Mapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using kOS.Safe.UserIO;
using System.Collections.Generic;
using System.Text;
using System;

namespace kOS.UserIO
{
Expand Down Expand Up @@ -154,7 +155,8 @@ public override string InputConvert(char[] inChars)
switch (inChars[index])
{
case ESCAPE_CHARACTER:
if (inChars[index + 1] == '[') // ESC followed by '[' is called the CSI (Control Sequence Initiator) and it's how most VT100 codes start.
if (index + 1 < inChars.Length && inChars[index + 1] == '[')
// ESC followed by '[' is called the CSI (Control Sequence Initiator) and it's how most VT100 codes start.
{
int numConsumed;
char ch = ConvertVT100InputCSI(inChars, index + 2, out numConsumed);
Expand Down Expand Up @@ -194,16 +196,20 @@ public override string InputConvert(char[] inChars)
/// <returns>The UnicdeCommand equivalent. NOTE that if numConsumed is zero, this value shouldn't be used as nothing was actually done.</returns>
protected char ConvertVT100InputCSI(char[] inChars, int offset, out int numConsumed)
{
char returnChar = '\0'; // dummy until changed.
switch (inChars[offset])
char returnChar = '\0'; // default until changed.
numConsumed = 0; // default if all the clauses below get skipped.
if (offset < inChars.Length)
{
case 'A': returnChar = (char)UnicodeCommand.UPCURSORONE; numConsumed = 1; break;
case 'B': returnChar = (char)UnicodeCommand.DOWNCURSORONE; numConsumed = 1; break;
case 'C': returnChar = (char)UnicodeCommand.RIGHTCURSORONE; numConsumed = 1; break;
case 'D': returnChar = (char)UnicodeCommand.LEFTCURSORONE; numConsumed = 1; break;
case 'H': returnChar = (char)UnicodeCommand.HOMECURSOR; numConsumed = 1; break;
case 'F': returnChar = (char)UnicodeCommand.ENDCURSOR; numConsumed = 1; break;
default: numConsumed = 0; break; // Do nothing if it's not a recognized sequence. Leave the chars to be read normally.
switch (inChars[offset])
{
case 'A': returnChar = (char)UnicodeCommand.UPCURSORONE; numConsumed = 1; break;
case 'B': returnChar = (char)UnicodeCommand.DOWNCURSORONE; numConsumed = 1; break;
case 'C': returnChar = (char)UnicodeCommand.RIGHTCURSORONE; numConsumed = 1; break;
case 'D': returnChar = (char)UnicodeCommand.LEFTCURSORONE; numConsumed = 1; break;
case 'H': returnChar = (char)UnicodeCommand.HOMECURSOR; numConsumed = 1; break;
case 'F': returnChar = (char)UnicodeCommand.ENDCURSOR; numConsumed = 1; break;
default: numConsumed = 0; break; // Do nothing if it's not a recognized sequence. Leave the chars to be read normally.
}
}
// The following are technically VT220 codes, not VT100, but I couldn't be bothered making a separate
// mapper just for them. (i.e. the proper way would be to make a VT220Mapper that inherits from this VT100Mapper,
Expand Down

0 comments on commit 87ec1e7

Please sign in to comment.