Skip to content
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

exit on first keystroke should print the keystroke on the terminal #25

Closed
pberto opened this issue Nov 17, 2017 · 7 comments
Closed

exit on first keystroke should print the keystroke on the terminal #25

pberto opened this issue Nov 17, 2017 · 7 comments
Labels

Comments

@pberto
Copy link

pberto commented Nov 17, 2017

The -s: option activates the "Screensaver" mode, with exits on first keystroke.
This is nice but the keystroke is not recorded on the terminal. So if for example user wants to type "git" the first character g should be recorded and when learning the screen from matrix, g should be present on the terminal along with whatever other characters the user has typed.

@abishekvashok
Copy link
Owner

That seems an ideal feature...

@livibetter
Copy link
Contributor

I've never thought of this, and thanks to hstr, the only program that I know that can do this, it needs that, so user can edit command in shell prompt and execute command by the shell.

After found out how hstr does it, I wrote the following piece of code:

                ungetch(keypress);

                char *buf = malloc(1);
                char *p = buf;
                while ((*p++ = wgetch(stdscr)) != ERR) {
                    buf = realloc(buf, sizeof(buf) + 1);
                }
                *(p - 1) = 0;

                p = buf;
                while (*p) {
                    ioctl(0, TIOCSTI, p++);
                }
                free(buf);

Put them before finish():

cmatrix/cmatrix.c

Lines 477 to 479 in 93fd357

if ((keypress = wgetch(stdscr)) != ERR) {
if (screensaver == 1) {
finish();

The code can be reduced down to one line if we only consider human typing or single character, the code above will make sure whatever in standard input will be carried over via TIOCSTI (simulating typed input), a single char or a whole bunch of text, for instance, user pastes a text.

TIOCSTI is likely the simplest way to achieve the feature—if there is even a possibility of having other methods—I was baffled by how a process could put stuff in standard input after it's gone, that just doesn't seem possible unless you have help from outside. Before reading hstr's code, I thought it must employ some wrapper with some secret Bash/shell functionality that I am not aware of, but nope. Its solution is just that ioctl line.

While trying to read about the magic of TIOCSTI, I stumbled On the Insecurity of TIOCSTI. We will need more code to turn it back on for those systems, if that is possible, although Linux wouldn't be one of them.

Nonetheless, do we actually need this feature for not being able to press an extra key that is destined to be forgotten? Frankly, I would vote against this feature, it's cool, but not worth all the extra codes in my opinion.

@abishekvashok
Copy link
Owner

I was baffled by how a process could put stuff in standard input after it's gone

We can do that just before exiting after the terminal has been cleared. It's really easy.

@abishekvashok
Copy link
Owner

Pass an argument (character) to finish. See the screensaver switch case inside the on character press selection section.

@livibetter
Copy link
Contributor

@abishekvashok then you should be the one to do it.


This issue got me a thought, if we would be doing this, why not go all the way, that is mouse as well. The -s screensaver mode should also exit upon any mouse activities. CMatrix be a real screensaver!

But again, against it, because more codes, that's why I am not opening a feature request, @abishekvashok or anyone think it's good, it's your issue to open.

@AstolfoKawaii
Copy link
Contributor

Pull request #67 implements this functionality.

@kovasap
Copy link

kovasap commented Aug 2, 2024

This feature does not seem to work when building with cmake at head. Anyone else have this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants