in src/common/details/console/gui/controls/HelpViewer.cs [17:113]
public static void DisplayHelpText(string[] lines, int width, int height, Colors normal, Colors selected, int selectedRow = 0, int selectedCol = 0, int selectionWidth = 1)
{
lines = lines.Prepend("").ToArray();
while (true)
{
if (height > lines.Length + 2) height = lines.Length + 2;
if (width == int.MinValue)
{
foreach (var line in lines)
{
if (line.Length > width)
{
width = line.Length;
}
}
width += 2;
}
var rect = Screen.Current.MakeSpaceAtCursor(width, height);
var border = rect.Height > 2 ? Window.Borders.SingleLine : null;
var viewer = new HelpViewer(null, rect, normal, selected, border)
{
Items = lines,
};
viewer.SetSelectedRow(selectedRow);
viewer.SetSelectedColumn(selectedCol, selectionWidth);
viewer.Run();
Screen.Current.SetCursorPosition(rect.X, rect.Y);
Screen.Current.ResetColors();
(selectedRow, selectedCol, selectionWidth) = (viewer._rowPicked, viewer._colPicked, viewer._widthPicked);
if (selectedRow < 0 || selectedCol < 0) break;
if (selectedRow >= lines.Length) break;
// check to see if there's a help command present on that row
var helpCommand = GetProgramHelpCommand();
var text = lines[selectedRow].TrimEnd();
if (text.Contains(helpCommand))
{
var at = text.LastIndexOf(helpCommand);
helpCommand = text.Substring(at);
// remove potential trailing parenthesis
var i = at - "(see: ".Length;
if (i > 0 && text.Substring(i).StartsWith("(see: ") && text.EndsWith(")"))
{
helpCommand = helpCommand.Substring(0, helpCommand.Length - 1);
}
if (helpCommand.EndsWith(")`#e_;*`"))
{
helpCommand = helpCommand.Substring(0, helpCommand.Length - 8);
}
var programExe = OperatingSystem.IsWindows() ? Program.Exe : Program.Exe.Replace(".exe", "");
var start = new ProcessStartInfo(programExe, $"quiet {helpCommand}");
start.UseShellExecute = false;
var process = Process.Start(start);
process?.WaitForExit();
if (process?.ExitCode == 1)
{
Environment.Exit(process.ExitCode);
}
}
else if (text.ToLower().Contains("see: https://") || text.ToLower().Contains("see https://"))
{
var at = text.LastIndexOf("https://");
var url = text.Substring(at);
ProcessHelpers.StartBrowser(url);
}
else
{
var tryItPrefix = $"try: {Program.Name} ";
var at = text.ToLower().LastIndexOf(tryItPrefix);
if (at > 0)
{
var tryCommand = text.Substring(at + tryItPrefix.Length);
if (tryCommand.EndsWith(")`#e_;*`"))
{
tryCommand = tryCommand.Substring(0, tryCommand.Length - 8);
}
var programExe = OperatingSystem.IsWindows() ? Program.Exe : Program.Exe.Replace(".exe", "");
var start = new ProcessStartInfo(programExe, $"cls {tryCommand}");
start.UseShellExecute = false;
Process.Start(start)?.WaitForExit();
Environment.Exit(1);
}
}
}
}