-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recommended version #130
Comments
I would recommend the latest master. If you run into any issues, please let us know and we'll fix it. Also please give us any feedback that you have. We want to make sure it works for you. |
Thanks! Master seems to be very actively worked on, for example in the README it says that this a header-only library but I see you've moved to |
Yes, @MCWertGaming has been working on restructuring into cpp and header files. @jonashaag I think #129 is the main one to merge, and I think it is ready to be merged as is. Beyond that, @MCWertGaming do you expect any other big changes? It seems the other changes will be rather iterative. In particular, for the y/n prompt, I would imagine we would add some high level API for that into cpp-terminal itself, so from mamba's side, I think things should be rather stable. @jonashaag why don't we start working on an example how to do this and put it into cpp-terminal? In the meantime the refactor will be done and we can then use it in mamba. |
That would be great. You can see the code we currently use in the PR that's linked above. |
For convenience, current code: |
Perfect. I think that is straightforward, except: #ifdef _WIN32
response = strip(response);
#endif Do you now the reason for this? Does the |
@wolfv was there trailing whitespace in the Windows prompt response? Ref mamba-org/mamba#543 and mamba-org/mamba#544 Will we be facing this with |
I think this might be related to Windows |
The current stage on the terminal is a bit complicated. We have split the original headers into smaller headers with a clear structure. Also moved the source into actual source files to fix the definition clashes between the windows library and those of other peoples projects. Currently the splitting is almost done. I have merged #129, wich basically does the splitting for everything regarding the The next will be the Window class which needs a generall overhaul for the color management. I have created a proof of concept with @certik already for that. It might take me another week. But thats only important for you, if you plan on using the window class for managing the terminal. So the usage of the master branch is a bit tricky for the next one or two weeks, but I'll get back to this issue as soon as the bare minimum is done. If you want to use the old "header only" library, you can check it out here: |
Thanks @MCWertGaming, I appreciate your work on this. Regarding the prompt API, let's simply add an example how to do this, and implement it in cpp-terminal. I bet this example will have some simple function or a class such as |
I could create an example for that! But first I have to finish splitting the input and terminal preparation appart. Doing a prompt is really easy though. Therre is the so: #include <cpp-terminal/terminal.h>
#include <iostream>
int main() {
try {
// enters raw mode to capture input without requirering the user to press enter
// (not sure if it's desired for a prompt, but currently required. This will not be necessary with my next PR anymore)
Terminal term(true, false);
bool on = true;
int key;
while(on) {
std::cout << "Proceed? [y/N]"
key = term.read_key();
if (key == "y")
// proceed
else if (key == "n")
// stop
else
std::cout << "wrong input! Please try again\n";
}
} catch (const std::runtime_error& re) {
std::cerr << "Runtime error: " << re.what() << std::endl;
return 2;
} catch (...) {
std::cerr << "Unknown error." << std::endl;
return 1;
}
return 0;
} Something like that should work. Just make it a bit more fancy, maybe with colors or something :) |
Thank you! Actually I guess we want the prompt to require |
@MCWertGaming Mamba is already using cpp-terminal. All we need is to take the code and ensure it works with the latest master, and wrap it into some nice API. |
Oh okay, now I understand. Like I said, I'm working on finishing the spliting and restructuring. Tell me if you need additional features or something is not working. Updating from the header only cpp-terminal library the the current master is possible by changing the includes to the new headers. But if you have already cpp-terminal running. you can wait a few days until we pushed the next PR. Will look into finishing it this week with additional testing on windows due to the input class changes. For the API, what are you thinking of? Something like a simple function for creating a yes/no prompt that returns if CTRL+C was pressed? That should be quickly implemented. @certik |
Yes, something like that. Once the example works, we can refine the API to make it as simple to use as possible. |
Once #132 is merged, we will work on the prompt. |
#132 is merged since yesterday. I'm looking foreward into creating a first prototype for the prompt. @certik the multiline update of the prompt kind of broke what they are doing in mamba. Would you prefer to patch the prompt to make the multiline editing and the prmpt message optional / changable? Or should we make the second prompt independant from the first one? Also I'm thinking that it would be nice to extend the y/n prompt a bit with like colors and a spelling indicator that is green/red wether if the given input is valid or not. So my idea would be:
The prompt would only allow return, if no input, "yes", "y", "no" or "n" is entered and returns a value for "yes", "no" or abort. I'll try make other options than "yes" and "no" possible so it's really universally usable. Is this in your interest @jonashaag and @wolfv? Or would you prefer to have something more simple? |
@wolfv Are we trying to keep the prompt identical to conda? |
I think the y/n prompt should probably be a special kind of API, say |
hey, yeah, I don't think we need anything crazy fancy. The main problem with our current implementation is that it doesn't react without pressing enter, and doesn't abort on CTRL+C. Those two things (I think it requires the "raw" input mode?) would already be a major win! |
Yes, that's all I am imagining for the |
@wolfv so you actually prefer not having to press return? That'd be different from what Conda does, just FYI. I don't have any preference. |
Let's do some research when we're implementing this. I don't recall how other command line programs do this -- for example apt or dnf etc. could be good to look at a bunch. I think y and n are also far enoguh apart on the keyboard that not requiring enter migth be fine :) |
Am done with the first prototype now. Is this API desirable? It's not fully done yet, I'll add a "raw" prompt as well that does not require pressing enter to pass the key stroke and a "simplified" version that gives you a prompt with the minimal possible interface. @certik @jonashaag @wolfv |
I have made a PR with some variations of y/n prompts in #144. |
Awesome, thanks @MCWertGaming for working on it! |
Hello there, I would like to use cpp-terminal in Mamba. Specifically we'd like to use it for a yes/no prompt with Ctrl+C support. What's the recommended version to use right now? Would you recommend using latest master, or v0.1, or would you consider publishing a more recent stable release?
The text was updated successfully, but these errors were encountered: