Modify PaginationTools output. This fixes some problems with wraparound in the server console.
This commit is contained in:
parent
d4c7385781
commit
c00c929ad6
1 changed files with 19 additions and 24 deletions
|
|
@ -23,6 +23,9 @@ using System.Text;
|
|||
|
||||
namespace TShockAPI
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides tools for sending paginated output.
|
||||
/// </summary>
|
||||
public static class PaginationTools
|
||||
{
|
||||
public delegate Tuple<string, Color> LineFormatterDelegate(object lineData, int lineIndex, int pageNumber);
|
||||
|
|
@ -105,7 +108,7 @@ namespace TShockAPI
|
|||
this.FooterTextColor = Color.Yellow;
|
||||
this.NothingToDisplayString = null;
|
||||
this.LineFormatter = null;
|
||||
this.LineTextColor = Color.White;
|
||||
this.LineTextColor = Color.Yellow;
|
||||
this.maxLinesPerPage = 4;
|
||||
this.pageLimit = 0;
|
||||
}
|
||||
|
|
@ -198,7 +201,7 @@ namespace TShockAPI
|
|||
{
|
||||
if (player is TSServerPlayer)
|
||||
{
|
||||
Console.WriteLine(lineMessage);
|
||||
player.SendInfoMessage(lineMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -239,11 +242,11 @@ namespace TShockAPI
|
|||
PaginationTools.SendPage(player, pageNumber, dataToPaginate, dataToPaginate.Count, settings);
|
||||
}
|
||||
|
||||
public static List<string> BuildLinesFromTerms(
|
||||
IEnumerable terms, Func<object, string> termFormatter = null, string separator = ", ", int maxCharsPerLine = 80)
|
||||
public static List<string> BuildLinesFromTerms(IEnumerable terms, Func<object, string> termFormatter = null, string separator = ", ", int maxCharsPerLine = 80)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
StringBuilder lineBuilder = new StringBuilder();
|
||||
|
||||
foreach (object term in terms)
|
||||
{
|
||||
if (term == null && termFormatter == null)
|
||||
|
|
@ -254,9 +257,7 @@ namespace TShockAPI
|
|||
{
|
||||
try
|
||||
{
|
||||
termString = termFormatter(term);
|
||||
|
||||
if (termString == null)
|
||||
if ((termString = termFormatter(term)) == null)
|
||||
continue;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -270,41 +271,35 @@ namespace TShockAPI
|
|||
termString = term.ToString();
|
||||
}
|
||||
|
||||
bool goesOnNextLine = (lineBuilder.Length + termString.Length + separator.Length > maxCharsPerLine);
|
||||
if (!goesOnNextLine)
|
||||
if (lineBuilder.Length + termString.Length + separator.Length < maxCharsPerLine)
|
||||
{
|
||||
if (lineBuilder.Length > 0)
|
||||
lineBuilder.Append(separator);
|
||||
lineBuilder.Append(termString);
|
||||
lineBuilder.Append(termString).Append(separator);
|
||||
}
|
||||
else
|
||||
{
|
||||
// A separator should always be at the end of a line as we know it is followed by another line.
|
||||
lineBuilder.Append(separator);
|
||||
lines.Add(lineBuilder.ToString());
|
||||
lineBuilder.Clear();
|
||||
|
||||
lineBuilder.Append(termString);
|
||||
lineBuilder.Clear().Append(termString).Append(separator);
|
||||
}
|
||||
}
|
||||
if (lineBuilder.Length > 0)
|
||||
lines.Add(lineBuilder.ToString());
|
||||
|
||||
if (lineBuilder.Length > 0)
|
||||
{
|
||||
lines.Add(lineBuilder.ToString().Substring(0, lineBuilder.Length - 2));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
public static bool TryParsePageNumber(
|
||||
List<string> commandParameters, int expectedParamterIndex, TSPlayer errorMessageReceiver, out int pageNumber)
|
||||
public static bool TryParsePageNumber(List<string> commandParameters, int expectedParameterIndex, TSPlayer errorMessageReceiver, out int pageNumber)
|
||||
{
|
||||
pageNumber = 1;
|
||||
if (commandParameters.Count <= expectedParamterIndex)
|
||||
if (commandParameters.Count <= expectedParameterIndex)
|
||||
return true;
|
||||
|
||||
string pageNumberRaw = commandParameters[expectedParamterIndex];
|
||||
string pageNumberRaw = commandParameters[expectedParameterIndex];
|
||||
if (!int.TryParse(pageNumberRaw, out pageNumber) || pageNumber < 1)
|
||||
{
|
||||
if (errorMessageReceiver != null)
|
||||
errorMessageReceiver.SendErrorMessage(string.Format("\"{0}\" is not a valid page number.", pageNumberRaw));
|
||||
errorMessageReceiver.SendErrorMessage("\"{0}\" is not a valid page number.", pageNumberRaw);
|
||||
|
||||
pageNumber = 1;
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue