Hi Patrique,

I have been able to achieve it using session.readLine() :
final String userInput = session.readLine("Do you want to proceed with the
deletion? (y/n)\n", null);
if (!StringUtils.equalsIgnoreCase(userInput, "y")) return;

I don't know what the "mask" parameter is for, but just setting it to null
did the job.

I assume that session.getKeyboard() is useful when you want to listen the
keyboard while the command is running, whereas with readLine() it pauses
the execution and waits for the input.


Best,
Damien


Le jeu. 16 sept. 2021 à 22:57, Patrique Legault <patriquelega...@gmail.com>
a écrit :

> I tried to get an example going today of this but failed to properly use
> the getKeyboard() function.
>
> With that being said I would like to an example of this.
>
> On Thu., Sep. 16, 2021, 7:26 a.m. Jean-Baptiste Onofré, <j...@nanthrax.net>
> wrote:
>
> > Hi Damien,
> >
> > Yes, sure.
> >
> > You can get the session by reference (for instance @Reference Session).
> >
> > Then session gives you access to getKeyboard() which is a input stream
> > with what the user input.
> >
> > I can improve the example with the required code if you want.
> >
> > Regards
> > JB
> >
> > On 16/09/2021 11:39, Damien Saulnier wrote:
> > > Hi,
> > >
> > > I would like to know if it is possible to develop some interactive
> > commands
> > > in the Karaf Shell, pausing the execution of the command and reading
> some
> > > additional input from the user.
> > > I have not found anything about that neither in the documentation nor
> in
> > > the examples on Github.
> > >
> > > To give a basic use case, I would like to ask for a confirmation before
> > > proceeding with the actual removal in the "RemoveCommand" example:
> > >
> >
> https://github.com/apache/karaf/blob/main/examples/karaf-command-example/karaf-command-example-command/src/main/java/org/apache/karaf/examples/command/command/RemoveCommand.java
> > >
> > >
> > > Best,
> > > Damien
> > >
> >
>

Reply via email to