41 Commits

Author SHA1 Message Date
Adian Kozlica
4f8b935567 feat: json support for table printer 2025-10-13 13:53:15 +00:00
Simon McVittie
fc1b32e97b table-printer: Slightly increase const-correctness
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-08-22 15:17:13 -03:00
Chris Williams
2aebcb117a table-printer: Ellipsize by terminal width by default
This fixes the display of ellipsized columns in `flatpak remotes -d`
with wide terminals.
2024-03-27 14:26:28 +00:00
Simon McVittie
ae2579637a app: Move terminal-related utility functions from common into app
These functions are to do with being an interactive, terminal-oriented
CLI/TUI, so it would be inappropriate for library code in libflatpak
to call them, and it would also be inappropriate for daemons like the
session and system helpers to call them.

In fact all calls to these were already isolated to app/, so we can
easily move the terminal-related utilities themselves into app/.

As well as shrinking libflatpak, this makes it obvious that the system
helper does not actually need to call flatpak_disable_fancy_output():
it does not link any code that would be affected by that API call.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-07-03 20:19:00 +02:00
Phaedrus Leeds
600e18567c Add a vim modeline and .editorconfig
To make indentation work with less effort. The modeline was copied from
libostree with minor modification and the .editorconfig from GLib.

The advantage of having both a modeline and an editorconfig is we can
work out of the box on more editor setups, and the modeline allows us to
specify the style with a lot more fine grained control.
2022-08-22 19:48:10 -07:00
Simon McVittie
17b6c31c7c Add missing G_GNUC_PRINTF attributes
This allows callers to be checked for mismatches between format string
and arguments, and also means gcc can assume that the format string and
the arguments match up correctly when forwarding them to functions
like g_strdup_vprintf, removing the need to suppress -Wformat-nonliteral
warnings.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-05-25 10:33:18 +02:00
Alexander Larsson
515ae5e5df CLI: List arch if it is not the primary arch (even if unique)
Currenly we only list arch in the list of things to install from a
transaction if not all the refs are the same arch. It makes more sense
to show the arch even if its unique if they are not the primary arch.
2021-05-19 09:54:59 +02:00
Alexander Larsson
bf5329aa69 table-printer: Add append_with_comma_unique
This means we can ensure a flag is only added once
2020-11-13 10:32:19 +01:00
Alexander Larsson
caa1c8c839 table printer: Add some helpers
Allow looking up pre-existing rows (by key) and appending to existing
cells.
2020-10-29 15:30:35 +01:00
Phaedrus Leeds
08f692962e Avoid shadowing local variables
Avoid shadowing variables that are already declared in a previous scope,
and make such occurrences compile-time errors. These are not functional
changes.

In a few places do related code cleanup.

A similar ostree PR is here:
https://github.com/ostreedev/ostree/pull/2195
2020-09-15 08:58:49 +02:00
Ryan Gonzalez
cd231503f2 app: Avoid a potential segfault when skipping columns
Closes: #2942
Approved by: mwleeds
2019-06-07 03:48:33 +00:00
Ryan Gonzalez
6cfd399c45 app: Fix a typo
Closes: #2942
Approved by: mwleeds
2019-06-07 03:48:33 +00:00
Alexander Larsson
05ac7f4833 CLI: Add skip_unique_if_default to Column
Additionally flatpak_table_printer_set_columns now takes a boolean
to say whether the arguments in use are the default.

Closes: #2850
Approved by: matthiasclasen
2019-04-23 13:05:14 +00:00
Alexander Larsson
c25de61cd1 table-printer: Add support for skipping unique columns
If a column is marked skip_unique it will be entierly skipped
if all the rows have the same unique value for it. This is
useful for example to skip the arch column if all arches are
the same.

