Comments (4)
Hello @psychon
Thanks for reporting this
I think this was improved ~30 days ago with:
#774
Every builtin components have been updated.
A new API for custom on is available
bool Mouse::IsPressed(Button button) const;
bool Mouse::IsHeld(Button button) const;
bool Mouse::IsReleased(Button button) const;
Does the new version satisfies you, or do we need something different?
That being said, the example print_key_press
would still report the same kind of result.
from ftxui.
Ah, you are right. I was initially experimenting with the latest release and then switched to latest main
before reporting this issue.
However, "things" still don't seem to work correctly. I switched to the component/dropdown
example. My instructions:
- click an entry (to open the dropdown)
- move the mouse to an item
- click
- move the mouse
With xterm
, the dropdown closes at step 3 and the mouse move has no effect. With urxvt, the mouse click has no effect and only at step 4 does "something" happen.
Put differently: Yes, I can now interact with the dropdown via the mouse, but things still behave weird / unexpected.
I checked out git at c31aecf2edde81d20f4f4bc8c97af053026483a6^
(= before #774) and there things indeed behave as I described out. That's a lot worse than the current state of things.
from ftxui.
I found http://pod.tst.eu/http://cvs.schmorp.de/rxvt-unicode/doc/rxvt.7.pod#Mouse_Reporting and the following sub-sections. ftxui seems to enable 1000, 1003, 1015, and 1016.
I did some more tests showing the raw input that was received in a human readable form:
diff --git a/examples/component/print_key_press.cpp b/examples/component/print_key_press.cpp
index c481271..221f93a 100644
--- a/examples/component/print_key_press.cpp
+++ b/examples/component/print_key_press.cpp
@@ -22,6 +22,9 @@ std::string Stringify(Event event) {
std::string out;
for (auto& it : event.input())
out += " " + std::to_string((unsigned int)it);
+ out += " ";
+ for (auto& it : event.input())
+ out += it;
out = "(" + out + " ) -> ";
if (event.is_character()) {
I am just showing the printable part of the above output.
- Mouse move:
[<31;94;30M
- Button 1 press:
[<0;98;29M
- Button 1 release:
[<0;98;29m
- Mouse move after the above button business:
[<32;67;40M
- Button 2 and 3 work the same with numbers 1 and 2.
- Mouse moves always indicate the last button.
- After I pressed button 1, mouse moves use
32
as the first argument - After button 2, it's
33
- After button 3, it's
34
- After I pressed button 1, mouse moves use
So... the moves are the last button that was pressed with 32 added?
With the following proof-of-concept patch, the print_key_press
example seems to produce sane output.
diff --git a/src/ftxui/component/terminal_input_parser.cpp b/src/ftxui/component/terminal_input_parser.cpp
index 3ba0e69..ec3cc3c 100644
--- a/src/ftxui/component/terminal_input_parser.cpp
+++ b/src/ftxui/component/terminal_input_parser.cpp
@@ -401,6 +401,10 @@ TerminalInputParser::Output TerminalInputParser::ParseMouse( // NOLINT
output.mouse.meta = bool(arguments[0] & 8); // NOLINT
output.mouse.x = arguments[1]; // NOLINT
output.mouse.y = arguments[2]; // NOLINT
+ if (arguments[0] & 32) {
+ // DECMode::kMouseSgrExtMode: This is a move and not a press
+ output.mouse.button = Mouse::Button::None;
+ }
return output;
}
How did I come up with the above? The following part of the urxvt docs (but ignoring the offset since mode 1015 does not include one):
Bit 5 of b is set for motion events or double clicks (rxvt extension, disabled by default):
Motion = (b - SPACE) & 32
However, if I open a new terminal, newer press a button and move the mouse, I get e.g. [<31;78;45M
. Button -1 pressed?!?
I also dug into urxvt's source code. The mouse reporting "stuff" is generated here: http://cvs.schmorp.de/rxvt-unicode/src/command.C?revision=1.603&view=markup#l1353
So... since ftxui enables mode 1006 (kMouseSgrExtMode / PrivMode_ExtMouseSGR), all the docs for urxvt mode do not apply. And I could have actually noticed that the escape sequences above have [<
and the <
would not be present in urxvt mode...
Besides that, I have not found anything helpful in this source code. I am now trying to figure out how this code remembers the last button that was pressed?!?
Edit: Found it. MEvent
is a member variable of the class and is used to track this. The button_number is calculated at MEvent.button - Button1
. At startup, MEvent.button
is initialised to AnyButton
and AnyButton - Button1
is -1. I'll report a bug to urxvt.
@ArthurSonzogni I hope some of this helps you help me. I never dug into escape sequences before.
from ftxui.
Thanks you very much!
You made me realize 3 things:
- I forgot to record the
mouse.control
modified. - Terminal do report "movement". I can simplify ftxui!
urxvt
behave a bit differently than other terminals.
I start working on something. I will send you a PR.
from ftxui.
Related Issues (20)
- when will release new version HOT 4
- Simulate a timeline HOT 2
- dropdown example bugs HOT 2
- Creating an input window, and outputting entered text after hitting enter or special key. HOT 3
- how to hide the cursor HOT 2
- About Support for Full width Characters in FTXUI HOT 10
- Is there an Event handling when CTRL+SHIFT+C is pressed? HOT 2
- From ftxui::Element to std::string or char* HOT 3
- focus problem HOT 2
- Untidy exit on std::terminate() HOT 1
- Do you have any recommended fonts? The font provided by windows is not very beautiful HOT 2
- How to highlight text inside ftxui::text() or ftxui::paragraph() HOT 1
- Is there a bug between full width characters and vertical?
- Running tests alters the terminal state HOT 2
- The scrollbar doesn't work in the "homescreen.cpp" demo HOT 2
- [feature request] Scatter plots HOT 1
- Dynamically adding elements to Checkboxes HOT 5
- Correctness of layout requirement for flexbox. Scrollbar implementation. HOT 1
- I've tried everything. I need help
- Compression priority when rendering a vbox with inadequate space. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ftxui.