Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
termion
termion
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 61
    • Issues 61
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 22
    • Merge Requests 22
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • redox-os
  • termiontermion
  • Issues
  • #168

Closed
Open
Opened Jun 09, 2019 by doums@doums⚓

[question] async_stdin and keys()

Hi,

I noted that while being in async_stdin "mod" the keys() method does not return proper events. For example if I use the code below, Left key is not recognized. If I use let mut it = stdin.keys() instead of termion::async_stdin() this works well. Can someone explain me why ?

use std::io;
use std::io::{stdin, stdout, Read, Write};
use termion;
use termion::event::Key;
use termion::input::TermRead;
use termion::raw::IntoRawMode;

fn main() -> Result<(), io::Error> {
    let mut stdout = io::stdout().into_raw_mode()?;
    let mut stdin = termion::async_stdin();
    // let mut stdin = io::stdin();
    let mut it = stdin.keys();
    loop {        
        let b = it.next();
         
        if let Some(event) = b {
            match event? {
                Key::Left => println!("LEFT"),
                Key::Char('q') => break,          
                _ => {}
            }     
        }
        stdout.flush()?;
    }
    Ok(())
}
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: redox-os/termion#168