Class TypingHints
java.lang.Object
com.j3d.engine.interact.cmd.complete.TypingHints
Provides real-time typing hints, suggestions, and visual feedback for the command palette input.
It analyses user input (tokens) to suggest command names, validate argument types, and highlight
potential errors or matches. This includes tab completion for command names, argument type checking
(e.g., Vector3, Colour, UUID, numbers, booleans, arg sets), and styling of usage strings to indicate
correctness or partial matches.
- Author:
- Lehlogonolo Poole
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic ColorColour used for command names that are considered "likely matches" (e.g., start with the input).static ColorColour used for command names that are considered "partial matches" (e.g., contain the input but don't start with it).static ColorColour used for arguments that are an exact match in type and value.static ColorColour used for arguments that are of an incorrect type or value.(package private) intThe maximum number of command name suggestions to display for both likely and partial matches.static ColorColour used for arguments that are a partial match or unfinished but potentially correct.private booleanA flag indicating whether an error related to tagged arguments has occurred. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate InlineHTMLargSetMatch(String arg, CmdToken token) Type checks a givenStringvalue as to be at least partially or fully matched within the given argument set.private InlineHTMLType checks a given value as to expect aBooleancolourGivenUsage(String usage, ArrayList<CmdToken> tokens) Styles a given command usage string based on the provided user input tokens.private InlineHTMLcolourMatch(String arg, CmdToken token) Type checks a given value as to expect aColorprivate InlineHTMLcolourTaggedArgs(InlineHTML rich, Command command, ArrayList<CmdToken> init) Appends a hint for tagged arguments to the givenInlineHTMLbased on the command's support for tagged arguments and whether any tagged arguments are present in the input.private InlineHTMLcorrectType(String arg) Colours the given type as fully correct.Filters a list of command usages based on the provided command tokens.private InlineHTMLidReferenceMatch(String arg, CmdToken token) private InlineHTMLincorrectType(String arg) Colours the given type as incorrectprivate InlineHTMLnotGivenYet(String arg) Styles a given input as generic (The user has not given this input yet.)private InlineHTMLnumberMatch(String arg, CmdToken token) Provides aQuadConsumerthat handles tab completion logic for the command palette.voidParses the given command tokens and provides typing hints or suggestions based on the current input.private InlineHTMLpartialStringMatch(ArrayList<String> options, String input) private InlineHTMLpartialType(String arg) Colours the given type as partially correct.private SamePair<ArrayList<InlineHTML>> Finds and styles possible command alias matches based on the given command token.private voidsetOptions(ArrayList<String> options) booleansimilarTypes(CmdToken token, String usage) Determines if a given command token's type is compatible with a specified usage string.voidtaggedArgErr(boolean value) Sets thetaggedArgErrflag.private InlineHTMLType checks a given value as to expect aVector3
-
Field Details
-
CMDNAME_LIEKLY_MATCH
Colour used for command names that are considered "likely matches" (e.g., start with the input). -
CMDNAME_PARTIAL_MATCH
Colour used for command names that are considered "partial matches" (e.g., contain the input but don't start with it). -
EXACT_MATCH
Colour used for arguments that are an exact match in type and value. -
PARTIAL_MATCH
Colour used for arguments that are a partial match or unfinished but potentially correct. -
INCORRECT_TYPE
Colour used for arguments that are of an incorrect type or value. -
MAX_CMDNAME_SUGGESTIONS
int MAX_CMDNAME_SUGGESTIONSThe maximum number of command name suggestions to display for both likely and partial matches. -
taggedArgErr
private boolean taggedArgErrA flag indicating whether an error related to tagged arguments has occurred. This is used to prevent other hints from overriding the tagged argument error message. -
options
-
-
Constructor Details
-
TypingHints
public TypingHints()
-
-
Method Details
-
parse
Parses the given command tokens and provides typing hints or suggestions based on the current input. This method updates theCommandParser.safeJLabel()with relevant information, such as command matches, usage hints, or error messages.- Parameters:
init- The initial list ofCmdTokenobjects, including any tagged arguments, representing the user's input.endsWithSpace- A boolean indicating whether the user's input currently ends with a space.
-
findUsages
public ArrayList<String> findUsages(String alias, ArrayList<String> usages, ArrayList<CmdToken> tokens) Filters a list of command usages based on the provided command tokens. It iteratively narrows down the possible usages by checking if each token's type is compatible with the corresponding argument in the usage string.- Parameters:
alias- The alias of the command being used.usages- An array of all possible usage strings for the command.tokens- AnArrayListofCmdTokenobjects representing the user's input arguments.- Returns:
- An
ArrayListofStringcontaining the usage strings that are compatible with the given tokens.
-
similarTypes
Determines if a given command token's type is compatible with a specified usage string. This method checks for various type matches, including generic ("any"), string, typed arguments, numbers, and specific object references (UUIDs).- Parameters:
token- TheCmdTokenrepresenting the user's input argument.usage- The expected usage string for an argument, e.g.,<string>,<int>,[option1|option2], or<vector3>.- Returns:
trueif the token's type is similar or compatible with the usage string,falseotherwise.
-
possibleCommandAliasMatches
Finds and styles possible command alias matches based on the given command token. It categorises matches into "likely" (aliases starting with the input) and "partial" (aliases containing the input but not starting with it), and styles them accordingly.- Parameters:
token- TheCmdTokenrepresenting the user's current input for a command name.- Returns:
- A
SamePaircontaining twoArrayLists ofInlineHTML. The first list contains likely matches, and the second contains partial matches.
-
onTabComplete
Provides aQuadConsumerthat handles tab completion logic for the command palette. This consumer attempts to complete the current command name or argument based on available aliases and suggestions. If no specific completion is found, it delegates to the defaultAction.- Returns:
- A
QuadConsumerthat takes:
-
colourTaggedArgs
Appends a hint for tagged arguments to the givenInlineHTMLbased on the command's support for tagged arguments and whether any tagged arguments are present in the input.- Parameters:
rich- The currentInlineHTMLto append to.command- TheCommandfor which the hints are being generated.init- The initial list ofCmdTokens, including any tagged arguments.- Returns:
- The modified
InlineHTMLwith the tagged argument hint appended and styled.
-
colourGivenUsage
Styles a given command usage string based on the provided user input tokens. This method provides visual feedback (colors) to indicate whether each argument in the usage string is correctly typed, partially matched, or incorrectly typed by the user.- Parameters:
usage- The expected command usage string, e.g., "mycommand[option1|option2] ". tokens- AnArrayListofCmdTokenrepresenting the user's parsed input.- Returns:
- A
InlineHTMLobject containing the styled usage string.
-
argSetMatch
Type checks a givenStringvalue as to be at least partially or fully matched within the given argument set.- Parameters:
arg- The expected arg string, which is[value1|value2|value3]and defines the accepted values.token- The token to check against- Returns:
- A styled
InlineHTMLwhich colours the given expected argument. This is either, the single fully matched value, a list of partially matched values or otherwise incorrect.
-
idReferenceMatch
- Parameters:
arg- The expected arg string, which is<point>,<line>,<tri>,<thing>,<point?>,<line?>,<tri?>or<thing?>token- The token to check against- Returns:
- A styled
InlineHTMLwhich colours the given expected argument.
-
numberMatch
- Parameters:
arg- The expected arg string, which is<int>,<int?>,<number>or<number?>token- The token to check against- Returns:
- A styled
InlineHTMLwhich colours the given expected argument
-
colourMatch
Type checks a given value as to expect aColor- Parameters:
arg- The expected arg string, which is<color>or<color?>token- The token to check against- Returns:
- A styled
InlineHTMLwhich colours the given expected argument. This goes the extra mile by colouring the background of the rich text to be the given input colour as to tell the user the input they gave.
-
boolMatch
Type checks a given value as to expect aBoolean- Parameters:
arg- The expected arg string, which is<boolean>or<boolean?>token- The token to check against- Returns:
- A styled
InlineHTMLwhich colours the given expected argument. This is either a fully matched boolean, or a partially matched boolean. Otherwise it is incorrect.
-
vector3
Type checks a given value as to expect aVector3- Parameters:
arg- The expected arg string, which is<vector3>or<vector3?>token- The token to check against- Returns:
- A styled
InlineHTMLwhich colours the given expected argument
-
correctType
Colours the given type as fully correct.- Parameters:
arg- The expected arg string, like<vector3>or[p|r|e]- Returns:
- A styled
InlineHTMLwhich colours the given expected argument
-
partialType
Colours the given type as partially correct. Partial matches are usually those who aren't a fully enclosed typed and get parsed as a string. These include:- Parameters:
arg- The expected arg string, like<vector3>or[p|r|e]- Returns:
- A styled
InlineHTMLwhich colours the given expected argumentPARTIAL_MATCH
-
incorrectType
Colours the given type as incorrect- Parameters:
arg- The expected arg string, like<vector3>or[p|r|e]- Returns:
- A styled
InlineHTMLwhich colours the given expected argumentINCORRECT_TYPE
-
notGivenYet
Styles a given input as generic (The user has not given this input yet.)- Parameters:
arg- The input to style- Returns:
- A
InlineHTMLobject containing the styled input
-
partialStringMatch
- Parameters:
options- The list of optionsinput- The input the user gave- Returns:
- A styled
InlineHTMLconsisting of a partially coloured match.
-
taggedArgErr
public void taggedArgErr(boolean value) Sets thetaggedArgErrflag.- Parameters:
value- The value to set it to.
-
getOptions
-
setOptions
-