tty-acs.c 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* $OpenBSD$ */
  2. /*
  3. * Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
  14. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  15. * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <sys/types.h>
  18. #include <stdlib.h>
  19. #include "tmux.h"
  20. int tty_acs_cmp(const void *, const void *);
  21. /* Table mapping ACS entries to UTF-8. */
  22. struct tty_acs_entry {
  23. u_char key;
  24. const char *string;
  25. };
  26. const struct tty_acs_entry tty_acs_table[] = {
  27. { '+', "\342\206\222" }, /* arrow pointing right */
  28. { ',', "\342\206\220" }, /* arrow pointing left */
  29. { '-', "\342\206\221" }, /* arrow pointing up */
  30. { '.', "\342\206\223" }, /* arrow pointing down */
  31. { '0', "\342\226\256" }, /* solid square block */
  32. { '`', "\342\227\206" }, /* diamond */
  33. { 'a', "\342\226\222" }, /* checker board (stipple) */
  34. { 'f', "\302\260" }, /* degree symbol */
  35. { 'g', "\302\261" }, /* plus/minus */
  36. { 'h', "\342\226\222" }, /* board of squares */
  37. { 'i', "\342\230\203" }, /* lantern symbol */
  38. { 'j', "\342\224\230" }, /* lower right corner */
  39. { 'k', "\342\224\220" }, /* upper right corner */
  40. { 'l', "\342\224\214" }, /* upper left corner */
  41. { 'm', "\342\224\224" }, /* lower left corner */
  42. { 'n', "\342\224\274" }, /* large plus or crossover */
  43. { 'o', "\342\216\272" }, /* scan line 1 */
  44. { 'p', "\342\216\273" }, /* scan line 3 */
  45. { 'q', "\342\224\200" }, /* horizontal line */
  46. { 'r', "\342\216\274" }, /* scan line 7 */
  47. { 's', "\342\216\275" }, /* scan line 9 */
  48. { 't', "\342\224\234" }, /* tee pointing right */
  49. { 'u', "\342\224\244" }, /* tee pointing left */
  50. { 'v', "\342\224\264" }, /* tee pointing up */
  51. { 'w', "\342\224\254" }, /* tee pointing down */
  52. { 'x', "\342\224\202" }, /* vertical line */
  53. { 'y', "\342\211\244" }, /* less-than-or-equal-to */
  54. { 'z', "\342\211\245" }, /* greater-than-or-equal-to */
  55. { '{', "\317\200" }, /* greek pi */
  56. { '|', "\342\211\240" }, /* not-equal */
  57. { '}', "\302\243" }, /* UK pound sign */
  58. { '~', "\302\267" } /* bullet */
  59. };
  60. int
  61. tty_acs_cmp(const void *key, const void *value)
  62. {
  63. const struct tty_acs_entry *entry = value;
  64. u_char ch;
  65. ch = *(u_char *) key;
  66. return (ch - entry->key);
  67. }
  68. /* Retrieve ACS to output as a string. */
  69. const char *
  70. tty_acs_get(struct tty *tty, u_char ch)
  71. {
  72. struct tty_acs_entry *entry;
  73. /* If not a UTF-8 terminal, use the ACS set. */
  74. if (tty != NULL && !(tty->flags & TTY_UTF8)) {
  75. if (tty->term->acs[ch][0] == '\0')
  76. return (NULL);
  77. return (&tty->term->acs[ch][0]);
  78. }
  79. /* Otherwise look up the UTF-8 translation. */
  80. entry = bsearch(&ch,
  81. tty_acs_table, nitems(tty_acs_table), sizeof tty_acs_table[0],
  82. tty_acs_cmp);
  83. if (entry == NULL)
  84. return (NULL);
  85. return (entry->string);
  86. }