Browse Source

Add auto-highlighting of commands' descriptions

pull/12/head
Anton Tarasenko 2 years ago
parent
commit
58d1d686b9
  1. 39
      sources/LevelAPI/Features/Commands/CommandDataBuilder.uc
  2. 10
      sources/Users/ACommandUserGroups.uc

39
sources/LevelAPI/Features/Commands/CommandDataBuilder.uc

@ -372,12 +372,45 @@ public final function Option(BaseText longName, optional BaseText shortName) {
/// Adds description to the selected sub-command / option. /// Adds description to the selected sub-command / option.
/// ///
/// Highlights parts of the description in-between "`" characters.
///
/// Does nothing if nothing is yet selected. /// Does nothing if nothing is yet selected.
public final function Describe(BaseText description) { public final function Describe(BaseText description) {
_.memory.Free(selectedDescription); local int fromIndex, toIndex;
if (description != none) { local BaseText.Formatting keyWordFormatting;
selectedDescription = description.Copy(); local bool lookingForEnd;
local MutableText coloredDescription;
if (description == none) {
return;
}
keyWordFormatting = _.text.FormattingFromColor(_.color.TextEmphasis);
coloredDescription = description.MutableCopy();
while (true) {
if (lookingForEnd) {
toIndex = coloredDescription.IndexOf(P("`"), fromIndex + 1);
} else {
fromIndex = coloredDescription.IndexOf(P("`"), toIndex + 1);
} }
if (toIndex < 0 || fromIndex < 0) {
break;
}
if (lookingForEnd) {
coloredDescription.ChangeFormatting(
keyWordFormatting,
fromIndex,
toIndex - fromIndex + 1);
lookingForEnd = false;
} else {
lookingForEnd = true;
}
}
coloredDescription.Replace(P("`"), P(""));
if (lookingForEnd) {
coloredDescription.ChangeFormatting(keyWordFormatting, fromIndex);
}
_.memory.Free(selectedDescription);
selectedDescription = coloredDescription.IntoText();
} }
/// Sets new name of the command that caller [`CommandDataBuilder`] constructs. /// Sets new name of the command that caller [`CommandDataBuilder`] constructs.

10
sources/Users/ACommandUserGroups.uc

@ -44,10 +44,10 @@ protected function BuildData(CommandDataBuilder builder)
builder.ParamText(P("group_name")); builder.ParamText(P("group_name"));
builder.SubCommand(P("addplayer")); builder.SubCommand(P("addplayer"));
builder.Describe(F("Adds new user to the group, specified by the player selector. Can add" builder.Describe(P("Adds new user to the group, specified by the player selector. Can add"
@ "several players at once. Allows to also optionally specify annotation (human-readable" @ "several players at once. Allows to also optionally specify annotation (human-readable"
@ "name) that can be thought of as a {$TextEmphasis comment}. If annotation isn't" @ "name) that can be thought of as a `comment`. If annotation isn't specified current"
@ "specified current nickname will be used as one.")); @ "nickname will be used as one."));
builder.ParamText(P("group_name")); builder.ParamText(P("group_name"));
builder.ParamPlayers(P("player_selector")); builder.ParamPlayers(P("player_selector"));
builder.OptionalParams(); builder.OptionalParams();
@ -60,8 +60,8 @@ protected function BuildData(CommandDataBuilder builder)
builder.ParamPlayers(P("player_selector")); builder.ParamPlayers(P("player_selector"));
builder.SubCommand(P("adduser")); builder.SubCommand(P("adduser"));
builder.Describe(F("Adds new user to the group. Allows to also optionally specify annotation" builder.Describe(P("Adds new user to the group. Allows to also optionally specify annotation"
@ "(human-readable name) that can be thought of as a {$TextEmphasis comment}.")); @ "(human-readable name) that can be thought of as a `comment`."));
builder.ParamText(P("group_name")); builder.ParamText(P("group_name"));
builder.ParamText(P("user_id")); builder.ParamText(P("user_id"));
builder.OptionalParams(); builder.OptionalParams();

Loading…
Cancel
Save