SHARE
TWEET

Untitled

satya5 Jul 21st, 2017 19 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. From 50c1d6e2ebf4169ad0d3daa91cc5ce3dac02dccb Mon Sep 17 00:00:00 2001
  2. From: SATYAM KUMAR <satyamvats5@gmail.com>
  3. Date: Fri, 21 Jul 2017 03:16:56 +0530
  4. Subject: [PATCH 2/2] output: clear the screen on exit
  5.  
  6. Whenever the program terminates we clear the
  7. screen and repostion the cursor using escape
  8. sequence "\x1b[2J" and "\x1b[H" respectively.
  9.  
  10. fixes: #19(https://github.com/BytesClub/chalk/issues/19)
  11.  
  12. Signed-off-by: SATYAM KUMAR <satyamvats5@gmail.com>
  13. ---
  14.  ...put-reposition-the-cursor-to-the-top-left.patch | 31 ++++++++++++++++++++++
  15.  chalk.c                                            |  4 +++
  16.  2 files changed, 35 insertions(+)
  17.  create mode 100644 0001-output-reposition-the-cursor-to-the-top-left.patch
  18.  
  19. diff --git a/0001-output-reposition-the-cursor-to-the-top-left.patch b/0001-output-reposition-the-cursor-to-the-top-left.patch
  20. new file mode 100644
  21. index 0000000..46d1b0f
  22. --- /dev/null
  23. +++ b/0001-output-reposition-the-cursor-to-the-top-left.patch
  24. @@ -0,0 +1,31 @@
  25. +From 5bc3961faa1e6a4f66f974778979d6b58ede7c2e Mon Sep 17 00:00:00 2001
  26. +From: SATYAM KUMAR <satyamvats5@gmail.com>
  27. +Date: Fri, 21 Jul 2017 02:58:45 +0530
  28. +Subject: [PATCH] output: reposition the cursor to the top left
  29. +
  30. +Before processing the keypresses we need to position the
  31. +cursor to the top left corner of the screen, we position the
  32. +cursor using escape sequence "\x1b[H"
  33. +
  34. +fixes: #18 (https://github.com/BytesClub/chalk/issues/18)
  35. +
  36. +Signed-off-by: SATYAM KUMAR <satyamvats5@gmail.com>
  37. +---
  38. + chalk.c | 1 +
  39. + 1 file changed, 1 insertion(+)
  40. +
  41. +diff --git a/chalk.c b/chalk.c
  42. +index 2abf6bc..e73c4d2 100644
  43. +--- a/chalk.c
  44. ++++ b/chalk.c
  45. +@@ -66,6 +66,7 @@ char editorReadKey()
  46. + void editorRefreshScreen()
  47. + {
  48. +         write(STDOUT_FILENO, "\x1b[2J", 4);
  49. ++        write(STDOUT_FILENO, "\x1b[H", 3);        
  50. + }
  51. +
  52. + /* input */
  53. +--
  54. +2.7.4
  55. +
  56. diff --git a/chalk.c b/chalk.c
  57. index e73c4d2..8707c08 100644
  58. --- a/chalk.c
  59. +++ b/chalk.c
  60. @@ -20,6 +20,8 @@ struct termios orig_termios;
  61.  void die(const char *S )
  62.  {
  63.          perror(S);
  64. +        write(STDOUT_FILENO, "\x1b[2J", 4);
  65. +        write(STDOUT_FILENO,"\x1b[H", 3);
  66.          exit(1);
  67.  }
  68.  
  69. @@ -77,6 +79,8 @@ void editorProcessKeypress()
  70.  
  71.          switch(c) {
  72.                  case CTRL_KEY('q'):
  73. +                        write(STDOUT_FILENO, "\x1b[2J", 4);
  74. +                        write(STDOUT_FILENO, "\x1b[H", 3);
  75.                          exit(0);
  76.                          break;
  77.          }
  78. --
  79. 2.7.4
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top