Skip to content

Commit

Permalink
make 3 versions of keyread for linux tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertK66 committed Nov 12, 2021
1 parent 5adf6f2 commit 021b5bf
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 41 deletions.
2 changes: 1 addition & 1 deletion ScreenLib/MainScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void RunLine(String exitCmd) {

}

abstract public void HandleConsoleInput(Screen inputScreen);
abstract public void HandleConsoleInput(Screen inputScreen, string debugOption);

}
}
5 changes: 3 additions & 2 deletions StatusConsole/HostedCmdlineApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ public class HostedCmdlineApp : IHostedService {
public IUartService uartInFocus { get; set; }

private Screen appLogScreen;
private String debugOption;


// Constructor with IOC injection
public HostedCmdlineApp(IUartServices service, IConfiguration conf) {
_myServices = service ?? throw new ArgumentNullException(nameof(service));
uarts = service.GetUartServices();

debugOption = conf.GetValue<String>("Option") ?? "A";
}

public async Task StartAsync(CancellationToken cancellationToken) {
Expand Down Expand Up @@ -72,7 +73,7 @@ public async Task StartAsync(CancellationToken cancellationToken) {
appLogScreen.WriteLine("Use TAB to switch input control.");

// prepare Input cursor
guiInputHandler = Task.Run(() => main.HandleConsoleInput(appLogScreen));
guiInputHandler = Task.Run(() => main.HandleConsoleInput(appLogScreen, debugOption));

uartInFocus = _myServices.GetCurrentService();
}
Expand Down
5 changes: 4 additions & 1 deletion StatusConsole/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"profiles": {
"StatusConsole": {
"commandName": "Project"
"commandName": "Project",
"remoteDebugEnabled": false,
"authenticationMode": "Windows",
"remoteDebugMachine": "192.168.177.26"
}
}
}
88 changes: 52 additions & 36 deletions StatusConsole/StatusConsoleMainView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace StatusConsole {
Expand All @@ -16,51 +17,66 @@ public StatusConsoleMainView(int x, int y, HostedCmdlineApp model) : base(x, y,


private int selIdx = -1;
public override void HandleConsoleInput(Screen logScreen) {
public override void HandleConsoleInput(Screen logScreen, String debugOption) {
String line = "";
while(line != "quit") {
ConsoleKeyInfo k = Console.ReadKey();
if(k.Key == ConsoleKey.Tab) {
var saveLeft = Console.CursorLeft;
Model.uartInFocus = Model._myServices.GetNextService();
ConsoleColor cc = Model.uartInFocus.IsConnected() ? ConsoleColor.Green : ConsoleColor.Red;
logScreen.Write("Switched to ");
logScreen.WriteLine(Model.uartInFocus.GetInterfaceName(), cc);
ClearInputLine(line);
Console.Write(line);
} else if(k.Key == ConsoleKey.Enter) {
Model.uartInFocus?.SendUart(line);
LineBuffer.Add(line);
selIdx = -1;
ClearInputLine(line);
line = "";
} else if(k.Key == ConsoleKey.Escape) {
Clear(true); //Todo: !? geht nicht mehr !?
} else if(k.Key == ConsoleKey.UpArrow) {
if(LineBuffer.Count > 0) {
if(selIdx == -1) {
selIdx = LineBuffer.Count;
ConsoleKeyInfo? k = null;
if (debugOption.Equals("A")) {
k = Console.ReadKey(true);
} else if (debugOption.Equals("B")) {
k = Console.ReadKey(false);
} else {
if (Console.KeyAvailable) {
k = Console.ReadKey(false);
} else {
Thread.Sleep(100);
}
}

if (k != null) {

if (k?.Key == ConsoleKey.Tab) {
var saveLeft = Console.CursorLeft;
Model.uartInFocus = Model._myServices.GetNextService();
ConsoleColor cc = Model.uartInFocus.IsConnected() ? ConsoleColor.Green : ConsoleColor.Red;
logScreen.Write("Switched to ");
logScreen.WriteLine(Model.uartInFocus.GetInterfaceName(), cc);
ClearInputLine(line);
Console.Write(line);
} else if (k?.Key == ConsoleKey.Enter) {
Model.uartInFocus?.SendUart(line);
LineBuffer.Add(line);
selIdx = -1;
ClearInputLine(line);
line = "";
} else if (k?.Key == ConsoleKey.Escape) {
Clear(true); //Todo: !? geht nicht mehr !?
} else if (k?.Key == ConsoleKey.UpArrow) {
if (LineBuffer.Count > 0) {
if (selIdx == -1) {
selIdx = LineBuffer.Count;
}
selIdx--;
if (selIdx >= 0) {
ClearInputLine(line);
line = LineBuffer[selIdx];
Console.Write(line);
}
}
} else if (k?.Key == ConsoleKey.DownArrow) {
if (selIdx >= 0) {
selIdx++;
}
selIdx--;
if(selIdx >= 0) {
if (selIdx < LineBuffer.Count) {
ClearInputLine(line);
line = LineBuffer[selIdx];
Console.Write(line);
} else {
selIdx = 0;
}
}
} else if(k.Key == ConsoleKey.DownArrow) {
if(selIdx >= 0) {
selIdx++;
}
if(selIdx < LineBuffer.Count) {
ClearInputLine(line);
line = LineBuffer[selIdx];
Console.Write(line);
} else {
selIdx=0;
line += k?.KeyChar;
}
} else {
line += k.KeyChar;
}
}
logScreen.WriteLine("Input Handler closed!");
Expand Down
3 changes: 2 additions & 1 deletion StatusConsole/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
// "Pos_Y": 0
// }
//}
}
},
"Option": "C"
}

0 comments on commit 021b5bf

Please sign in to comment.