nxterm_putc.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /****************************************************************************
  2. * graphics/nxterm/nxterm_putc.c
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /****************************************************************************
  21. * Included Files
  22. ****************************************************************************/
  23. #include <nuttx/config.h>
  24. #include <nuttx/ascii.h>
  25. #include "nxterm.h"
  26. /****************************************************************************
  27. * Private Functions
  28. ****************************************************************************/
  29. /****************************************************************************
  30. * Public Functions
  31. ****************************************************************************/
  32. /****************************************************************************
  33. * Name: nxterm_putc
  34. *
  35. * Description:
  36. * Render the specified character at the current display position.
  37. *
  38. ****************************************************************************/
  39. void nxterm_putc(FAR struct nxterm_state_s *priv, uint8_t ch)
  40. {
  41. FAR const struct nxterm_bitmap_s *bm;
  42. int lineheight;
  43. /* Ignore carriage returns */
  44. if (ch == '\r')
  45. {
  46. return;
  47. }
  48. /* Handle backspace (treating both BS and DEL as backspace) */
  49. if (ch == ASCII_BS || ch == ASCII_DEL)
  50. {
  51. nxterm_backspace(priv);
  52. return;
  53. }
  54. /* Will another character fit on this line? */
  55. if (priv->fpos.x + priv->fwidth > priv->wndo.wsize.w)
  56. {
  57. #ifndef CONFIG_NXTERM_NOWRAP
  58. /* No.. move to the next line */
  59. nxterm_newline(priv);
  60. /* If we were about to output a newline character, then don't */
  61. if (ch == '\n')
  62. {
  63. return;
  64. }
  65. #else
  66. /* No.. Ignore all further characters until a newline is encountered */
  67. if (ch != '\n')
  68. {
  69. return;
  70. }
  71. #endif
  72. }
  73. /* If it is a newline character, then just perform the logical newline
  74. * operation.
  75. */
  76. if (ch == '\n')
  77. {
  78. nxterm_newline(priv);
  79. return;
  80. }
  81. /* Check if we need to scroll up */
  82. lineheight = (priv->fheight + CONFIG_NXTERM_LINESEPARATION);
  83. while (priv->fpos.y >= priv->wndo.wsize.h - lineheight)
  84. {
  85. nxterm_scroll(priv, lineheight);
  86. }
  87. /* Find the glyph associated with the character and render it onto the
  88. * display.
  89. */
  90. bm = nxterm_addchar(priv, ch);
  91. if (bm)
  92. {
  93. nxterm_fillchar(priv, NULL, bm);
  94. }
  95. }
  96. /****************************************************************************
  97. * Name: nxterm_showcursor
  98. *
  99. * Description:
  100. * Render the cursor character at the current display position.
  101. *
  102. ****************************************************************************/
  103. void nxterm_showcursor(FAR struct nxterm_state_s *priv)
  104. {
  105. int lineheight;
  106. /* Will another character fit on this line? */
  107. if (priv->fpos.x + priv->fwidth > priv->wndo.wsize.w)
  108. {
  109. #ifndef CONFIG_NXTERM_NOWRAP
  110. /* No.. move to the next line */
  111. nxterm_newline(priv);
  112. #else
  113. return;
  114. #endif
  115. }
  116. /* Check if we need to scroll up */
  117. lineheight = (priv->fheight + CONFIG_NXTERM_LINESEPARATION);
  118. while (priv->fpos.y >= priv->wndo.wsize.h - lineheight)
  119. {
  120. nxterm_scroll(priv, lineheight);
  121. }
  122. /* Render the cursor glyph onto the display. */
  123. priv->cursor.pos.x = priv->fpos.x;
  124. priv->cursor.pos.y = priv->fpos.y;
  125. nxterm_fillchar(priv, NULL, &priv->cursor);
  126. }
  127. /****************************************************************************
  128. * Name: nxterm_hidecursor
  129. *
  130. * Description:
  131. * Render the cursor cursor character from the display.
  132. *
  133. ****************************************************************************/
  134. void nxterm_hidecursor(FAR struct nxterm_state_s *priv)
  135. {
  136. nxterm_hidechar(priv, &priv->cursor);
  137. }