Skip to content

Commit

Permalink
Merge pull request #12 from ibigbug/handle-arrow-keys
Browse files Browse the repository at this point in the history
handle arrow keys
  • Loading branch information
ibigbug authored Dec 16, 2020
2 parents 615903a + 6125dd6 commit 43dbbc0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
8 changes: 4 additions & 4 deletions PowerSession.Cli/PowerSession.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<Title>PowerSession</Title>
<Authors>Yuwei Ba</Authors>
<IsPackable>true</IsPackable>
<PackageVersion>1.2.1</PackageVersion>
<AssemblyVersion>1.2.1</AssemblyVersion>
<FileVersion>1.2.1</FileVersion>
<PackageVersion>1.4.0</PackageVersion>
<AssemblyVersion>1.4.0</AssemblyVersion>
<FileVersion>1.4.0</FileVersion>
<PackAsTool>true</PackAsTool>
<ToolCommandName>PowerSession</ToolCommandName>
<RepositoryUrl>https://github.com/ibigbug/PowerSession</RepositoryUrl>
Expand All @@ -24,7 +24,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Packaging.Tools.Trimming" Version="1.1.0-preview1-26619-01" />
<PackageReference Include="System.CommandLine.Experimental" Version="0.3.0-alpha.19528.1" />
<PackageReference Include="System.CommandLine.Experimental" Version="0.3.0-alpha.19573.2" />
</ItemGroup>

</Project>
23 changes: 22 additions & 1 deletion PowerSession.ConPTY/Terminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace PowerSession.Main.ConPTY
public sealed class Terminal
{
private const string CtrlC_Command = "\x3";
private char[] UpArrow = new []{(char) 0x1b, (char) 0x5b, 'A'};
private char[] DownArrow = new []{(char) 0x1b, (char) 0x5b, 'B'};
private char[] RightArrow = new []{(char) 0x1b, (char) 0x5b, 'C'};
private char[] LeftArrow = new []{(char) 0x1b, (char) 0x5b, 'D'};

private readonly Stream _inputReader;
private readonly Stream _outputWriter;
Expand Down Expand Up @@ -92,7 +96,24 @@ private void AttachStdin()
while (!_token.IsCancellationRequested)
{
var key = Console.ReadKey(true);
_consoleInputWriter.Write(key.KeyChar);
switch (key.Key)
{
case ConsoleKey.UpArrow:
_consoleInputWriter.Write(UpArrow);
break;
case ConsoleKey.DownArrow:
_consoleInputWriter.Write(DownArrow);
break;
case ConsoleKey.RightArrow:
_consoleInputWriter.Write(RightArrow);
break;
case ConsoleKey.LeftArrow:
_consoleInputWriter.Write(LeftArrow);
break;
default:
_consoleInputWriter.Write(key.KeyChar);
break;
}
}
}, TaskCreationOptions.LongRunning);
}
Expand Down
2 changes: 1 addition & 1 deletion PowerSession.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PowerSession.ConPTY", "PowerSession.ConPTY\PowerSession.ConPTY.csproj", "{0E1F00C7-4F6B-4A7D-9A2F-6AD18A3D2F0A}"
EndProject
Expand Down

0 comments on commit 43dbbc0

Please sign in to comment.