Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #include <curses.h>
  2. #include "mucurses.h"
  3. /** @file
  4. *
  5. * MuCurses core functions
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. static void _wupdcurs ( WINDOW *win ) __nonnull;
  10. void _wputch ( WINDOW *win, chtype ch, int wrap ) __nonnull;
  11. void _wputc ( WINDOW *win, char c, int wrap ) __nonnull;
  12. void _wcursback ( WINDOW *win ) __nonnull;
  13. void _wputchstr ( WINDOW *win, const chtype *chstr, int wrap, int n ) __nonnull;
  14. void _wputstr ( WINDOW *win, const char *str, int wrap, int n ) __nonnull;
  15. int wmove ( WINDOW *win, int y, int x ) __nonnull;
  16. WINDOW _stdscr = {
  17. .attrs = A_DEFAULT,
  18. .ori_y = 0,
  19. .ori_x = 0,
  20. .curs_y = 0,
  21. .curs_x = 0,
  22. .scr = &_ansi_screen,
  23. };
  24. /*
  25. * Primitives
  26. */
  27. /**
  28. * Update cursor position
  29. *
  30. * @v *win window in which to update position
  31. */
  32. static void _wupdcurs ( WINDOW *win ) {
  33. win->scr->movetoyx ( win->scr, win->ori_y + win->curs_y,
  34. win->ori_x + win->curs_x );
  35. }
  36. /**
  37. * Write a single character rendition to a window
  38. *
  39. * @v *win window in which to write
  40. * @v ch character rendition to write
  41. * @v wrap wrap "switch"
  42. */
  43. void _wputch ( WINDOW *win, chtype ch, int wrap ) {
  44. /* make sure we set the screen cursor to the right position
  45. first! */
  46. _wupdcurs(win);
  47. win->scr->putc(win->scr, ch);
  48. if ( ++(win->curs_x) - win->width == 0 ) {
  49. if ( wrap == WRAP ) {
  50. win->curs_x = 0;
  51. /* specification says we should really scroll,
  52. but we have no buffer to scroll with, so we
  53. can only overwrite back at the beginning of
  54. the window */
  55. if ( ++(win->curs_y) - win->height == 0 )
  56. win->curs_y = 0;
  57. } else {
  58. (win->curs_x)--;
  59. }
  60. }
  61. }
  62. /**
  63. * Write a single character to a window
  64. *
  65. * @v *win window in which to write
  66. * @v c character rendition to write
  67. * @v wrap wrap "switch"
  68. */
  69. void _wputc ( WINDOW *win, char c, int wrap ) {
  70. _wputch ( win, ( ( ( unsigned char ) c ) | win->attrs ), wrap );
  71. }
  72. /**
  73. * Retreat the cursor back one position (useful for a whole host of
  74. * ops)
  75. *
  76. * @v *win window in which to retreat
  77. */
  78. void _wcursback ( WINDOW *win ) {
  79. if ( win->curs_x == 0 ) {
  80. if ( win->curs_y == 0 )
  81. win->curs_y = win->height - 1;
  82. win->curs_x = win->width = 1;
  83. } else {
  84. win->curs_x--;
  85. }
  86. _wupdcurs(win);
  87. }
  88. /**
  89. * Write a chtype string to a window
  90. *
  91. * @v *win window in which to write
  92. * @v *chstr chtype string
  93. * @v wrap wrap "switch"
  94. * @v n write at most n chtypes
  95. */
  96. void _wputchstr ( WINDOW *win, const chtype *chstr, int wrap, int n ) {
  97. for ( ; *chstr && n-- ; chstr++ ) {
  98. _wputch(win,*chstr,wrap);
  99. }
  100. }
  101. /**
  102. * Write a standard c-style string to a window
  103. *
  104. * @v *win window in which to write
  105. * @v *str string
  106. * @v wrap wrap "switch"
  107. * @v n write at most n chars from *str
  108. */
  109. void _wputstr ( WINDOW *win, const char *str, int wrap, int n ) {
  110. for ( ; *str && n-- ; str++ ) {
  111. _wputc ( win, *str, wrap );
  112. }
  113. }
  114. /**
  115. * Move a window's cursor to the specified position
  116. *
  117. * @v *win window to be operated on
  118. * @v y Y position
  119. * @v x X position
  120. * @ret rc return status code
  121. */
  122. int wmove ( WINDOW *win, int y, int x ) {
  123. /* chech for out-of-bounds errors */
  124. if ( ( (unsigned)y >= win->height ) ||
  125. ( (unsigned)x >= win->width ) ) {
  126. return ERR;
  127. }
  128. win->curs_y = y;
  129. win->curs_x = x;
  130. _wupdcurs(win);
  131. return OK;
  132. }
  133. /**
  134. * Set cursor visibility
  135. *
  136. * @v visibility cursor visibility
  137. */
  138. int curs_set ( int visibility ) {
  139. stdscr->scr->cursor ( stdscr->scr, visibility );
  140. return OK;
  141. }