Inspection of what system calls flatpak search
does shows that the flatpak command checks the standard output for being an actual terminal, and gets its width in characters¹, to lay out the output (you can test that: make a smaller console window, and run the the same flatpak search
command again: it's not containing the exact same output!).
Because redirection into a file doesn't have a "number of displayable columns", flatpak doesn't try to do the same nice layout as for displaying.
Hey Flimm, this sounds a lot like you really shouldn't be using the "human-pretty" output that e.g. flatpak search
produces, but call the underlying programs yourself. However:
flatpak
does by default separate the columns in its output with tabulators (Tab, ↹, \t
, however you call it), and that makes it easy for you to just separate the individual columns and do the layouting yourself, the way you want it. For example:
COLUMNS=application,version,name
flatpak search --columns "${COLUMNS}" gimp | mlr --itsv --opprint --barred --implicit-csv-header label "${COLUMNS}"
yields
+------------------------------------+---------+--------------------------------+
| application | version | name |
+------------------------------------+---------+--------------------------------+
| org.gimp.GIMP.Manual | 2.10 | GIMP User Manual |
| org.gimp.GIMP | 2.10.34 | GNU Image Manipulation Program |
| org.gimp.GIMP.Plugin.Resynthesizer | 2.0.3 | Resynthesizer |
| org.gimp.GIMP.Plugin.Resynthesizer | 2.0.3 | Resynthesizer |
| org.gimp.GIMP.Plugin.Lensfun | 0.2.4 | GimpLensfun |
| org.gimp.GIMP.Plugin.Lensfun | 0.2.4 | GimpLensfun |
| org.gimp.GIMP.Plugin.Fourier | 0.4.3 | Fourier |
| org.gimp.GIMP.Plugin.Fourier | 0.4.3 | Fourier |
| org.gimp.GIMP.Plugin.BIMP | 2.6 | BIMP |
| org.gimp.GIMP.Plugin.BIMP | 2.5 | BIMP |
| org.gimp.GIMP.Plugin.LiquidRescale | 0.7.2 | LiquidRescale |
| org.gimp.GIMP.Plugin.LiquidRescale | 0.7.2 | LiquidRescale |
| org.gimp.GIMP.Plugin.GMic | 3.2.6 | G'MIC |
| org.gimp.GIMP.Plugin.GMic | 2.9.6 | G'MIC |
| org.gimp.GIMP.Plugin.FocusBlur | 3.2.6 | FocusBlur |
| org.gimp.GIMP.Plugin.FocusBlur | 3.2.6 | FocusBlur |
| org.gabmus.swatch | 0.1 | Swatch |
| com.github.unrud.djpdf | 0.4.3 | Scans to PDF |
+------------------------------------+---------+--------------------------------+
¹ How I did that:
A quick strace -o /tmp/flatpak.strace flatpak search
, followed by reading /tmp/flatpak.strace:
grep ioctl /tmp/strace
giving us
ioctl(1, TIOCGWINSZ, {ws_row=61, ws_col=232, ws_xpixel=2552, ws_ypixel=1403}) = 0
ioctl(1, TCGETS, {c_iflag=ICRNL|IXON|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
bvi
..) Look for linefeed characters (hex0A
).flatpack
.