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

x/sys: provide termios.h-like functionality #13210

Open
akevinbailey opened this issue Nov 11, 2015 · 6 comments

Comments

@akevinbailey
Copy link

commented Nov 11, 2015

Go needs a way to flush the stdin before prompt and Scanln.

See odeke-em/drive#157 for psoible fix for Linux.

@rakyll rakyll changed the title fmt should be able to flush stdin before printing the prompt and Scanln fmt: be able to flush stdin before printing the prompt and Scanln Nov 11, 2015

@adg

This comment has been minimized.

Copy link
Contributor

commented Nov 11, 2015

This isn't a fmt issue. It's a feature request for a function that should probably be in the x/sys repo.

This is how @minux implemented it, by calling out to a C library: https://github.com/minux/drive/blob/2b076a3dc02b5fee728e9eeee8c089a414de5fbc/src/tty.go

@adg adg changed the title fmt: be able to flush stdin before printing the prompt and Scanln x/sys: provide termios.h-like functionality Nov 11, 2015

@akevinbailey

This comment has been minimized.

Copy link
Author

commented Nov 12, 2015

I disagree. Flushing stdio should be a basic function of GO without having to call an external C library. Java and Python have it built in.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Nov 12, 2015

How do you flush standard input in Java and Python? Can you point to the docs?

Note that this issue is not about flushing standard output. Go can already do that perfectly well.

@akevinbailey

This comment has been minimized.

Copy link
Author

commented Nov 12, 2015

Sorry, I meant stdin

Java:
System.in.read(new byte[System.in.available()]); // Flushes stdin

Python:
from termios import tcflush, TCIOFLUSH
tcflush(sys.stdin, TCIOFLUSH)

@adg

This comment has been minimized.

Copy link
Contributor

commented Nov 12, 2015

On 12 November 2015 at 12:18, A. Kevin Bailey notifications@github.com
wrote:

from termios import tcflush, TCIOFLUSH
tcflush(sys.stdin, TCIOFLUSH)

This is the kind of thing I was suggesting in renaming this issue.

@rsc rsc added this to the Unreleased milestone Dec 28, 2015

@tklauser

This comment has been minimized.

Copy link
Member

commented Apr 3, 2018

Some of the termios.h function require more functionality than just mere syscall wrappers (which is the scope of the x/sys package) or they don't use any syscalls at all (like the cf* functions). Thus, it might be more appropriate to implement these functions in the (currently empty) x/term package? We may then make use of x/sys for certain parts of the implementation.

Also, some parts like cfmakeraw are already available in x/crypto/ssh/terminal and I guess we should move/copy them to x/term as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.