Skip to content
  • Thomas Rast's avatar
    add -i: ignore terminal escape sequences · b5cc0032
    Thomas Rast authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    On the author's terminal, the up-arrow input sequence is ^[[A, and
    thus fat-fingering an up-arrow into 'git checkout -p' is quite
    dangerous: git-add--interactive.perl will ignore the ^[ and [
    characters and happily treat A as "discard everything".
    
    As a band-aid fix, use Term::Cap to get all terminal capabilities.
    Then use the heuristic that any capability value that starts with ^[
    (i.e., \e in perl) must be a key input sequence.  Finally, given an
    input that starts with ^[, read more characters until we have read a
    full escape sequence, then return that to the caller.  We use a
    timeout of 0.5 seconds on the subsequent reads to avoid getting stuck
    if the user actually input a lone ^[.
    
    Since none of the currently recognized keys start with ^[, the net
    result is that the sequence as a whole will be ignored and the help
    displayed.
    
    Signed-off-by: default avatarThomas Rast <trast@student.ethz.ch>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    b5cc0032