修复help命令

This commit is contained in:
2026-02-27 22:42:26 +08:00
parent b67e0e7a03
commit 02ff8295ef
3 changed files with 16 additions and 8 deletions

View File

@@ -1 +1 @@
2026-02-27 22:33:00 2026-02-27 22:39:48

View File

@@ -1 +1 @@
fefb7e7 b67e0e7

View File

@@ -403,7 +403,7 @@ namespace CMLeonOS.Commands
{ {
Command = "help", Command = "help",
Parameters = "<page>", Parameters = "<page>",
Description = "Show help page (1-3)", Description = "Show help page (1-4)",
SubCommands = new[] { new SubCommandInfo { Command = "help all", Description = "Show all help pages" } } SubCommands = new[] { new SubCommandInfo { Command = "help all", Description = "Show all help pages" } }
} }
}; };
@@ -483,24 +483,32 @@ namespace CMLeonOS.Commands
pageNumber = 1; pageNumber = 1;
} }
int startIndex = (pageNumber - 1) * CommandsPerPage;
int endIndex = Math.Min(startIndex + CommandsPerPage, allCommands.Count);
Console.WriteLine("===================================="); Console.WriteLine("====================================");
Console.WriteLine($" Help - Page {pageNumber}/{totalPages}"); Console.WriteLine($" Help - Page {pageNumber}/{totalPages}");
Console.WriteLine("===================================="); Console.WriteLine("====================================");
Console.WriteLine(); Console.WriteLine();
int linesOnPage = 0; int linesOnPage = 0;
for (int i = startIndex; i < endIndex; i++) int currentLine = 0;
for (int i = 0; i < allCommands.Count; i++)
{ {
int cmdLines = GetCommandLinesCount(allCommands[i]); int cmdLines = GetCommandLinesCount(allCommands[i]);
if (linesOnPage + cmdLines > CommandsPerPage)
if (currentLine + cmdLines <= (pageNumber - 1) * CommandsPerPage)
{
currentLine += cmdLines;
continue;
}
if (linesOnPage >= CommandsPerPage)
{ {
break; break;
} }
DisplayCommand(allCommands[i]); DisplayCommand(allCommands[i]);
linesOnPage += cmdLines; linesOnPage += cmdLines;
currentLine += cmdLines;
} }
if (pageNumber < totalPages) if (pageNumber < totalPages)