Blame monitor/display.h

Packit 34410b
/*
Packit 34410b
 *
Packit 34410b
 *  BlueZ - Bluetooth protocol stack for Linux
Packit 34410b
 *
Packit 34410b
 *  Copyright (C) 2011-2014  Intel Corporation
Packit 34410b
 *  Copyright (C) 2002-2010  Marcel Holtmann <marcel@holtmann.org>
Packit 34410b
 *
Packit 34410b
 *
Packit 34410b
 *  This library is free software; you can redistribute it and/or
Packit 34410b
 *  modify it under the terms of the GNU Lesser General Public
Packit 34410b
 *  License as published by the Free Software Foundation; either
Packit 34410b
 *  version 2.1 of the License, or (at your option) any later version.
Packit 34410b
 *
Packit 34410b
 *  This library is distributed in the hope that it will be useful,
Packit 34410b
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 34410b
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 34410b
 *  Lesser General Public License for more details.
Packit 34410b
 *
Packit 34410b
 *  You should have received a copy of the GNU Lesser General Public
Packit 34410b
 *  License along with this library; if not, write to the Free Software
Packit 34410b
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
Packit 34410b
 *
Packit 34410b
 */
Packit 34410b
Packit 34410b
#include <stdbool.h>
Packit 34410b
#include <inttypes.h>
Packit 34410b
Packit 34410b
bool use_color(void);
Packit 34410b
Packit 34410b
#define COLOR_OFF	"\x1B[0m"
Packit 34410b
#define COLOR_BLACK	"\x1B[0;30m"
Packit 34410b
#define COLOR_RED	"\x1B[0;31m"
Packit 34410b
#define COLOR_GREEN	"\x1B[0;32m"
Packit 34410b
#define COLOR_YELLOW	"\x1B[0;33m"
Packit 34410b
#define COLOR_BLUE	"\x1B[0;34m"
Packit 34410b
#define COLOR_MAGENTA	"\x1B[0;35m"
Packit 34410b
#define COLOR_CYAN	"\x1B[0;36m"
Packit 34410b
#define COLOR_WHITE	"\x1B[0;37m"
Packit 34410b
#define COLOR_WHITE_BG	"\x1B[0;47;30m"
Packit 34410b
#define COLOR_HIGHLIGHT	"\x1B[1;39m"
Packit 34410b
Packit 34410b
#define COLOR_RED_BOLD		"\x1B[1;31m"
Packit 34410b
#define COLOR_GREEN_BOLD	"\x1B[1;32m"
Packit 34410b
#define COLOR_BLUE_BOLD		"\x1B[1;34m"
Packit 34410b
#define COLOR_MAGENTA_BOLD	"\x1B[1;35m"
Packit 34410b
Packit 34410b
#define COLOR_ERROR	"\x1B[1;31m"
Packit 34410b
#define COLOR_WARN	"\x1B[1m"
Packit 34410b
#define COLOR_INFO	COLOR_OFF
Packit 34410b
#define COLOR_DEBUG	COLOR_WHITE
Packit 34410b
Packit 34410b
#define FALLBACK_TERMINAL_WIDTH 80
Packit 34410b
Packit 34410b
#define print_indent(indent, color1, prefix, title, color2, fmt, args...) \
Packit 34410b
do { \
Packit 34410b
	printf("%*c%s%s%s%s" fmt "%s\n", (indent), ' ', \
Packit 34410b
		use_color() ? (color1) : "", prefix, title, \
Packit 34410b
		use_color() ? (color2) : "", ## args, \
Packit 34410b
		use_color() ? COLOR_OFF : ""); \
Packit 34410b
} while (0)
Packit 34410b
Packit 34410b
#define print_text(color, fmt, args...) \
Packit 34410b
		print_indent(8, COLOR_OFF, "", "", color, fmt, ## args)
Packit 34410b
Packit 34410b
#define print_field(fmt, args...) \
Packit 34410b
		print_indent(8, COLOR_OFF, "", "", COLOR_OFF, fmt, ## args)
Packit 34410b
Packit 34410b
struct bitfield_data {
Packit 34410b
	uint64_t bit;
Packit 34410b
	const char *str;
Packit 34410b
};
Packit 34410b
Packit 34410b
static inline uint64_t print_bitfield(int indent, uint64_t val,
Packit 34410b
					const struct bitfield_data *table)
Packit 34410b
{
Packit 34410b
	uint64_t mask = val;
Packit 34410b
	int i;
Packit 34410b
Packit 34410b
	for (i = 0; table[i].str; i++) {
Packit 34410b
		if (val & (((uint64_t) 1) << table[i].bit)) {
Packit 34410b
			print_field("%*c%s", indent, ' ', table[i].str);
Packit 34410b
			mask &= ~(((uint64_t) 1) << table[i].bit);
Packit 34410b
		}
Packit 34410b
	}
Packit 34410b
Packit 34410b
	return mask;
Packit 34410b
}
Packit 34410b
Packit 34410b
int num_columns(void);
Packit 34410b
Packit 34410b
void open_pager(void);
Packit 34410b
void close_pager(void);