An autocomplete model can be also provided for the terminal, which will enable the autocompletion feature on the component.
Autocompletion can be triggered using the TAB key. In case there are more alternatives for arguments, these can be clicked to override the current input.
<div class="card">
<h:form>
<p:focus for="terminal"/>
<p>Try any of the following inputs as an example:</p>
<ul style="line-height: 1.5" class="m-0 pl-6">
<li>TAB</li>
<li><i>git</i> + TAB</li>
<li><i>svn co</i> + TAB</li>
<li><i>git pus</i> + TAB + TAB + TAB</li>
</ul>
<p:terminal id="terminal" widgetVar="term" styleClass="mt-5"
commandHandler="#{terminalAutoCompleteView.handleCommand}"
autoCompleteModel="#{terminalAutoCompleteView.autoCompleteModel}"
welcomeMessage="Welcome to PrimeFaces Terminal, how are you today?"/>
<p:commandButton type="button" value="Clear" icon="pi pi-trash" onclick="PF('term').clear()" styleClass="mt-3" />
</h:form>
</div>
@Named
@ViewScoped
public class TerminalAutoCompleteView implements Serializable {
private TerminalAutoCompleteModel autoCompleteModel;
public TerminalAutoCompleteView() {
this.autoCompleteModel = buildAutoCompleteModel();
}
private TerminalAutoCompleteModel buildAutoCompleteModel() {
TerminalAutoCompleteModel model = new TerminalAutoCompleteModel();
TerminalCommand git = model.addCommand("git");
git.addArgument("checkout");
git.addArgument("commit");
git.addArgument("status");
git.addArgument("pull");
git.addArgument("push").addArgument("origin").addArgument("master");
TerminalCommand svn = model.addCommand("svn");
svn.addArgument("commit");
svn.addArgument("checkout");
svn.addArgument("status");
svn.addArgument("update");
return model;
}
public TerminalAutoCompleteModel getAutoCompleteModel() {
return autoCompleteModel;
}
public String handleCommand(String command, String[] params) {
StringBuilder response = new StringBuilder("The command you entered was: '").append(command);
for (String param : params) {
response.append(" ").append(param);
}
return response.append("'").toString();
}
}