Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. When using Curses, I can't echo back a character I've read in using `getchar`.
  2.  
  3. ```perl
  4. #!/usr/bin/perl
  5.  
  6. use warnings;
  7. use strict;
  8.  
  9. use utf8;
  10. use open qw( :std :encoding(UTF-8) );
  11.  
  12. use Curses;
  13.  
  14. sub setup {
  15. initscr();
  16. raw();
  17. keypad(1);
  18. noecho();
  19. }
  20.  
  21. sub teardown {
  22. endwin();
  23. }
  24.  
  25. {
  26. setup();
  27.  
  28. printw("Press any key to echo it...");
  29. my ($ch, $key) = getchar();
  30. printw("\n");
  31. printw("Got: %s\n", $ch) if defined($ch);
  32.  
  33. printw("Press any key to exit...");
  34. getchar();
  35.  
  36. endwin();
  37. }
  38. ```
  39.  
  40. Try pasting each of `q`, `è` and `д`. The character is correctly output for only the first and third of these:
  41.  
  42. ```lang-none
  43. Press any key to echo it...
  44. Got: q
  45. Press any key to exit...
  46. ```
  47.  
  48. ```lang-none
  49. Press any key to echo it...
  50. Got:
  51. Press any key to exit...
  52. ```
  53.  
  54. ```lang-none
  55. Press any key to echo it...
  56. Got: д
  57. Press any key to exit...
  58. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement