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

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