From fc7ae83f91cc99b24143880293ca757f4024a62d Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 18 Dec 2012 04:17:45 +0100 Subject: [PATCH] client: Add helper function for readline async printing --- Makefile.tools | 4 ++-- client/display.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ client/display.h | 2 ++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 client/display.c diff --git a/Makefile.tools b/Makefile.tools index 720a2c1bd..0d782a6b5 100644 --- a/Makefile.tools +++ b/Makefile.tools @@ -2,8 +2,8 @@ if CLIENT bin_PROGRAMS += client/bluetoothctl -client_bluetoothctl_SOURCES = $(gdbus_sources) \ - client/main.c client/display.h \ +client_bluetoothctl_SOURCES = $(gdbus_sources) client/main.c \ + client/display.h client/display.c \ client/agent.h client/agent.c client_bluetoothctl_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ -lreadline endif diff --git a/client/display.c b/client/display.c new file mode 100644 index 000000000..197049d64 --- /dev/null +++ b/client/display.c @@ -0,0 +1,57 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2012 Intel Corporation. All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "display.h" + +void rl_printf(const char *fmt, ...) +{ + va_list args; + char *saved_line; + int saved_point; + + saved_point = rl_point; + saved_line = rl_copy_text(0, rl_end); + rl_save_prompt(); + rl_replace_line("", 0); + rl_redisplay(); + + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); + + rl_restore_prompt(); + rl_replace_line(saved_line, 0); + rl_point = saved_point; + rl_redisplay(); + free(saved_line); +} diff --git a/client/display.h b/client/display.h index 7abefa45c..ae43d0fc1 100644 --- a/client/display.h +++ b/client/display.h @@ -34,3 +34,5 @@ static inline void end_message(void) { rl_clear_message(); } + +void rl_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); -- 2.47.3