Eigenbahn / ai-dungeon-cli

:european_castle: A cli client to play.aidungeon.io
MIT License
150 stars 34 forks source link

Added "slow" typing animation with config option #19

Closed jgb95 closed 4 years ago

jgb95 commented 4 years ago

Hello! On the web version, there is a slow typing animation for the generated responses, but in this cli version, they are printed instantly, all at once. I feel like the animation really adds to the whole "retro" experience, so I went ahead and implemented something like that here.

To enable it, use "slow: true" in the config file (disabled by default).

Note: I am a student programmer (this is actually my first ever pull request!), so I am not sure if this is the best way of doing things. I am open to suggestions, of course. Or if this is something you'd rather not merge, that is fine as well

p3r7 commented 4 years ago

Hey!

I am not sure if this is the best way of doing things

That PR seems fine.

I am open to suggestions

There are only some minor stuff I would like changed, like:

if this is something you'd rather not merge, that is fine as well

I'm undecided regarding this feature. I guess one could just use an actual hardware terminal cool-retro-term to get this effect but your implementation would allow getting it with any term emulator and isn't too intrusive.

jgb95 commented 4 years ago

conditionally setting print_handler to print_slow_term instead of defining a separate print_slow_handler

The main reason I defined a separate print_slow_handler is because print_handler is used in various other places that we might not want to print slow, i.e. exceptions.

Would you like for print_handler to be set conditionally in the story functions and then reset to print_output_term before moving on, thus only printing slow in the story:

def process_regular_action(self, user_input: str):
        r = self.session.post(
            "https://api.aidungeon.io/sessions/" + str(self.session_id) + "/inputs",
            json={"text": user_input},
        )
        r.raise_for_status()
        action_res = r.json()
        action_res_str = action_res[self.prompt_iteration]["value"]

        if self.slow:
            print_handler = print_slow_term

        print_handler(action_res_str)

        print_handler = print_output_term

Or would you rather it just be set conditionally one time at the beginning and print slow (or not) for everything?

I'm undecided regarding this feature.

That's understandable, especially if you're already using a hardware terminal, haha! But yeah, I figured that maybe some people might want to play the game in their daily terminal emulator, and it would be neat to have this option. That's also why I implemented it as an optional config setting, rather than a default main feature. But I completely understand if you decide not to merge it, it's a small feature that I'd be happy to just maintain for myself :smile:

p3r7 commented 4 years ago

After proper testing I must say that the effect is quite nice.

It's much slower than the delay you'd get from a hardware terminal or cool-retro-term but that's a plus as it forces the user to read the input as it gets displayed.

So I agree to merge the feature. I'll do a PR on your branch to propose a few improvements (bug when slow is False due to missing global input_handler at top of fn def, referencing source of Unbuffered in code instead of doc...).

Stay tuned!

jgb95 commented 4 years ago

I'm glad to hear you enjoyed it! Improvements have been merged and all is looking good. Thanks for allowing me to contribute a small part to this cool project!

p3r7 commented 4 years ago

You're welcome 😄