Drawing a button? #7095

Closed
opened 2026-01-31 00:54:52 +00:00 by claunia · 4 comments
Owner

Originally created by @Richienb on GitHub (Mar 22, 2020).

With the addition of mouse support, is it possible to simulate buttons in the Windows Terminal?

Originally created by @Richienb on GitHub (Mar 22, 2020). With the addition of mouse support, is it possible to simulate buttons in the Windows Terminal?
Author
Owner

@j4james commented on GitHub (Mar 22, 2020):

With the addition of mouse support, is it possible to simulate buttons in the Windows Terminal?

Yes. You can test this with the Linux dialog utility. In a WSL bash shell, try something like this:

dialog --yesno "Click Yes or No" 5 20 && echo Yes clicked
@j4james commented on GitHub (Mar 22, 2020): > With the addition of mouse support, is it possible to simulate buttons in the Windows Terminal? Yes. You can test this with the Linux [`dialog`](https://linux.die.net/man/1/dialog) utility. In a WSL bash shell, try something like this: dialog --yesno "Click Yes or No" 5 20 && echo Yes clicked
Author
Owner

@Richienb commented on GitHub (Mar 22, 2020):

@j4james Is there a demo with code that I can use or an implementation guide for this?

@Richienb commented on GitHub (Mar 22, 2020): @j4james Is there a demo with code that I can use or an implementation guide for this?
Author
Owner

@j4james commented on GitHub (Mar 22, 2020):

The general idea is you enable up/down click events by setting private mode 1000 ("\e[?1000h"). And then you can just read the events from stdin in the form of an escape sequence, in the same way you'd read a keypress event.

There are a bunch of a different reporting modes you can choose from, depending on whether you need a wider coordinate range, or you want to know the state of modifier keys, etc. Have a look at the Terminal Guide website for a nice explanation of the different options, and the format of the reports. But note that some formats are better supported than others. Windows in particular only supports modes 1000, 1002, 1003, 1005, and 1006 (at least for now).

Anyway, that's the low level protocol, but depending on what programming language and operating systems you're targeting, there may be higher level libraries you can use (e.g. ncurses). I'm not sure this is the best place to ask for example code though.

@j4james commented on GitHub (Mar 22, 2020): The general idea is you enable up/down click events by setting private mode 1000 (`"\e[?1000h"`). And then you can just read the events from stdin in the form of an escape sequence, in the same way you'd read a keypress event. There are a bunch of a different reporting modes you can choose from, depending on whether you need a wider coordinate range, or you want to know the state of modifier keys, etc. Have a look at the [Terminal Guide](https://terminalguide.netlify.com/mouse/) website for a nice explanation of the different options, and the format of the reports. But note that some formats are better supported than others. Windows in particular only supports modes 1000, 1002, 1003, 1005, and 1006 (at least for now). Anyway, that's the low level protocol, but depending on what programming language and operating systems you're targeting, there may be higher level libraries you can use (e.g. [ncurses](https://en.wikipedia.org/wiki/Ncurses)). I'm not sure this is the best place to ask for example code though.
Author
Owner

@zadjii-msft commented on GitHub (Mar 23, 2020):

This is a fine discussion, and by all means, feel free to continue it here, but since there's nothing really actionable for the Terminal team here, I'm going to close this issue. Thanks!

@zadjii-msft commented on GitHub (Mar 23, 2020): This is a fine discussion, and by all means, feel free to continue it here, but since there's nothing really actionable for the Terminal team here, I'm going to close this issue. Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#7095