Updated Console Output

This commit is contained in:
Glax 2024-01-14 02:20:27 +01:00
parent b837dec116
commit b7a314cae3
2 changed files with 53 additions and 62 deletions

View File

@ -5,69 +5,60 @@ namespace VRC_Console;
public partial class OSCCollar
{
private const byte CoordinateSystemSize = 16;
private Task SetupConsoleOutput()
private void PrintConsole()
{
Layout layout = new Layout().SplitRows(
new Layout("Top"),
new Layout("Middle").SplitColumns(
new Layout("Config-Values"),
new Layout("Variable-Values"),
new Layout("Position")
),
new Layout("Bottom"));
if(OperatingSystem.IsWindows())
Console.WindowWidth += 20;
Table configTable = new Table();
configTable.AddColumn("ConVar");
configTable.AddColumn("Value");
configTable.AddRow("IP", this._config.Ip);
configTable.AddRow("Send-Osc-Port", this._config.PortSend.ToString());
configTable.AddRow("Receive-Osc-Port", _portReceive.ToString());
configTable.AddRow("HTTP-Port", this.OscQueryService?.TcpPort.ToString() ?? "");
configTable.AddRow("CalibrationX", $"{this._config.CalibrationX}");
configTable.AddRow("CalibrationY", $"{this._config.CalibrationY}");
configTable.AddRow(Resources.OSCCollar_ConsoleOutput_StretchDeadzone, $"{this._config.WalkStretchDeadzone}");
configTable.AddRow(Resources.OSCCollar_ConsoleOutput_RunStretch, $"{this._config.RunStretch}");
Table variableTable = new Table();
variableTable.AddColumn("OscVar");
variableTable.AddColumn("Value");
layout["Top"].Update(new FigletText(FigletFont.Parse(Resources.alligatorFont), "OSC Collar").LeftJustified());
layout["Config-Values"].Update(configTable);
layout["Variable-Values"].Update(variableTable);
layout["Position"].Update(new Panel(new Text(GetCoordinateSystem())));
layout["Bottom"].Update(new Text($"{_lastNilMessageSent} AvatarId: {_avatarId} Runtime: {DateTime.Now.Subtract(_programStarted)}"));
variableTable.AddRow("Status", "");
variableTable.AddRow("GPS 1", "");
variableTable.AddRow("GPS 2", "");
variableTable.AddRow("GPS 3", "");
variableTable.AddRow(Resources.OSCCollar_ConsoleOutput_PositionVector, "");
variableTable.AddRow(Resources.OSCCollar_ConsoleOutput_LeashStretch, "");
variableTable.AddRow(Resources.OSCCollar_ConsoleOutput_MovementVector, "");
variableTable.AddRow("CalibrationX", "");
variableTable.AddRow("CalibrationY", "");
return AnsiConsole.Live(layout).StartAsync(async displayContext =>
Console.Clear();
ValueTuple<string, string>[] configValues = new[]
{
while (true)
{
variableTable.Rows.Update(0, 1, new Text($"{(_allowMoving ? Resources.OSCCollar_ConsoleOutput_StatusEnabled : Resources.OSCCollar_ConsoleOutput_StatusDisabled)}"));
variableTable.Rows.Update(1, 1, new Text($"{_gps1.Distance:00.00000}"));
variableTable.Rows.Update(2, 1, new Text($"{_gps2.Distance:00.00000}"));
variableTable.Rows.Update(3, 1, new Text($"{_gps3.Distance:00.00000}"));
variableTable.Rows.Update(4, 1, new Text($"{_unitVectorLeash}"));
variableTable.Rows.Update(5, 1, new Text($"{_leashStretch:0.00000}"));
variableTable.Rows.Update(6, 1, new Text($"{_movementVector}"));
variableTable.Rows.Update(7, 1, new Text($"{GetCalibrationValues().Item1}"));
variableTable.Rows.Update(8, 1, new Text($"{GetCalibrationValues().Item2}"));
layout["Position"].Update(new Panel(new Text(GetCoordinateSystem())));
layout["Bottom"].Update(new Text($"{_lastNilMessageSent} AvatarId: {_avatarId} Runtime: {DateTime.Now.Subtract(_programStarted)}"));
displayContext.Refresh();
await Task.Delay(500);
}
});
new ValueTuple<string, string>("IP", this._config.Ip),
new ValueTuple<string, string>("Send-Osc-Port", this._config.PortSend.ToString()),
new ValueTuple<string, string>("Receive-Osc-Port", _portReceive.ToString()),
new ValueTuple<string, string>("HTTP", this.OscQueryService?.TcpPort.ToString() ?? ""),
new ValueTuple<string, string>("CalibrationX", $"{this._config.CalibrationX}"),
new ValueTuple<string, string>("CalibrationY", $"{this._config.CalibrationY}"),
};
ValueTuple<string, string>[] variableValues = new[]
{
new ValueTuple<string, string>("Status", $"{(_allowMoving ? Resources.OSCCollar_ConsoleOutput_StatusEnabled : Resources.OSCCollar_ConsoleOutput_StatusDisabled)}"),
new ValueTuple<string, string>("GPS 1", $"{_gps1.Distance:00.00000}"),
new ValueTuple<string, string>("GPS 2", $"{_gps2.Distance:00.00000}"),
new ValueTuple<string, string>("GPS 3", $"{_gps3.Distance:00.00000}"),
new ValueTuple<string, string>("GPS 1", $"{_gps1.Distance:00.00000}"),
new ValueTuple<string, string>(Resources.OSCCollar_ConsoleOutput_PositionVector, _unitVectorLeash.ToString()),
new ValueTuple<string, string>(Resources.OSCCollar_ConsoleOutput_LeashStretch, _leashStretch.ToString()),
new ValueTuple<string, string>(Resources.OSCCollar_ConsoleOutput_MovementVector, _movementVector.ToString()),
new ValueTuple<string, string>("CalibrationX", $"{GetCalibrationValues().Item1}"),
new ValueTuple<string, string>("CalibrationY", $"{GetCalibrationValues().Item2}")
};
Console.Write(GetCoordinateSystem());
int coordOffset = CoordinateSystemSize + 5;
int valueOffset = configValues.MaxBy(item => item.Item1.Length).Item1.Length + 3;
for (int i = 0; i < configValues.Length; i++)
{
Console.SetCursorPosition(coordOffset, i);
Console.Write($"{configValues[i].Item1}:");
Console.SetCursorPosition(coordOffset + valueOffset, i);
Console.Write(configValues[i].Item2);
}
ValueTuple<string, string> x = configValues.MaxBy(item => item.Item1.Length + item.Item2.Length);
int varOffset = coordOffset + x.Item1.Length + x.Item2.Length + 10;
valueOffset = variableValues.MaxBy(item => item.Item1.Length).Item1.Length + 3;
for (int i = 0; i < variableValues.Length; i++)
{
Console.SetCursorPosition(varOffset, i);
Console.Write($"{variableValues[i].Item1}:");
Console.SetCursorPosition(varOffset + valueOffset, i);
Console.Write(variableValues[i].Item2);
}
Console.SetCursorPosition(0, Console.WindowHeight - 2);
Console.Write($"{_lastNilMessageSent} AvatarId: {_avatarId} Runtime: {DateTime.Now.Subtract(_programStarted)}");
}
private String GetCoordinateSystem()

View File

@ -71,7 +71,6 @@ public partial class OSCCollar
this._portReceive = Extensions.GetAvailableUdpPort();
this.SetupOSCServer();
this.SetupOSCQuery();
this._consoleOutputTask = this.SetupConsoleOutput();
}
private OSCCollar(string ip = "127.0.0.1", int portSend = 9000, double radius = 100, double calibrationX = 0,
@ -212,6 +211,7 @@ public partial class OSCCollar
this._client.Send("/input/Vertical", 0f);
this._client.Send("/input/Horizontal", 0f);
this._lastNilMessageSent = DateTime.Now;
PrintConsole();
}else if (_allowMoving)
{
this._client.Send("/input/Vertical", Convert.ToSingle(_movementVector.Y));