Giter VIP home page Giter VIP logo

Comments (6)

ajalt avatar ajalt commented on May 26, 2024

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.

feature avatar feature commented on May 26, 2024

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.mainregardless, 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.

ajalt avatar ajalt commented on May 26, 2024

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.

feature avatar feature commented on May 26, 2024

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.

ajalt avatar ajalt commented on May 26, 2024

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.

feature avatar feature commented on May 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.