mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-03 18:20:29 +01:00
cli: show external connection in different color
This commit is contained in:
parent
16cff1149a
commit
a3528b1fe8
7 changed files with 45 additions and 21 deletions
|
|
@ -490,9 +490,7 @@ _metagen_con_show_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS)
|
|||
const char *s;
|
||||
char *s_mut;
|
||||
|
||||
NMC_HANDLE_COLOR ( ac
|
||||
? nmc_active_connection_state_to_color (nm_active_connection_get_state (ac))
|
||||
: NM_META_COLOR_CONNECTION_UNKNOWN);
|
||||
NMC_HANDLE_COLOR (nmc_active_connection_state_to_color (ac));
|
||||
|
||||
if (c)
|
||||
s_con = nm_connection_get_setting_connection (c);
|
||||
|
|
@ -1427,8 +1425,18 @@ nmc_connection_profile_details (NMConnection *connection, NmCli *nmc)
|
|||
}
|
||||
|
||||
NMMetaColor
|
||||
nmc_active_connection_state_to_color (NMActiveConnectionState state)
|
||||
nmc_active_connection_state_to_color (NMActiveConnection *ac)
|
||||
{
|
||||
NMActiveConnectionState state;
|
||||
|
||||
if (!ac)
|
||||
return NM_META_COLOR_CONNECTION_UNKNOWN;
|
||||
|
||||
if (NM_FLAGS_HAS (nm_active_connection_get_state_flags (ac), NM_ACTIVATION_STATE_FLAG_EXTERNAL))
|
||||
return NM_META_COLOR_CONNECTION_EXTERNAL;
|
||||
|
||||
state = nm_active_connection_get_state (ac);
|
||||
|
||||
if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING)
|
||||
return NM_META_COLOR_CONNECTION_ACTIVATING;
|
||||
else if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ nmc_process_connection_properties (NmCli *nmc,
|
|||
gboolean allow_remove_setting,
|
||||
GError **error);
|
||||
|
||||
NMMetaColor nmc_active_connection_state_to_color (NMActiveConnectionState state);
|
||||
NMMetaColor nmc_active_connection_state_to_color (NMActiveConnection *ac);
|
||||
|
||||
int nmc_active_connection_cmp (NMActiveConnection *ac_a, NMActiveConnection *ac_b);
|
||||
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ _metagen_device_status_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS)
|
|||
NMDevice *d = target;
|
||||
NMActiveConnection *ac;
|
||||
|
||||
NMC_HANDLE_COLOR (nmc_device_state_to_color (nm_device_get_state (d)));
|
||||
NMC_HANDLE_COLOR (nmc_device_state_to_color (d));
|
||||
|
||||
switch (info->info_type) {
|
||||
case NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_DEVICE:
|
||||
|
|
@ -1716,8 +1716,20 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
}
|
||||
|
||||
NMMetaColor
|
||||
nmc_device_state_to_color (NMDeviceState state)
|
||||
nmc_device_state_to_color (NMDevice *device)
|
||||
{
|
||||
NMDeviceState state;
|
||||
NMActiveConnection *ac;
|
||||
|
||||
if (!device)
|
||||
return NM_META_COLOR_DEVICE_UNKNOWN;
|
||||
|
||||
ac = nm_device_get_active_connection (device);
|
||||
if ( ac
|
||||
&& NM_FLAGS_HAS (nm_active_connection_get_state_flags (ac), NM_ACTIVATION_STATE_FLAG_EXTERNAL))
|
||||
return NM_META_COLOR_CONNECTION_EXTERNAL;
|
||||
|
||||
state = nm_device_get_state (device);
|
||||
if (state <= NM_DEVICE_STATE_UNAVAILABLE)
|
||||
return NM_META_COLOR_DEVICE_UNAVAILABLE;
|
||||
else if (state == NM_DEVICE_STATE_DISCONNECTED)
|
||||
|
|
@ -2612,7 +2624,7 @@ device_state (NMDevice *device, GParamSpec *pspec, NmCli *nmc)
|
|||
NMMetaColor color;
|
||||
char *str;
|
||||
|
||||
color = nmc_device_state_to_color (state);
|
||||
color = nmc_device_state_to_color (device);
|
||||
str = nmc_colorize (&nmc->nmc_config, color, "%s: %s\n",
|
||||
nm_device_get_iface (device),
|
||||
gettext (nmc_device_state_to_string (state)));
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ void monitor_devices (NmCli *nmc);
|
|||
|
||||
NMDevice ** nmc_get_devices_sorted (NMClient *client);
|
||||
|
||||
NMMetaColor nmc_device_state_to_color (NMDeviceState state);
|
||||
NMMetaColor nmc_device_state_to_color (NMDevice *device);
|
||||
|
||||
extern const NmcMetaGenericInfo *const metagen_device_status[];
|
||||
extern const NmcMetaGenericInfo *const metagen_device_detail_general[];
|
||||
|
|
|
|||
|
|
@ -1408,15 +1408,12 @@ nmc_command_func_overview (const NMCCommand *cmd, NmCli *nmc, int argc, const ch
|
|||
/* The VPN connections don't have devices (yet?). */
|
||||
p = nm_client_get_active_connections (nmc->client);
|
||||
for (i = 0; i < p->len; i++) {
|
||||
NMActiveConnectionState state;
|
||||
|
||||
ac = p->pdata[i];
|
||||
|
||||
if (!nm_active_connection_get_vpn (ac))
|
||||
continue;
|
||||
|
||||
state = nm_active_connection_get_state (ac);
|
||||
color = nmc_active_connection_state_to_color (state);
|
||||
color = nmc_active_connection_state_to_color (ac);
|
||||
tmp = nmc_colorize (&nmc->nmc_config, color, _("%s VPN connection"),
|
||||
nm_active_connection_get_id (ac));
|
||||
g_print ("%s\n", tmp);
|
||||
|
|
@ -1428,33 +1425,34 @@ nmc_command_func_overview (const NMCCommand *cmd, NmCli *nmc, int argc, const ch
|
|||
|
||||
devices = nmc_get_devices_sorted (nmc->client);
|
||||
for (i = 0; devices[i]; i++) {
|
||||
NMDevice *device = devices[i];
|
||||
NMDeviceState state;
|
||||
|
||||
ac = nm_device_get_active_connection (devices[i]);
|
||||
ac = nm_device_get_active_connection (device);
|
||||
|
||||
state = nm_device_get_state (devices[i]);
|
||||
color = nmc_device_state_to_color (state);
|
||||
state = nm_device_get_state (device);
|
||||
color = nmc_device_state_to_color (device);
|
||||
if (ac) {
|
||||
/* TRANSLATORS: prints header line for activated device in plain `nmcli` overview output as
|
||||
* "<interface-name>: <device-state> to <connection-id>" */
|
||||
tmp = nmc_colorize (&nmc->nmc_config, color, C_("nmcli-overview", "%s: %s to %s"),
|
||||
nm_device_get_iface (devices[i]),
|
||||
nm_device_get_iface (device),
|
||||
gettext (nmc_device_state_to_string (state)),
|
||||
nm_active_connection_get_id (ac));
|
||||
} else {
|
||||
/* TRANSLATORS: prints header line for not active device in plain `nmcli` overview output as
|
||||
* "<interface-name>: <device-state>" */
|
||||
tmp = nmc_colorize (&nmc->nmc_config, color, C_("nmcli-overview", "%s: %s"),
|
||||
nm_device_get_iface (devices[i]),
|
||||
nm_device_get_iface (device),
|
||||
gettext (nmc_device_state_to_string (state)));
|
||||
}
|
||||
g_print ("%s\n", tmp);
|
||||
g_free (tmp);
|
||||
|
||||
if (nm_device_get_description (devices[i]) && strcmp (nm_device_get_description (devices[i]), ""))
|
||||
g_print ("\t\"%s\"\n", nm_device_get_description (devices[i]));
|
||||
if (nm_device_get_description (device) && strcmp (nm_device_get_description (device), ""))
|
||||
g_print ("\t\"%s\"\n", nm_device_get_description (device));
|
||||
|
||||
device_overview (nmc, devices[i]);
|
||||
device_overview (nmc, device);
|
||||
if (ac)
|
||||
ac_overview (nmc, ac);
|
||||
g_print ("\n");
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
[NM_META_COLOR_CONNECTION_ACTIVATING] = "33", \
|
||||
[NM_META_COLOR_CONNECTION_DISCONNECTING] = "31", \
|
||||
[NM_META_COLOR_CONNECTION_INVISIBLE] = "2", \
|
||||
[NM_META_COLOR_CONNECTION_EXTERNAL] = "32;2", \
|
||||
[NM_META_COLOR_CONNECTIVITY_FULL] = "32", \
|
||||
[NM_META_COLOR_CONNECTIVITY_LIMITED] = "33", \
|
||||
[NM_META_COLOR_CONNECTIVITY_NONE] = "31", \
|
||||
|
|
@ -49,6 +50,7 @@
|
|||
[NM_META_COLOR_DEVICE_PLUGIN_MISSING] = "31", \
|
||||
[NM_META_COLOR_DEVICE_UNAVAILABLE] = "2", \
|
||||
[NM_META_COLOR_DEVICE_DISABLED] = "31", \
|
||||
[NM_META_COLOR_DEVICE_EXTERNAL] = "32;2", \
|
||||
[NM_META_COLOR_MANAGER_RUNNING] = "32", \
|
||||
[NM_META_COLOR_MANAGER_STARTING] = "33", \
|
||||
[NM_META_COLOR_MANAGER_STOPPED] = "31", \
|
||||
|
|
@ -550,6 +552,7 @@ parse_color_scheme (char *palette_buffer,
|
|||
[NM_META_COLOR_CONNECTION_ACTIVATING] = "connection-activating",
|
||||
[NM_META_COLOR_CONNECTION_DISCONNECTING] = "connection-disconnecting",
|
||||
[NM_META_COLOR_CONNECTION_INVISIBLE] = "connection-invisible",
|
||||
[NM_META_COLOR_CONNECTION_EXTERNAL] = "connection-external",
|
||||
[NM_META_COLOR_CONNECTION_UNKNOWN] = "connection-unknown",
|
||||
[NM_META_COLOR_CONNECTIVITY_FULL] = "connectivity-full",
|
||||
[NM_META_COLOR_CONNECTIVITY_LIMITED] = "connectivity-limited",
|
||||
|
|
@ -563,6 +566,7 @@ parse_color_scheme (char *palette_buffer,
|
|||
[NM_META_COLOR_DEVICE_PLUGIN_MISSING] = "device-plugin-missing",
|
||||
[NM_META_COLOR_DEVICE_UNAVAILABLE] = "device-unavailable",
|
||||
[NM_META_COLOR_DEVICE_DISABLED] = "device-disabled",
|
||||
[NM_META_COLOR_DEVICE_EXTERNAL] = "device-external",
|
||||
[NM_META_COLOR_DEVICE_UNKNOWN] = "device-unknown",
|
||||
[NM_META_COLOR_MANAGER_RUNNING] = "manager-running",
|
||||
[NM_META_COLOR_MANAGER_STARTING] = "manager-starting",
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ typedef enum {
|
|||
NM_META_COLOR_CONNECTION_ACTIVATING,
|
||||
NM_META_COLOR_CONNECTION_DISCONNECTING,
|
||||
NM_META_COLOR_CONNECTION_INVISIBLE,
|
||||
NM_META_COLOR_CONNECTION_EXTERNAL,
|
||||
NM_META_COLOR_CONNECTION_UNKNOWN,
|
||||
NM_META_COLOR_CONNECTIVITY_FULL,
|
||||
NM_META_COLOR_CONNECTIVITY_LIMITED,
|
||||
|
|
@ -89,6 +90,7 @@ typedef enum {
|
|||
NM_META_COLOR_DEVICE_PLUGIN_MISSING,
|
||||
NM_META_COLOR_DEVICE_UNAVAILABLE,
|
||||
NM_META_COLOR_DEVICE_DISABLED,
|
||||
NM_META_COLOR_DEVICE_EXTERNAL,
|
||||
NM_META_COLOR_DEVICE_UNKNOWN,
|
||||
NM_META_COLOR_MANAGER_RUNNING,
|
||||
NM_META_COLOR_MANAGER_STARTING,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue