Comments (6)
Clikt currently only uses System.out
if you call CliktCommand.main
or if you use prompt()
. If you don't use prompt()
, and want to output to another location, you can use CliktCommand.parse
instead of main
.
Take a look at how main is implemented to see which exceptions to catch.
That being said, maybe there's a way to make that easier. Can you give me an example of your use case?
from clikt.
I looked over the project before I submitted the issue, to see what I could do to implement this myself, and it seemed to be mostly possible except for prompts. I'd have to implement my own version of CliktCommand.main
regardless, as exiting the process wouldn't be feasible.
My use case is niche and quite specific. I want to embed a CLI using Clikt in a Minecraft client mod, and therefore using standard I/O channels is not really an option.
from clikt.
I'm happy to add support for your use case if I can. Did you want to use the built-in prompts? It should be possible to add a property to the context with a customizable object that handles reading and writing. Does your embedded CLI have something equivalent to System.console
, or at least something equivalent to System.out.println
and System.in.readln
? Do you have a way to do password prompts? What about TermUi.editFile
?
from clikt.
Being able to use the built-in prompts isn't a necessity, but it would be nice. The CLI is embedded into the chat functionality of the game. That means I'm unfortunately limited to printing to chat (println
replacement), and intercepting sent chat messages. There isn't a direct equivalent of waiting for a user input, but implementing that myself shouldn't be very difficult.
From what I can tell TermUi.editText
, TermUi.editFile
, TermUi.prompt
, and TermUi.confirm
are all blocking. I should be able work around this quite easily, to prevent the game from freezing. It seems editing is done in a different process, so I don't think that would be an issue. Passwords prompts wouldn't be able to hide the password, and would have to either be unsupported, or work as normal prompts.
from clikt.
I assume editText
and editFile
don't make sense for your environment. But I could have all the prompt code use an interface that you could implement to do the i/o. Would this be possible to implement?
interface CliktConsole {
/**
* Show the [prompt] to the user, and return a line of their response.
*
* This function will block until a line of input has been read.
*
* @param prompt The text to display to the user
* @param hideInput If true, the user's input should not be echoed to the screen. If the current console
* does not support hidden input, this argument may be ignored.
* @return A line of user input, or null if an error occurred.
*/
fun promptForLine(prompt: String, hideInput: Boolean):String
/**
* Show some [text] to the user.
*/
fun print(text:String):String
}
from clikt.
That would definitely be possible to implement.
I have addition to this issue, maybe we could add something like TermUi.echo
's function as a protected function inside CliktCommand
, so we can use echo
inside commands, without explicitly using TermUi
.
from clikt.
Related Issues (20)
- Options and arguments broken in 4.2.1 HOT 2
- Clikt 4.2.1 does not work for me when building native images HOT 1
- multiple cooccurring option groups e.g. val userOptions by UserOptions().cooccurring().multiple() HOT 5
- clikt and kscript standalone main have the same JVM signature (main([Ljava/lang/String;)V): HOT 2
- Pasting multiple lines to a prompt is broken HOT 2
- Can't use option inside option group in defaultLazy HOT 2
- Kotlin debug doesn't stop at Clikt subcommand HOT 1
- Add support for TextStyle in the Text Widget. HOT 1
- [Question] Callback to execute some code when the help is shown HOT 4
- Feature request: Command/option/flag information exposed via hook HOT 2
- Init inside `Object` in Kotlin Script HOT 1
- Consider specifying limits on `counted`
- Option to echo "raw" String HOT 4
- Feature request: generation of man pages or AsciiDoc HOT 1
- Feature request: choosing from options using arrow keys or fuzzy find HOT 1
- [QUESTION] Validate input arguments without running the command HOT 1
- Support path arguments for native HOT 3
- Other ways to construct a CliktCommand object HOT 4
- Disable prompt() globally HOT 3
- Cooccuring option group with required options is passed as nullable HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clikt.