mirror of
https://github.com/flatpak/flatpak.git
synced 2026-01-28 17:41:14 -05:00
tables: Add support for ellipsize start and use for app id
I think this makes a lot more sense than ellipsizing in the middle. Most app ids start with a common prefix after all. Closes: #2448 Approved by: alexlarsson
This commit is contained in:
committed by
Atomic Bot
parent
5b247157a3
commit
b7e06dee2d
@@ -169,16 +169,16 @@ print_table_for_refs (gboolean print_apps,
|
||||
flatpak_table_printer_set_column_expand (printer, i, TRUE);
|
||||
flatpak_table_printer_set_column_ellipsize (printer,
|
||||
find_column (columns, "description", NULL),
|
||||
TRUE);
|
||||
flatpak_table_printer_set_column_ellipsize_middle (printer,
|
||||
FLATPAK_ELLIPSIZE_MODE_END);
|
||||
flatpak_table_printer_set_column_ellipsize (printer,
|
||||
find_column (columns, "application", NULL),
|
||||
TRUE, TRUE);
|
||||
FLATPAK_ELLIPSIZE_MODE_START);
|
||||
|
||||
if (app_runtime)
|
||||
{
|
||||
if (!flatpak_split_partial_ref_arg (app_runtime, FLATPAK_KINDS_RUNTIME, NULL, NULL,
|
||||
&match_kinds, &match_id, &match_arch, &match_branch, error))
|
||||
return FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; i < refs_array->len; i++)
|
||||
|
||||
@@ -126,7 +126,7 @@ ls_remote (GHashTable *refs_hash, const char **arches, const char *app_runtime,
|
||||
flatpak_table_printer_set_column_expand (printer, i, TRUE);
|
||||
flatpak_table_printer_set_column_ellipsize (printer,
|
||||
find_column (columns, "description", NULL),
|
||||
TRUE);
|
||||
FLATPAK_ELLIPSIZE_MODE_END);
|
||||
|
||||
if (app_runtime)
|
||||
{
|
||||
|
||||
@@ -260,9 +260,9 @@ print_matches (Column *columns, GSList *matches)
|
||||
|
||||
flatpak_get_window_size (&rows, &cols);
|
||||
ellip = find_column (columns, "description", NULL);
|
||||
flatpak_table_printer_set_column_ellipsize (printer, ellip, TRUE);
|
||||
flatpak_table_printer_set_column_ellipsize (printer, ellip, FLATPAK_ELLIPSIZE_MODE_END);
|
||||
ellip = find_column (columns, "application", NULL);
|
||||
flatpak_table_printer_set_column_ellipsize_middle (printer, ellip, TRUE, TRUE);
|
||||
flatpak_table_printer_set_column_ellipsize (printer, ellip, FLATPAK_ELLIPSIZE_MODE_START);
|
||||
flatpak_table_printer_print_full (printer, 0, cols, NULL, NULL);
|
||||
g_print ("\n");
|
||||
|
||||
|
||||
@@ -973,22 +973,24 @@ format_timestamp (guint64 timestamp)
|
||||
char *
|
||||
ellipsize_string (const char *text, int len)
|
||||
{
|
||||
return ellipsize_string_pos (text, len, FALSE);
|
||||
return ellipsize_string_full (text, len, FLATPAK_ELLIPSIZE_MODE_END);
|
||||
}
|
||||
|
||||
char *
|
||||
ellipsize_string_pos (const char *text, int len, gboolean middle)
|
||||
ellipsize_string_full (const char *text, int len, FlatpakEllipsizeMode mode)
|
||||
{
|
||||
g_autofree char *ret = g_strdup (text);
|
||||
|
||||
if (g_utf8_strlen (ret, -1) > len)
|
||||
if (mode != FLATPAK_ELLIPSIZE_MODE_NONE && g_utf8_strlen (ret, -1) > len)
|
||||
{
|
||||
char *p;
|
||||
char *q;
|
||||
int i;
|
||||
int l1, l2;
|
||||
|
||||
if (middle)
|
||||
if (mode == FLATPAK_ELLIPSIZE_MODE_START)
|
||||
l1 = 0;
|
||||
else if (mode == FLATPAK_ELLIPSIZE_MODE_MIDDLE)
|
||||
l1 = len / 2;
|
||||
else
|
||||
l1 = len - 1;
|
||||
|
||||
@@ -129,8 +129,17 @@ Column *handle_column_args (Column *all_columns,
|
||||
GError **error);
|
||||
|
||||
char * format_timestamp (guint64 timestamp);
|
||||
|
||||
|
||||
typedef enum {
|
||||
FLATPAK_ELLIPSIZE_MODE_NONE,
|
||||
FLATPAK_ELLIPSIZE_MODE_START,
|
||||
FLATPAK_ELLIPSIZE_MODE_MIDDLE,
|
||||
FLATPAK_ELLIPSIZE_MODE_END,
|
||||
} FlatpakEllipsizeMode;
|
||||
|
||||
char * ellipsize_string (const char *text, int len);
|
||||
char * ellipsize_string_pos (const char *text, int len, gboolean middle);
|
||||
char * ellipsize_string_full (const char *text, int len, FlatpakEllipsizeMode mode);
|
||||
|
||||
AsApp *as_store_find_app (AsStore *store,
|
||||
const char *ref);
|
||||
|
||||
@@ -67,8 +67,7 @@ typedef struct
|
||||
{
|
||||
char *title;
|
||||
gboolean expand;
|
||||
gboolean ellipsize;
|
||||
gboolean ellipsize_middle;
|
||||
FlatpakEllipsizeMode ellipsize;
|
||||
} TableColumn;
|
||||
|
||||
static void
|
||||
@@ -564,7 +563,7 @@ flatpak_table_printer_print_full (FlatpakTablePrinter *printer,
|
||||
if (shrinks[j] > 0 && ellipsize)
|
||||
{
|
||||
len -= shrinks[j];
|
||||
freeme = text = ellipsize_string_pos (text, len, col->ellipsize_middle);
|
||||
freeme = text = ellipsize_string_full (text, len, col->ellipsize);
|
||||
}
|
||||
|
||||
if (flatpak_fancy_output ())
|
||||
@@ -660,22 +659,9 @@ flatpak_table_printer_set_column_expand (FlatpakTablePrinter *printer,
|
||||
void
|
||||
flatpak_table_printer_set_column_ellipsize (FlatpakTablePrinter *printer,
|
||||
int column,
|
||||
gboolean ellipsize)
|
||||
FlatpakEllipsizeMode mode)
|
||||
{
|
||||
TableColumn *col = get_table_column (printer, column);
|
||||
|
||||
col->ellipsize = ellipsize;
|
||||
col->ellipsize_middle = FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
flatpak_table_printer_set_column_ellipsize_middle (FlatpakTablePrinter *printer,
|
||||
int column,
|
||||
gboolean ellipsize,
|
||||
gboolean middle)
|
||||
{
|
||||
TableColumn *col = get_table_column (printer, column);
|
||||
|
||||
col->ellipsize = ellipsize;
|
||||
col->ellipsize_middle = middle;
|
||||
col->ellipsize = mode;
|
||||
}
|
||||
|
||||
@@ -74,10 +74,6 @@ void flatpak_table_printer_set_column_expand (FlatpakTablePrinter
|
||||
gboolean expand);
|
||||
void flatpak_table_printer_set_column_ellipsize (FlatpakTablePrinter *printer,
|
||||
int col,
|
||||
gboolean ellipsize);
|
||||
void flatpak_table_printer_set_column_ellipsize_middle (FlatpakTablePrinter *printer,
|
||||
int col,
|
||||
gboolean ellipsize,
|
||||
gboolean middle);
|
||||
FlatpakEllipsizeMode mode);
|
||||
|
||||
#endif /* __FLATPAK_TABLE_PRINTER_H__ */
|
||||
|
||||
Reference in New Issue
Block a user