From e152ec7bf4ba252ff9d3eb13eabd417b931dac9a Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Mon, 24 Sep 2018 09:29:55 +0100 Subject: Import Upstream version 1.12.2 --- clients/cli/utils.h | 116 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 96 insertions(+), 20 deletions(-) (limited to 'clients/cli/utils.h') diff --git a/clients/cli/utils.h b/clients/cli/utils.h index ffc5b6f3..19694d11 100644 --- a/clients/cli/utils.h +++ b/clients/cli/utils.h @@ -14,7 +14,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright 2010 - 2017 Red Hat, Inc. + * Copyright 2010 - 2018 Red Hat, Inc. */ #ifndef NMC_UTILS_H @@ -41,11 +41,7 @@ char *ssid_to_hex (const char *str, gsize len); void nmc_terminal_erase_line (void); void nmc_terminal_show_progress (const char *str); void nmc_terminal_spawn_pager (const NmcConfig *nmc_config); -gboolean nmc_term_use_colors (NmcColorOption color_option); -const char *nmc_term_color_sequence (NMMetaTermColor color); -const char *nmc_term_format_sequence (NMMetaTermFormat format); -NMMetaTermColor nmc_term_color_parse_string (const char *str, GError **error); -char *nmc_colorize (NmcColorOption color_option, NMMetaTermColor color, NMMetaTermFormat format, const char * fmt, ...) _nm_printf (4, 5); +char *nmc_colorize (const NmcConfig *nmc_config, NMMetaColor color, const char * fmt, ...) _nm_printf (3, 4); void nmc_filter_out_colors_inplace (char *str); char *nmc_filter_out_colors (const char *str); char *nmc_get_user_input (const char *ask_str); @@ -53,14 +49,12 @@ int nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquo char ***argv, int *argc); const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error); char * nmc_util_strv_for_display (const char *const*strv, gboolean brackets); -char **nmc_strsplit_set (const char *str, const char *delimiter, int max_tokens); int nmc_string_screen_width (const char *start, const char *end); void set_val_str (NmcOutputField fields_array[], guint32 index, char *value); void set_val_strc (NmcOutputField fields_array[], guint32 index, const char *value); void set_val_arr (NmcOutputField fields_array[], guint32 index, char **value); void set_val_arrc (NmcOutputField fields_array[], guint32 index, const char **value); -void set_val_color_all (NmcOutputField fields_array[], NMMetaTermColor color); -void set_val_color_fmt_all (NmcOutputField fields_array[], NMMetaTermFormat format); +void set_val_color_all (NmcOutputField fields_array[], NMMetaColor color); void nmc_free_output_field_values (NmcOutputField fields_array[]); GArray *parse_output_fields (const char *fields_str, @@ -127,12 +121,43 @@ typedef enum { NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DOMAIN, _NMC_GENERIC_INFO_TYPE_IP6_CONFIG_NUM, + NMC_GENERIC_INFO_TYPE_CON_SHOW_NAME = 0, + NMC_GENERIC_INFO_TYPE_CON_SHOW_UUID, + NMC_GENERIC_INFO_TYPE_CON_SHOW_TYPE, + NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP, + NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP_REAL, + NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT, + NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT_PRIORITY, + NMC_GENERIC_INFO_TYPE_CON_SHOW_READONLY, + NMC_GENERIC_INFO_TYPE_CON_SHOW_DBUS_PATH, + NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE, + NMC_GENERIC_INFO_TYPE_CON_SHOW_DEVICE, + NMC_GENERIC_INFO_TYPE_CON_SHOW_STATE, + NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE_PATH, + NMC_GENERIC_INFO_TYPE_CON_SHOW_SLAVE, + NMC_GENERIC_INFO_TYPE_CON_SHOW_FILENAME, + _NMC_GENERIC_INFO_TYPE_CON_SHOW_NUM, + + NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NAME = 0, + NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_UUID, + NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEVICES, + NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_STATE, + NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT, + NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT6, + NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_SPEC_OBJECT, + NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_VPN, + NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DBUS_PATH, + NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_CON_PATH, + NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_ZONE, + NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_MASTER_PATH, + _NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NUM, + } NmcGenericInfoType; -#define NMC_HANDLE_TERMFORMAT(color) \ +#define NMC_HANDLE_COLOR(color) \ G_STMT_START { \ - if (get_type == NM_META_ACCESSOR_GET_TYPE_TERMFORMAT) \ - return nm_meta_termformat_pack ((color), NM_META_TERM_FORMAT_NORMAL); \ + if (get_type == NM_META_ACCESSOR_GET_TYPE_COLOR) \ + return GINT_TO_POINTER (color); \ } G_STMT_END struct _NmcMetaGenericInfo { @@ -144,14 +169,19 @@ struct _NmcMetaGenericInfo { const char *name; const char *name_header; const NmcMetaGenericInfo *const*nested; - gconstpointer (*get_fcn) (const NMMetaEnvironment *environment, - gpointer environment_user_data, - const NmcMetaGenericInfo *info, - gpointer target, - NMMetaAccessorGetType get_type, - NMMetaAccessorGetFlags get_flags, - NMMetaAccessorGetOutFlags *out_flags, - gpointer *out_to_free); + +#define NMC_META_GENERIC_INFO_GET_FCN_ARGS \ + const NMMetaEnvironment *environment, \ + gpointer environment_user_data, \ + const NmcMetaGenericInfo *info, \ + gpointer target, \ + NMMetaAccessorGetType get_type, \ + NMMetaAccessorGetFlags get_flags, \ + NMMetaAccessorGetOutFlags *out_flags, \ + gboolean *out_is_default, \ + gpointer *out_to_free + + gconstpointer (*get_fcn) (NMC_META_GENERIC_INFO_GET_FCN_ARGS); }; #define NMC_META_GENERIC(n, ...) \ @@ -164,6 +194,52 @@ struct _NmcMetaGenericInfo { #define NMC_META_GENERIC_WITH_NESTED(n, nest, ...) \ NMC_META_GENERIC (n, .nested = (nest), __VA_ARGS__) +#define NMC_META_GENERIC_GROUP(_group_name, _nested, _name_header) \ + ((const NMMetaAbstractInfo *const*) ((const NmcMetaGenericInfo *const[]) { \ + NMC_META_GENERIC_WITH_NESTED (_group_name,_nested, .name_header = _name_header), \ + NULL, \ + })) + +static inline const char * +nmc_meta_generic_get_str_i18n (const char *s, NMMetaAccessorGetType get_type) +{ + if (!NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, + NM_META_ACCESSOR_GET_TYPE_PARSABLE)) + g_return_val_if_reached (NULL); + + if (!s) + return NULL; + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) + return gettext (s); + return s; +} + +static inline const char * +nmc_meta_generic_get_bool (gboolean val, NMMetaAccessorGetType get_type) +{ + return nmc_meta_generic_get_str_i18n (val ? N_("yes") : N_("no"), get_type); +} + +static inline char * +nmc_meta_generic_get_enum_with_detail (gint64 enum_val, const char *str_val, NMMetaAccessorGetType get_type) +{ + if (!NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, + NM_META_ACCESSOR_GET_TYPE_PARSABLE)) + g_return_val_if_reached (NULL); + + if (!str_val) { + /* Pass %NULL for only printing the numeric value. */ + return g_strdup_printf ("%lld", (long long) enum_val); + } + + /* note that this function will always print "$NUM ($NICK)", also in PARSABLE + * mode. That might not be desired, but it's done for certain properties to preserve + * previous behavior. */ + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) + return g_strdup_printf (_("%lld (%s)"), (long long) enum_val, gettext (str_val)); + return g_strdup_printf ("%lld (%s)", (long long) enum_val, str_val); +} + /*****************************************************************************/ gboolean nmc_print (const NmcConfig *nmc_config, -- cgit 1.3.0-6-gf8a5