Closes: #2850
Approved by: matthiasclasen
2019-04-23 13:05:14 +00:00
Matthew Leeds
e8816b7663 Remove extra newlines in variable definiton blocks
Uncrustify has an option "nl_func_var_def_blk" which is supposed to
ensure there's a newline character between the block of variable
definitions and the rest of the function body, but it gets confused and
thinks that the first instance of "g_autoptr" or "g_auto" being used on
a variable is the start of the function body. So this commit removes
those extra newline characters and removes that option in uncrustify.cfg
so they don't get re-added the next time uncrustify is run.

Here's the command I used:

perl -0777 -i -pe 's/\n(\n\s*g_auto\()/\1/g' `git ls-tree --name-only
-r HEAD | grep \\\.[ch]$ | grep -v common/valgrind-private.h |
grep -v app/flatpak-polkit-agent-text-listener\\\.[ch]`

I ran it again with "g_autoptr" in place of "g_auto", and made a few
manual edits to add back the newline when the g_auto* was in the middle
of a function body rather than at the top.

Closes: #2715
Approved by: matthiasclasen
2019-02-25 18:12:30 +00:00
Matthew Leeds
8d962a686f Run uncrustify
I had to make a few manual edits but other than those the changes look
reasonable.

Closes: #2715
Approved by: matthiasclasen
2019-02-25 18:12:30 +00:00
Matthias Clasen
ce0981cb6d table printer: Use cell width, throughout
This should make it safe to use Escape sequences
in table content without messing up the alignment.

Closes: #2689
Approved by: alexlarsson
2019-02-14 09:12:40 +00:00
Matthias Clasen
d1b4719ab8 table printer: Redo column handling
Move expand and ellipsize to the Column struct,
and change flatpak_table_printer_set_column_titles
to flatpak_table_printer_set_columns that sets up
not just the title, but also expand and ellipsize.

Update all callers.

Closes: #2460
Approved by: alexlarsson
2019-01-14 13:35:56 +00:00
Matthias Clasen
d3447eb3fa table printer: Properly handle title width
Another case of printf field width not being Unicode
safe.

Closes: #2502
Approved by: alexlarsson
2019-01-11 13:31:10 +00:00
Matthias Clasen
b3ea2248c7 Fix a few utf8 oversights
We are allowing Unicode output, so we need to
use g_utf8_strlen whenever we want to count the
number of columns occupied by a string.

Closes: #2502
Approved by: alexlarsson
2019-01-11 13:31:10 +00:00
Matthias Clasen
cefbbd6e59 table printer: Report actual width
When we can't shrink all the way to the desired
number of columns, report the actual width we've
achieved.

Closes: #2496
Approved by: matthiasclasen
2019-01-08 01:11:49 +00:00
Matthias Clasen
f4e42ec071 table printer: Be more careful with shrink
Ensure that 0 <= shrink[i] <= widths[i],
to avoid bad situations.

Closes: #2496
Approved by: matthiasclasen
2019-01-08 01:11:49 +00:00
Matthias Clasen
a133041bdd table printer: Don't loop forever
After ellipsizing nicely, we try to spread the extra
shortfall around, but we need to stop when we've
exhausted the available shrinkage and give up.

Some tables are just too wide.

This was showing up as an infinite loop with

flatpak remote-ls --columns=app,opt flathub

Closes: #2496
Approved by: matthiasclasen
2019-01-08 01:11:49 +00:00
Matthias Clasen
ff9aa02d93 table printer: Remote debug spew
Closes: #2462
Approved by: matthiasclasen
2018-12-21 16:51:48 +00:00
Alexander Larsson
c9c395c5c9 table-printer: Correctly handle alignment with utf8
We can't use printf alignment, because that aligns on byte count, not
char counts.

Closes: #2451
Approved by: alexlarsson
2018-12-20 17:06:28 +00:00
Alexander Larsson
9d3b1d6990 table-printer: Fix regression crash
printer->rows is now a Row, not a GPtrArray

Closes: #2451
Approved by: alexlarsson
2018-12-20 17:06:28 +00:00
Alexander Larsson
b7e06dee2d 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
2018-12-20 16:08:44 +00:00
Matthias Clasen
f3c6e647c1 table printer: Support middle ellipsization
This is sometimes better than ellipsizing at the end.

Closes: #2448
Approved by: alexlarsson
2018-12-20 16:08:44 +00:00
Matthias Clasen
d6c59020a2 Try harder to ellipsize well
Don't shrink all columns by the same amount.
Shrink wider columns more, and avoid ellipsizing
titles.

Closes: #2448
Approved by: alexlarsson
2018-12-20 16:08:44 +00:00
Alexander Larsson
89650f503c table-printer: Add support for sorting rows
Closes: #2450
Approved by: alexlarsson
2018-12-20 15:50:07 +00:00
Alexander Larsson
c4e76f6374 table-printer: Handle utf8 correctly for string widths
We're counting characters, not bytes, so we need g_ut8_strlen() & co.

Closes: #2449
Approved by: alexlarsson
2018-12-20 12:51:32 +00:00
Matthias Clasen
f0d4665901 Add ellipsizing to the table printer
Optionally mark a column as ellipsizing.

Currently, this won't work correctly if more
than one column is ellipsizing.

Closes: #2409
Approved by: alexlarsson
2018-12-19 15:45:34 +00:00
Alexander Larsson
2255e7c73f table-printer: Don't print newlines for skipped rows
Closes: #2371
Approved by: alexlarsson
2018-12-18 14:50:26 +00:00
Matthias Clasen
908703d64a table printer: Add per-column expand api
When we are given a with that is larger than the content we have,
expand the space between columns, within reason. We only make the
table at most 1.5 times as wide as it would be unexpanded.

Add a new API for setting individual columns to expand (or not).
For an expanding column, we'll grow the space between it and its
preceding column. The expand flag of the first column is ignored.

By default, columns do not expand.

Make flatpak_table_printer_print_full return not just the table
height, but also the width.

Update all callers.

Closes: #2371
Approved by: alexlarsson
2018-12-18 14:50:26 +00:00
Matthias Clasen
3fe15ef665 table printer: Add a decimal cell setter
The download column really hsold be decimal, and we want
to update it while the download is running.

Closes: #2371
Approved by: alexlarsson
2018-12-18 14:50:26 +00:00
Matthias Clasen
8fa0f73067 table printer: Add cell and row apis
Add a way to change individual cells and  a getter for the
current row. Also add a variation of the print() method that
returns the number of terminal rows that was generated
when formatting to given width, while skipping a number
of rows at the beginning. This method will be used in the
following commit to print a part of the table into a terminal
window of a given size.

Closes: #2371
Approved by: alexlarsson
2018-12-18 14:50:26 +00:00
Matthias Clasen
259e438d4b Add table printer convenience api for columns
This code is repeated in ever single command using
columns, so lets pull it into a utility function.

Closes: #2090
Approved by: alexlarsson
2018-10-05 15:19:43 +00:00
Alexander Larsson
bdf5c87429 tables: Avoid trailing spaces
In a table, if some row is wide then *all* rows will be that wide
with spaces at the end. This is not great in e.g. the remote-ls
case where one row has a long EOL message.

This commit strips all the trailing whitespace from each row to avoid
this.

Closes: #2189
Approved by: alexlarsson
2018-10-05 11:22:18 +00:00
Alexander Larsson
3f4518b15c Run uncrustify
Closes: #1870
Approved by: alexlarsson
2018-07-08 10:05:37 +00:00
Alexander Larsson
b1a7930cc7 TablePrinter: Add span cells
These can be used to print rows that are not cell-aligned.

Closes: #1799
Approved by: alexlarsson
2018-06-19 14:54:22 +00:00
Alexander Larsson
7c17e77e84 Move FlatpakTablePrinter to app/
This is only used by the CLI

Closes: #1706
Approved by: alexlarsson
2018-05-24 11:59:52 +00:00