You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

clear.c 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <curses.h>
  2. #include "mucurses.h"
  3. #include "cursor.h"
  4. /** @file
  5. *
  6. * MuCurses clearing functions
  7. *
  8. */
  9. FILE_LICENCE ( GPL2_OR_LATER );
  10. /**
  11. * Clear a window to the bottom from current cursor position
  12. *
  13. * @v *win subject window
  14. * @ret rc return status code
  15. */
  16. int wclrtobot ( WINDOW *win ) {
  17. struct cursor_pos pos;
  18. _store_curs_pos( win, &pos );
  19. do {
  20. _wputc( win, ' ', WRAP );
  21. } while ( win->curs_y + win->curs_x );
  22. _restore_curs_pos( win, &pos );
  23. return OK;
  24. }
  25. /**
  26. * Clear a window to the end of the current line
  27. *
  28. * @v *win subject window
  29. * @ret rc return status code
  30. */
  31. int wclrtoeol ( WINDOW *win ) {
  32. struct cursor_pos pos;
  33. _store_curs_pos( win, &pos );
  34. while ( ( win->curs_y - pos.y ) == 0 ) {
  35. _wputc( win, ' ', WRAP );
  36. }
  37. _restore_curs_pos( win, &pos );
  38. return OK;
  39. }
  40. /**
  41. * Delete character under the cursor in a window
  42. *
  43. * @v *win subject window
  44. * @ret rc return status code
  45. */
  46. int wdelch ( WINDOW *win ) {
  47. _wputc( win, ' ', NOWRAP );
  48. _wcursback( win );
  49. return OK;
  50. }
  51. /**
  52. * Delete line under a window's cursor
  53. *
  54. * @v *win subject window
  55. * @ret rc return status code
  56. */
  57. int wdeleteln ( WINDOW *win ) {
  58. struct cursor_pos pos;
  59. _store_curs_pos( win, &pos );
  60. /* let's just set the cursor to the beginning of the line and
  61. let wclrtoeol do the work :) */
  62. wmove( win, win->curs_y, 0 );
  63. wclrtoeol( win );
  64. _restore_curs_pos( win, &pos );
  65. return OK;
  66. }
  67. /**
  68. * Completely clear a window
  69. *
  70. * @v *win subject window
  71. * @ret rc return status code
  72. */
  73. int werase ( WINDOW *win ) {
  74. wmove( win, 0, 0 );
  75. wclrtobot( win );
  76. return OK;
  77. }