Skip to content

Commit fd404a7

Browse files
committed
Better terminal input support (Utf8)
1 parent 2022cac commit fd404a7

3 files changed

Lines changed: 40 additions & 2 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
namespace SSHDebugger.Extensions
3+
{
4+
public static class ExtGdkKey
5+
{
6+
public static char GetChar(this Gdk.Key key)
7+
{
8+
return (char)Gdk.Keyval.ToUnicode((uint)key);
9+
}
10+
}
11+
}

SSHDebugger/SSHDebugger.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<Compile Include="Terminal\clsSSHTerminal.cs" />
5858
<Compile Include="Terminal\ITerminal.cs" />
5959
<Compile Include="Terminal\FrontEnd\windowTerminalGTK.cs" />
60+
<Compile Include="Extensions\ExtGdkKey.cs" />
6061
</ItemGroup>
6162
<ItemGroup>
6263
<EmbeddedResource Include="Properties\Manifest.addin.xml" />
@@ -78,6 +79,7 @@
7879
<Folder Include="Host\" />
7980
<Folder Include="Terminal\" />
8081
<Folder Include="Terminal\FrontEnd\" />
82+
<Folder Include="Extensions\" />
8183
</ItemGroup>
8284
<ItemGroup>
8385
<None Include="..\SSHDebugger.png">

SSHDebugger/Terminal/clsSSHTerminal.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
using System.Net.Sockets;
3636
using System.Text;
3737
using System.Threading.Tasks;
38+
using SSHDebugger.Extensions;
3839

3940
namespace SSHDebugger
4041
{
@@ -456,8 +457,32 @@ public void ShellSend(Gdk.Key key)
456457
if (LocalEcho) Write(key.ToString());
457458
if (shellStream!=null && shellStream.CanWrite)
458459
{
459-
shellStream.WriteByte((byte)key);
460-
shellStream.Flush();
460+
byte[] charBytes = null;
461+
462+
switch (key)
463+
{
464+
case Gdk.Key.Shift_L:
465+
case Gdk.Key.Shift_R:
466+
case Gdk.Key.ISO_Level3_Shift: //Alt Gr
467+
//Ignore
468+
break;
469+
case Gdk.Key.Return:
470+
case Gdk.Key.KP_Enter:
471+
charBytes = Encoding.UTF8.GetBytes(Environment.NewLine);
472+
break;
473+
case Gdk.Key.BackSpace:
474+
charBytes = new byte[] { (byte)'\b' };
475+
break;
476+
default:
477+
charBytes = Encoding.UTF8.GetBytes(new char[] { key.GetChar() });
478+
break;
479+
}
480+
481+
if (charBytes != null)
482+
{
483+
shellStream.Write(charBytes, 0, charBytes.Length);
484+
shellStream.Flush();
485+
}
461486
}
462487
}
463488
}

0 commit comments

Comments
 (0)