You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/Imperat/Command Help.md
+79-124
Original file line number
Diff line number
Diff line change
@@ -48,157 +48,112 @@ public final class GroupCommand {
48
48
}
49
49
}
50
50
```
51
-
### Help template
52
-
53
-
A help template is an interface that allows you to customize how the help-menu is displayed to the command-sender, there's already a `DefaultHelpTemplate` that looks like this when you execute `/group <group> help`:
the `N/A` represents an unknown description, if it is annoying you, you can set a description per subcommand/usage whether using the classic way or the annotations or just make your own template which doesn't include the description in the `UsageFormatter`
59
-
60
-
:::
61
-
62
-
Any help template has 4 main components:
63
-
- Header -> the header of the menu at the top
64
-
- Footer -> the footer of the menu at the bottom
65
-
-**UsageFormatter** -> controls the formatting of each single `CommandUsage`
66
-
-**UsageDisplayer** -> controls how the **formatted usages** are displayed together
67
-
68
-
#### Example Help Template
69
-
Here we will be building and creating our custom help-template that will define how the help-menu is displayed, let's call it `ExampleHelpTemplate` as below :-
51
+
### Help provider
52
+
A help provider is an interface whose only responsibility is to provide help-menu per command
53
+
and it needs `ExecutionContext` as a parameter to do so.
54
+
Help provider is cached in `Imperat`(the dispatcher) acting as a global help providing service.
70
55
56
+
You can implement your own help-provider and register it, to define how the help message is displayed as below:
Then inside of your custom help-template, you should just replace `new DefaultFormatter()` with `new ExampleUsageFormatter`*(or whatever the name of your class that implements the `UsageFormatter`)*.
82
+
### Templates
83
+
Some people would prefer to have their help displayed in the old format
84
+
Any help template has 3 main components:
85
+
-**Two Hyphens** (header and footer)
86
+
-**UsageFormatter** -> defines the formatting of each single `CommandUsage`
131
87
132
-
:::info
133
-
UsageDisplayer has already a premade implementation that you should be using (unless you want to make your own implementation) `PlainDisplayer`,
134
-
We recommend fetching the instance of `PlainDisplayer` through the method `UsageDisplayer.plain()`.
135
-
:::
88
+
In imperat, there's an abstract class called `HelpTemplate`, it implements `HelpProvider` which contains these components,
89
+
and another abstract class called `PaginatedHelpTemplate` (the name describes it's purpose) which extends `HelpTemplate` adding
90
+
the ability to display command usages in the form of pages.
91
+
Both classes are sealed, meaning that you can't extend them to make your own templates.
92
+
You are forced to use our built-in builders for creation of templates as below
136
93
137
-
### Paginated Help Template
94
+
```java
95
+
imperat.setHelpProvider(
96
+
HelpProvider.<YourPlatformSource>template()
97
+
.header(content ->"------- "+ content.command().name() +"'s help --------")
98
+
.footer(content ->"-----------------")
99
+
.formatter(yourOwnFormatter)
100
+
.displayer((context, usages)-> {
101
+
//define how usages are displayed here
102
+
})
103
+
.build()
104
+
);
105
+
```
138
106
139
-
It's exactly the same as a normal `HelpTemplate` but with two extra methods :
140
-
-`int syntaxesPerPage()` -> defines how many syntax should displayed per one page
141
-
-`String pagesHeaderComponent(int page, int maxPages)` -> controls how the pages header will be displayed as a singular part of the full header.
107
+
As you can see above, you can define header, footer, `UsageFormatter` and displayer consumer to override the default display algorithm.
142
108
109
+
:::note[Notice]
110
+
You are not required to create your displayer; By default, it's a simple for-loop showing the usages linearly
111
+
along with their description on the right.
143
112
144
-
:::note
145
-
In `PaginatedHelpTemplate` , there's a default method that combines 2 methods to form the total header of the help-menu that will be displayed, which are:-
146
-
-`getHeader` (from the normal `HelpTemplate` interface)
147
-
-`pagesHeaderComponent()` (from the `PaginatedHelpTemplate`) which for example shows how the `%currentPage%/%max_pages%` are displayed for a `PaginatedHelpTemplate`
148
113
:::
149
114
150
-
#### Example Paginated Help Template
115
+
the header and footer are hyphens for help (`HelpHyphen`) which has some data/content cached with it (`HyphenContent`) which contains:
116
+
- Command owning the usages
117
+
- current page and max-pages (they are `1` by default if the template isn't paginated)
151
118
152
-
We will be creating our own paginated help template by creating
153
-
a class and calling it for example `ExamplePaginatedHelpTemplate` :-
119
+
Here's a quick example below on creating and registering a paginated template
120
+
```java
121
+
imperat.setHelpProvider(
122
+
HelpProvider.<YourPlatformSource>paginated(10)
123
+
.header(
124
+
content ->"--------"+ content.command().name() +"'s help ("
paginated help templates forces you to specify the number of usages to be displayed per one page.
151
+
which is `10` usages per page as specified in the example above.
152
+
Moreover, the paginated template builder has the same methods as that of the normal template builder.
193
153
:::
194
-
### Results
195
154
196
-
**Here i will show you the results of your patience and hard work for learning**
197
-
**how to create your own help displaying and customize it:-**
198
-
##### For normal help-template
155
+
:::tip[Tip]
156
+
If no usage description is supplied during command creation it will return `N/A` by default.
157
+
The `N/A` represents an unknown description, if it is annoying you, you can set a description per subcommand/usage whether using the classic way or the annotations.
199
158
200
-

201
-
202
-
##### For paginated help-template
203
-
204
-

0 commit comments