feat(io,cmd): configurable prompt, clean UX — remove # prefix, Ctrl+C, domain/bean sync - #67
Merged
Merged
Conversation
Change the default prompt from "$> " to "> " and allow users to
override it via the existing config file using the "prompt" key.
Template variables are resolved against the current session state on
each readline call:
{server} - connected JMX server (host:port or full URL), empty if not connected
{domain} - currently selected domain, empty if none
{bean} - currently selected bean, empty if none
Example config entries:
prompt=>
prompt=[{server}]>
prompt=[{domain}/{bean}]>
- AppConfig: add "prompt" key with default "> "
- PromptTemplate: new utility class that resolves variables against Session
- JlineCommandInput: accept Supplier<String> so prompt is re-evaluated each readline
- CommandCenter: expose getSession() for wiring in CliMain
- CliMain: wire prompt supplier using a session ref populated after CommandCenter construction
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rompt blocks, domain/bean sync
- VerboseCommandOutput: remove '#' prefix from printMessage(); errors
(printError) keep '#' for script parseability
- HelpCommand: capitalize header message; widen command column to 11
chars to fit longest command name ('unsubscribe')
- CliMain: catch UserInterruptException in the REPL loop and print
'Interrupted.' instead of propagating the exception
- PromptTemplate: add {?...} optional block syntax — a block is
rendered only if at least one {var} inside it is non-empty; supports
nesting via brace-balanced parser. Update AppConfig default config
examples to show optional-block templates.
- BeanCommand: after setting a fully-qualified bean, auto-set the
session domain to the domain prefix of the bean name
- DomainCommand: when setting a new domain, unset the session bean if
it does not belong to that domain
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove the '#' prefix from printError() in VerboseCommandOutput, PrintStreamCommandOutput, and WriterCommandOutput, and from the safety-net error handler in CliMain.main(). All output is now prefix-free. Update tests: StartupErrorsE2EIT, VerboseLevelIT, CliArgumentsE2EIT. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
This PR delivers two related improvements: configurable REPL prompt and several UX polish fixes.
1. Configurable prompt with template variables
The default REPL prompt changes from
$>to>. Users can override it via$XDG_CONFIG_HOME/jmxsh/config.propertiesusing thepromptkey.Template variables
{server}host:portwhen the URL carries a host, otherwise full URL string); empty when not connected{domain}{bean}Optional blocks
Wrap content in
{?...}to hide that section when all variables inside it are empty:With
{?[{server}] }{?{domain}}{?/{bean}}>:>[host:9010] java.lang/java.lang:type=Memory>2. UX polish
Remove
#prefix from normal messages —VerboseCommandOutput.printMessage()no longer prepends#. Errors (printError) keep their#prefix since they go to stderr.Ctrl+C exits cleanly —
UserInterruptExceptionfrom JLine is caught in the REPL loop; printsInterrupted.and exits cleanly instead of printing the exception class name.Auto-set domain from bean — When
BeanCommandsets a fully-qualified bean (e.g.java.lang:type=Memory), it also sets the session domain tojava.langautomatically.Unset bean when domain changes — When
DomainCommandchanges the domain, if the current bean doesn't belong to the new domain, the bean is automatically unset with a message.Help column width —
helpcommand widened to 11-char columns to fitunsubscribe; header capitalised.Changes
VerboseCommandOutput— remove#fromprintMessage()HelpCommand— capitalize header; widen format column to 11CliMain— catchUserInterruptExceptionin REPL loopAppConfig— addpromptkey (default"> "), update config file template with optional-block examplesPromptTemplate(new) — resolves{server},{domain},{bean}; adds{?...}optional block support via brace-balanced parserJlineCommandInput— acceptSupplier<String>prompt for dynamic re-evaluationCommandCenter— exposegetSession()for wiring inCliMainBeanCommand— auto-set domain from resolved bean nameDomainCommand— unset bean when domain changesTests
AppConfigTest—promptproperty casesPromptTemplateTest(new) — 15 cases covering variables, optional blocks, edge casesBeanCommandTest— domain auto-set from fully-qualified and partial bean namesDomainCommandTest— bean unset / keep / no-op cases for domain changesVerboseLevelIT— updated to reflect no#on messagesHelpCommandTest— updated expected column width