diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2016-07-01 21:44:47 +0200 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2016-07-19 14:29:05 +0200 |
commit | 65c6eb5ce5d8928ff4a0fd4dd1ed82a65ea66a6f (patch) | |
tree | 9ef954039b393fa3b63dd86499dc1718fc555661 /clients | |
parent | 39930396cdfa92101e8218828d19def02a143872 (diff) | |
download | NetworkManager-65c6eb5ce5d8928ff4a0fd4dd1ed82a65ea66a6f.tar.gz |
cli/connections: split out ac_state_to_color()
Going to be useful outside nmcli c.
Diffstat (limited to 'clients')
-rw-r--r-- | clients/cli/connections.c | 27 | ||||
-rw-r--r-- | clients/cli/connections.h | 1 |
2 files changed, 19 insertions, 9 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c index cedbb7c4ed..09f0c00c32 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -914,6 +914,19 @@ find_active_connection (const GPtrArray *active_cons, return found; } +void +nmc_active_connection_state_to_color (NMActiveConnectionState state, NmcTermColor *color) +{ + *color = NMC_TERM_COLOR_NORMAL; + + if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) + *color = NMC_TERM_COLOR_YELLOW; + else if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) + *color = NMC_TERM_COLOR_GREEN; + else if (state > NM_ACTIVE_CONNECTION_STATE_ACTIVATED) + *color = NMC_TERM_COLOR_RED; +} + static void fill_output_connection (NMConnection *connection, NmCli *nmc, gboolean active_only) { @@ -929,6 +942,7 @@ fill_output_connection (NMConnection *connection, NmCli *nmc, gboolean active_on const char *ac_state = NULL; NMActiveConnectionState ac_state_int = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; char *ac_dev = NULL; + NmcTermColor color; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); @@ -957,15 +971,10 @@ fill_output_connection (NMConnection *connection, NmCli *nmc, gboolean active_on arr = nmc_dup_fields_array (nmc_fields_con_show, sizeof (nmc_fields_con_show), 0); + /* Show active connections in color */ - if (ac) { - if (ac_state_int == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) - set_val_color_all (arr, NMC_TERM_COLOR_YELLOW); - else if (ac_state_int == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) - set_val_color_all (arr, NMC_TERM_COLOR_GREEN); - else if (ac_state_int > NM_ACTIVE_CONNECTION_STATE_ACTIVATED) - set_val_color_all (arr, NMC_TERM_COLOR_RED); - } + nmc_active_connection_state_to_color (ac_state_int, &color); + set_val_color_all (arr, color); set_val_strc (arr, 0, nm_setting_connection_get_id (s_con)); set_val_strc (arr, 1, nm_setting_connection_get_uuid (s_con)); @@ -1517,7 +1526,7 @@ compare_connections (gconstpointer a, gconstpointer b, gpointer user_data) } for (i = 0; i < order->len; i++) { - item = g_array_index (order, NmcSortOrder, i); + item = g_array_index (order, NmcSortOrder, i); switch (item) { case NMC_SORT_ACTIVE: case NMC_SORT_ACTIVE_INV: diff --git a/clients/cli/connections.h b/clients/cli/connections.h index 189d968a45..cb70a3d52e 100644 --- a/clients/cli/connections.h +++ b/clients/cli/connections.h @@ -33,5 +33,6 @@ nmc_read_connection_properties (NmCli *nmc, char ***argv, GError **error); +void nmc_active_connection_state_to_color (NMActiveConnectionState state, NmcTermColor *color); #endif /* NMC_CONNECTIONS_H */ |