display.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* SPDX-License-Identifier: LGPL-2.1-or-later */
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2011-2014 Intel Corporation
  7. * Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org>
  8. *
  9. *
  10. */
  11. #include <stdbool.h>
  12. #include <inttypes.h>
  13. bool use_color(void);
  14. enum monitor_color { COLOR_AUTO, COLOR_ALWAYS, COLOR_NEVER };
  15. void set_monitor_color(enum monitor_color);
  16. #define COLOR_OFF "\x1B[0m"
  17. #define COLOR_BLACK "\x1B[0;30m"
  18. #define COLOR_RED "\x1B[0;31m"
  19. #define COLOR_GREEN "\x1B[0;32m"
  20. #define COLOR_YELLOW "\x1B[0;33m"
  21. #define COLOR_BLUE "\x1B[0;34m"
  22. #define COLOR_MAGENTA "\x1B[0;35m"
  23. #define COLOR_CYAN "\x1B[0;36m"
  24. #define COLOR_WHITE "\x1B[0;37m"
  25. #define COLOR_WHITE_BG "\x1B[0;47;30m"
  26. #define COLOR_HIGHLIGHT "\x1B[1;39m"
  27. #define COLOR_RED_BOLD "\x1B[1;31m"
  28. #define COLOR_GREEN_BOLD "\x1B[1;32m"
  29. #define COLOR_BLUE_BOLD "\x1B[1;34m"
  30. #define COLOR_MAGENTA_BOLD "\x1B[1;35m"
  31. #define COLOR_ERROR "\x1B[1;31m"
  32. #define COLOR_WARN "\x1B[1m"
  33. #define COLOR_INFO COLOR_OFF
  34. #define COLOR_DEBUG COLOR_WHITE
  35. #define FALLBACK_TERMINAL_WIDTH 80
  36. #define print_indent(indent, color1, prefix, title, color2, fmt, args...) \
  37. do { \
  38. printf("%*c%s%s%s%s" fmt "%s\n", (indent), ' ', \
  39. use_color() ? (color1) : "", prefix, title, \
  40. use_color() ? (color2) : "", ## args, \
  41. use_color() ? COLOR_OFF : ""); \
  42. } while (0)
  43. #define print_text(color, fmt, args...) \
  44. print_indent(8, COLOR_OFF, "", "", color, fmt, ## args)
  45. #define print_field(fmt, args...) \
  46. print_indent(8, COLOR_OFF, "", "", COLOR_OFF, fmt, ## args)
  47. struct bitfield_data {
  48. uint64_t bit;
  49. const char *str;
  50. };
  51. static inline uint64_t print_bitfield(int indent, uint64_t val,
  52. const struct bitfield_data *table)
  53. {
  54. uint64_t mask = val;
  55. int i;
  56. for (i = 0; table[i].str; i++) {
  57. if (val & (((uint64_t) 1) << table[i].bit)) {
  58. print_field("%*c%s", indent, ' ', table[i].str);
  59. mask &= ~(((uint64_t) 1) << table[i].bit);
  60. }
  61. }
  62. return mask;
  63. }
  64. void set_default_pager_num_columns(int num_columns);
  65. int num_columns(void);
  66. void open_pager(void);
  67. void close_pager(void);