device: Set disconnect timer to zero for fast disconnection
[platform/upstream/bluez.git] / monitor / display.h
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
12 #include <stdbool.h>
13 #include <inttypes.h>
14
15 bool use_color(void);
16
17 enum monitor_color { COLOR_AUTO, COLOR_ALWAYS, COLOR_NEVER };
18 void set_monitor_color(enum monitor_color);
19
20 #define COLOR_OFF       "\x1B[0m"
21 #define COLOR_BLACK     "\x1B[0;30m"
22 #define COLOR_RED       "\x1B[0;31m"
23 #define COLOR_GREEN     "\x1B[0;32m"
24 #define COLOR_YELLOW    "\x1B[0;33m"
25 #define COLOR_BLUE      "\x1B[0;34m"
26 #define COLOR_MAGENTA   "\x1B[0;35m"
27 #define COLOR_CYAN      "\x1B[0;36m"
28 #define COLOR_WHITE     "\x1B[0;37m"
29 #define COLOR_WHITE_BG  "\x1B[0;47;30m"
30 #define COLOR_HIGHLIGHT "\x1B[1;39m"
31
32 #define COLOR_RED_BOLD          "\x1B[1;31m"
33 #define COLOR_GREEN_BOLD        "\x1B[1;32m"
34 #define COLOR_BLUE_BOLD         "\x1B[1;34m"
35 #define COLOR_MAGENTA_BOLD      "\x1B[1;35m"
36
37 #define COLOR_ERROR     "\x1B[1;31m"
38 #define COLOR_WARN      "\x1B[1m"
39 #define COLOR_INFO      COLOR_OFF
40 #define COLOR_DEBUG     COLOR_WHITE
41
42 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
43 #define FALLBACK_TERMINAL_WIDTH 130
44 #else
45 #define FALLBACK_TERMINAL_WIDTH 80
46 #endif
47
48 #define print_indent(indent, color1, prefix, title, color2, fmt, args...) \
49 do { \
50         printf("%*c%s%s%s%s" fmt "%s\n", (indent), ' ', \
51                 use_color() ? (color1) : "", prefix, title, \
52                 use_color() ? (color2) : "", ## args, \
53                 use_color() ? COLOR_OFF : ""); \
54 } while (0)
55
56 #define print_text(color, fmt, args...) \
57                 print_indent(8, COLOR_OFF, "", "", color, fmt, ## args)
58
59 #define print_field(fmt, args...) \
60                 print_indent(8, COLOR_OFF, "", "", COLOR_OFF, fmt, ## args)
61
62 struct bitfield_data {
63         uint64_t bit;
64         const char *str;
65 };
66
67 static inline uint64_t print_bitfield(int indent, uint64_t val,
68                                         const struct bitfield_data *table)
69 {
70         uint64_t mask = val;
71         int i;
72
73         for (i = 0; table[i].str; i++) {
74                 if (val & (((uint64_t) 1) << table[i].bit)) {
75                         print_field("%*c%s", indent, ' ', table[i].str);
76                         mask &= ~(((uint64_t) 1) << table[i].bit);
77                 }
78         }
79
80         return mask;
81 }
82
83 static inline void print_hex_field(const char *label, const uint8_t *data,
84                                                                 uint8_t len)
85 {
86         char str[len * 2 + 1];
87         uint8_t i;
88
89         str[0] = '\0';
90
91         for (i = 0; i < len; i++)
92                 sprintf(str + (i * 2), "%2.2x", data[i]);
93
94         print_field("%s: %s", label, str);
95 }
96
97 #ifndef TIZEN_FEATURE_BLUEZ_MODIFY
98 void set_default_pager_num_columns(int num_columns);
99 #endif
100 int num_columns(void);
101
102 void open_pager(void);
103 void close_pager(void);