crossterm-rs / crossterm

Cross platform terminal library rust
MIT License
3.29k stars 280 forks source link

inconsistent and incorrect touch behaviour #881

Closed bgkillas closed 6 months ago

bgkillas commented 6 months ago

Describe the bug when using a touch device like a phone and using event::read() to get a mouse button and timing how long you hold it, the program either doesn't notice or doesn't properly time how long it was held.

To Reproduce Steps to reproduce the behavior: run the following on a phone

use crossterm::{
     event,
    event::{Event, MouseButton, MouseEvent, MouseEventKind},ExecutableCommand,terminal
};
use std::{
    io::{stdout, Write},
    time::Instant,
};
fn main()
{
terminal::enable_raw_mode().unwrap();
    stdout().execute(event::EnableMouseCapture).unwrap();
        'outer: loop
        {
            match event::read().unwrap()
            {
                Event::Mouse(MouseEvent {
                    kind: MouseEventKind::Down(MouseButton::Left),
                    ..
                }) =>
                {
                    let timer = Instant::now();
                    loop
                    {
                        match event::read().unwrap()
                        {
                            Event::Mouse(MouseEvent {
                                kind: MouseEventKind::Up(MouseButton::Left),
                                ..
                            }) =>
                            {
                            print!("{} ",timer.elapsed().as_millis());
                stdout().flush().unwrap();
                break 'outer
                }
                            _ =>
                            {}
                        }
                    }
                }
                _ =>
                {}
            }
        }
        stdout().execute(terminal::LeaveAlternateScreen).unwrap();
        terminal::disable_raw_mode().unwrap();
}
  1. fast tap to notice an impossible 0ms of delay from key down and up
  2. tap and move finger around to sometimes get a proper time but sometimes it just doesn't notice the input.

Expected behavior show the real time of tap held duration

OS pinephone pro running postmarketos

Terminal/Console foot

bgkillas commented 6 months ago

finally had more time to mess with this, turns out foot has weird logic to turn hold events into scroll events while still preserving the ability to select text via hold