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

POC input rawmode #65

Closed
wants to merge 1 commit into from
Closed

POC input rawmode #65

wants to merge 1 commit into from

Conversation

marcopeereboom
Copy link

This is a proof of concept to hand of raw terminal input to the calling application. We all agree that terminal input is absolutely awful but this way the application can do it's own parsing and be responsible for the entire keymap.

What do you think?

@nsf
Copy link
Owner

nsf commented Feb 4, 2015

I like the idea. There should be a way to get input from the terminal without relying on termbox's parsing abilities. But I will elaborate more on that tomorrow. Need to think about the way to do it in the API.

@marcopeereboom
Copy link
Author

Yeah I played around with it a bit and what really would be best (I think) is a hybrid of sorts. Return raw AND parsed event. The diff I wrote was tiny but it looked wrong since it was setting event.Raw before calling extract_event. Anywho glad you are going to noodle on it. Having this available would make my life easier so that i could parse some additional keystrokes.

@nsf
Copy link
Owner

nsf commented Feb 4, 2015

Well, the question is tricky, because there is also windows implementation and it has raw input too. On windows in fact I cut a lot of input info explicitly to emulate terminals behaviour. I'm thinking about some common interface that fits both. On terminals you get a raw stream of bytes, on windows you get structured events. As an option I can fill an array of bytes with raw bytes and/or this input structure on windows. But returning a slice as you did is not an option, it leads to mallocs, I'm thinking about io.Reader kind of interface.

@nsf
Copy link
Owner

nsf commented Feb 8, 2015

I haven't forgot about this issue. Still not sure how to do it right. :)

Will try a couple of things today, but no promises. May take awhile.

@marcopeereboom
Copy link
Author

I am eagerly awaiting it. Meanwhile I am trying to figure out unicode stuff with termbox-go.

@nsf
Copy link
Owner

nsf commented Feb 10, 2015

Well, right now the only way I see it is this:

func PollRawEvent(data []byte) Event

And add some kind of an int to Event struct, which signals the amount of bytes read. On windows it writes the whole input event structure to that buffer. After that I can add a package github.com/nsf/termbox-go/windows which contains windows specific functions to decode that byte array back into a structure with meaningful fields.

While it's trivial to implement for *nix, it's a bit harder for windows, but not impossible.

What do you think about that kind of API?

@nsf
Copy link
Owner

nsf commented Feb 10, 2015

Oh. On *nix it returns the raw stream of bytes of course. The feature must substitute both keyboard and mouse events. Will also add a new event type "EventRaw".

@marcopeereboom
Copy link
Author

I think I can live with that :)

What may be neat is to expose the event parser. So that way one can intercept "magical key/mouse strokes" and pass on the event to the parser and get an Event type as termbox sees it.

@nsf
Copy link
Owner

nsf commented Feb 10, 2015

That's a good idea too.

@marcopeereboom
Copy link
Author

I am ready for this!

Fighting with ^? vs ^H

term stuff is amazingly bad... Thanks for looking at this btw!

@nsf
Copy link
Owner

nsf commented Feb 11, 2015

^? and ^H are two backspaces I think, there are Backspace and Backspace2 in termbox-go. In my opinion just handle them as if they are the same key.

As for raw input stuff, sorry, I'm a bit busy right now. It probably delays until the weekend.

@marcopeereboom
Copy link
Author

Oh my I am an idiot. I did not see KeyBackspace2 at all. Thanks!

@nsf
Copy link
Owner

nsf commented Feb 15, 2015

Added *nix implementation. It's just a basic stuff, nothing fancy yet. More to be done.

@marcopeereboom
Copy link
Author

Have you decided on exporting the key parse call?

@nsf
Copy link
Owner

nsf commented Feb 18, 2015

Yes, but can't say when I'll add it. Sorry, busy with various stuff lately. This week though..

@nsf
Copy link
Owner

nsf commented Feb 22, 2015

Added ParseEvent API.

@nsf
Copy link
Owner

nsf commented Mar 23, 2015

I'm closing the pull request. Because the functionality is in the repo now. No windows implementation yet, which is planned, but has low priority (not because it's windows, but because termbox-go in general is not the top priority in my list).

@nsf nsf closed this Mar 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants