summaryrefslogtreecommitdiffstats
path: root/src/shared/pretty-print.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* terminal-util: define ANSI_OSC as macro for the OSC terminal sequence prefixLennart Poettering2024-10-311-3/+5
|
* tree-wide: prefer generating 0x1B 0x5C as ANSI sequence "ST"Lennart Poettering2024-10-311-3/+3
| | | | | | | | | | | | | | | | | OSC sequences can be closed with one of three terminators: 1. ASCII code 7, aka BEL, aka ^G, aka \x07, aka \a 2. ASCII code 156, aka \x9c 2. Pair of ASCII code 27 followed by ASCII code 92, aka \x1b\x5c Of these, in some corner case scenarios BEL makes problem (see #34604). Hence switch away from that wherever we use it, and prefer the \x1b\x5c instead. That's preferable over \x9c, since the latter is also a valid UTF-8 codepoint. See discussion here for example: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda#the-escape-sequence Fixes: #34604
* pretty-print: add format-string version of draw_progress_bar()Lennart Poettering2024-10-291-0/+16
| | | | | We often format the prefix string via asprintf() before, let's hence add a helper for that.
* pretty-print: rename draw_progress_bar_impl()→draw_progress_bar_unbuffered()Lennart Poettering2024-10-291-5/+4
|
* progress-bar: issue Windows Terminal progress indicating ANSI sequencesLennart Poettering2024-10-291-2/+13
| | | | | | | | | | | | | | | | | | | | This generates the Windows Terminal OSC sequences indicating progress. This let's the terminal know that we are doing a slow operation, and how we are progressing. Windows Terminal uses this in two ways: it shows a circle in the tab that completes, and it highlights the progress in the task bar. I found no Linux terminal that currently supports it, but also none that didn't like it. Thankfully most terminals correctly ignore unrecognized OSC sequences. I think we should just merge this, and see if this trips up too many people, but I have reason to believe this shouldn't be too bad. And yes, I do work from Windows Terminal sometimes, ssh into my Linux build systems, and it is really cute seeing the progress animation there.
* pretty-print: introduce WITH_BUFFERED_STDERR macro to enable bufferingYu Watanabe2024-09-031-16/+2
| | | | | Then, the buffer will be flushed and buffering will be disabled on exiting from the scope.
* pretty-print: rename {draw,clear}_progress_bar_unbuffered() -> ↵Yu Watanabe2024-09-031-4/+4
| | | | | | | {draw,clear}_progress_bar_impl() Addresses https://github.com/systemd/systemd/pull/34205#discussion_r1739648525. Follow-ups for 5f9dd9c64d20e7cdf8b509421e28cfebf31b7c32.
* progress-bar: Add unbuffered variantAdrian Vovk2024-08-311-16/+25
| | | | | | | | | | | | The progress_bar functions do their own buffering: they reconfigure stderr, then print, then flush and disable buffering on their own. In situations where multiple progress bars are being drawn at a time (for example, in updatectl), it's even more efficient to hoist the buffering and flushing to the call site, and avoid drawing each progress bar individually. To that end, new _unbuffered variants of the progress_bar functions. And we use them in updatectl.
* progress-bar: Put a space after the prefixAdrian Vovk2024-08-311-4/+6
| | | | | We always want a space there. So let's just put one in the drawing routine, and adjust the call cites to avoid adding a second one.
* repart: make prefix argument to clear_progress_bar() optionalLennart Poettering2024-06-251-1/+3
| | | | | In this case, let's try to override the whole line, not just the first few chars.
* pretty-print: take console glyph width into account when drawing progress barLennart Poettering2024-06-171-3/+4
| | | | So far this used string length, not character width. Fix that.
* pretty-print: enable stdio buffering while outputting progress barLennart Poettering2024-06-151-0/+15
| | | | | | | | | | | | | Writing the progress bar so far was irritatingly slow, which was caused by the fact that the various things we output so far resulted in one write() syscall each because STDERR is unbuffered by default. Let's fix that, and temporarily turn on full buffering for stderr, restoring the normal unbuffered output right after. This makes progress bar print visibly more efficient (and flicker free too, since terminals no longer will move the cursor around during output).
* pretty-print: make separator line greyLennart Poettering2024-06-131-1/+1
| | | | Let's deemphasize the line in the output a bit.
* nspawn, vmspawn, run0: add env var for turning off background tintingLennart Poettering2024-05-021-0/+15
| | | | | | | Some people are just sad, sad lost souls who don't like even the tiniest ray of color in their life. Let's add an env var knob for allowing them to turn the background tinting off, to drive the last bit of color from their life so that they can stay in their grey grey life.
* various: use strdup_to() in various obvious casesZbigniew Jędrzejewski-Szmek2024-03-201-10/+2
| | | | | strdup_to() returns 0 on success and here we convert obvious blocks which either return -ENOMEM or 0.
* Merge pull request #30480 from keszybz/kernel-install-more-pathsZbigniew Jędrzejewski-Szmek2024-03-081-18/+7
|\ | | | | Read kernel-install config from /run/kernel too
| * shared/pretty-print: rename output parametersZbigniew Jędrzejewski-Szmek2024-03-071-4/+4
| |
| * constants: drop duplicated CONF_PATHS definesZbigniew Jędrzejewski-Szmek2024-03-071-15/+4
| | | | | | | | Follow-up for b0d3095fd6cc1791a38f57a1982116b4475244ba.
* | shared/pretty-print: use strrepa where appropriateMike Yuan2024-03-021-7/+4
| |
* | shared/pretty-print: print color sequence only when neededMike Yuan2024-03-021-3/+3
| | | | | | | | Follow-up for 71cb203a6ea6de409c6b9c042feda2ff655101e9
* | importctl: draw a pretty progress bar while downloadingLennart Poettering2024-03-011-0/+72
| | | | | | | | Everybody loves pretty terminal progress bar.
* | pretty-print: make tinting a bit less aggressiveLennart Poettering2024-02-261-1/+1
|/
* shared/pretty-print: inline one more variable declarationZbigniew Jędrzejewski-Szmek2024-01-301-4/+2
|
* shared/pretty-print: use normal else-if cascadeZbigniew Jędrzejewski-Szmek2024-01-301-12/+5
| | | | | | | This is not a hot path, but it seems silly to evalute subsequent branches, which can never match once one has matched. Also, it makes the code harder to read, because the reader has to first figure out that only one branch can match.
* pretty-print: split out color tinting into a helper of its ownLennart Poettering2024-01-231-0/+30
|
* shared: highlight directives when dumping configsFrantisek Sumsal2023-12-071-1/+23
| | | | | | | | We already highlight sections and "de-highlight" comments, so let's add the last piece of the puzzle and highlight the configuration directives to visually distinguish them from the values. Closes: #13416
* pid1: move draw_cylong() to pretty-print.[ch]Yu Watanabe2023-11-221-0/+36
|
* shared/pretty-print: skip redundant section headers with --tldrZbigniew Jędrzejewski-Szmek2023-10-241-6/+9
| | | | | | | | | | | | | If the same section appears consecutively in a given file, subsequent occurenced are not printed. [Slice] Foo=bar [Slice] # this is not printed Bar=bar Requested in https://github.com/systemd/systemd/pull/29553#pullrequestreview-1677310352.
* shared/pretty-print: add highlightingZbigniew Jędrzejewski-Szmek2023-10-241-6/+29
|
* analyze/cat-config: add switch to print only "interesting" parts of config filesZbigniew Jędrzejewski-Szmek2023-10-241-7/+32
| | | | | | | | | | | | | | | | | | | | | | | | | When looking at configuration, often a user wants to suppress the comments and just look at the parts that actually configure something, roughly equivalent to systemd-analyze cat-config … | rg -v '^(#|;|$) This switch implements this natively, skipping lines that start with a comment character or only contain whitespace. For formats that have section headers, section headers are skipped, if only followed by stuff that would be skipped. (The last section header is printed when we're about to print some actual output.) Note that the caller doesn't know if the format has headers or not. We do format type detection in pretty-print.c. So the caller only specifies tldr=true|false, and conf_files_cat() figures out if the format has headers and whether those should be handled specially. The comments that show the file name are always printed, even if all of the file is suppressed. This is a partial answer to the discussions in https://github.com/systemd/systemd/pull/28919, https://github.com/systemd/systemd/pull/29248. If the default config is shown in config files, the user can conveniently use '--tldr' to show the relevant parts.
* shared/pretty-print: drop unused flagZbigniew Jędrzejewski-Szmek2023-10-141-6/+1
| | | | | | | | | 0895e87348e5fc02f50498cad5922eb3eb172323 removed the last (only?) use of CAT_MAIN_FILE_OPTIONAL, except for tests. All callers first check if the main file exists on their own, so this code was effectively dead. I want to repopulate the enum in later commits, so a dummy flag is added to allow the code to compile.
* treewide: fix "an" before consonant U soundsJoerg Behrmann2023-07-061-1/+1
| | | | | | The article "a" goes before consonant sounds and "an" goes before vowel sounds. This commit changes an to a for UKI, UDP, UTF-8, URL, UUID, U-Label, UI and USB, since they start with the sound /ˌjuː/.
* Rename def.h to constants.hZbigniew Jędrzejewski-Szmek2022-11-081-1/+1
| | | | | | The name "def.h" originates from before the rule of "no needless abbreviations" was established. Let's rename the file to clarify that it contains a collection of various semi-related constants.
* basic: rename util.h to logarithm.hZbigniew Jędrzejewski-Szmek2022-11-081-1/+0
| | | | | util.h is now about logarithms only, so we can rename it. Many files included util.h for no apparent reason… Those includes are dropped.
* strv: make iterator in STRV_FOREACH() declaread in the loopYu Watanabe2022-03-191-3/+1
| | | | This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
* analyze: fix printing config when there is no main config fileZbigniew Jędrzejewski-Szmek2021-11-211-14/+29
| | | | | | | | | | | | | | | | | | Since 8b8024f1c231c166f5c450905c8fd91d11704ae7 and the follow-up commits, the main config file may be located in /usr or in other paths. But the code in analyze.c was still assuming that it must be in /etc. Things mostly worked for our own config files because we usually install a comments-only file in /etc, but was not correct in the general case. This fixes in particular 'systemd-analyze cat-config systemd/zram-generator.conf'. In Fedora we distribute a config file in zram-generator-defaults.rpm that is in /usr/lib, and 'cat-config' would refuse to show it because /etc/systemd/zram-generator.conf does not exist. The main config file is optional, but let's print an informative message because this is a slightly unusual case. The file paths that we printed were missing the root prefix.
* Add meson option to disable urlify.James Hilliard2021-07-191-0/+4
| | | | | Useful for systems that don't use a version of less with hyperlink support.
* shared/pretty-print: silence gcc warningZbigniew Jędrzejewski-Szmek2021-03-311-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | gcc was very unhappy for some reason: [988/1664] Compiling C object systemd-oomd.p/src_oom_oomd.c.o In file included from ../src/basic/path-util.h:10, from ../src/shared/pretty-print.c:14, from ../src/oom/oomd.c:15: ../src/shared/pretty-print.c: In function ‘conf_files_cat’: ../src/basic/strv.h:123:32: warning: ‘prefixes’ may be used uninitialized [-Wmaybe-uninitialized] 123 | for ((s) = (l); (s) && *(s); (s)++) | ^ In file included from ../src/oom/oomd.c:15: ../src/shared/pretty-print.c:283:16: note: ‘prefixes’ was declared here 283 | char **prefixes, **prefix; | ^~~~~~~~ ../src/shared/pretty-print.c:305:12: warning: ‘is_collection’ may be used uninitialized in this function [-Wmaybe-uninitialized] 305 | if (!is_collection) { | ^ ../src/shared/pretty-print.c:301:13: warning: ‘extension’ may be used uninitialized in this function [-Wmaybe-uninitialized] 301 | r = conf_files_list_strv(&files, extension, root, 0, (const char* const*) dirs); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Maybe this is caused by the statis char** variables?
* pager: stop disabling urlification under a pagerZbigniew Jędrzejewski-Szmek2020-12-021-5/+1
| | | | | | | | | | | Less 568 properly shows urlified strings. Putative NEWS entry: * Urlification is now enabled by default even when a pager is used. Previously it was disabled, because less would not show such markup properly. This has been fixed in less 568. Please either upgrade less, or use SYSTEMD_URLIFY=0 to disable the feature.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* pretty-print: don't abbreviate needlessly in user-facing stringLennart Poettering2020-10-071-1/+1
|
* analyze: fix 'cat-config systemd/zram-generator.conf'Zbigniew Jędrzejewski-Szmek2020-08-051-0/+6
| | | | Also makes this work for various systemd config files that support .d.
* pretty-print: export urlify_enabled()Lennart Poettering2020-05-291-1/+1
|
* analyze: make cat-config work with relabel-extra.dZbigniew Jędrzejewski-Szmek2019-08-191-9/+18
|
* timedated: add back support for ntp-units.d/Zbigniew Jędrzejewski-Szmek2019-07-221-0/+5
| | | | | | | | | | | | | | | | | | | | We removed support for foreign services (and ntp-units.d/) in b72ddf0f4. Support for foreign services was added back in 5d280742, but through an environment variable. The problem with the env var approach is that it only works as a mechanism to select one item, and doesn't work nicely as a mechinism to create a list of items through drop-ins (because the env var can be easily overridden, but not extended). Having a list of "ntp providers" is important to be able to reliably disable all of them when that is requested. Another problem is that nobody ever bothered to care about our new "standard". ntp-units.d/ is a nice simple format that works and is already supported by chrony and ntpd and timedatex. If we were to introduce and ask people to follow a new standard, there should be some good reason for this. The idea with env vars has lower functionality, requires systemd-specific syntax. We should just re-adopt the format that we originally introduced and that seems to work for everyone, and more on to more interesting problems.
* systemd-analyze: support cat-config kernel/install.dZbigniew Jędrzejewski-Szmek2019-03-071-0/+3
| | | | Extension of f1d9d36ac5958006bbd464944ef490a198d38189.
* analyze: generalize cat-config to apply to tmpfiles, presets, hwdb.d, etc.Zbigniew Jędrzejewski-Szmek2019-02-181-10/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #10256. What works: systemd-analyze cat-config systemd/system-preset systemd-analyze cat-config systemd/user-preset systemd-analyze cat-config tmpfiles.d systemd-analyze cat-config sysusers.d systemd-analyze cat-config systemd/sleep.conf systemd-analyze cat-config systemd/user.conf systemd-analyze cat-config systemd/system.conf systemd-analyze cat-config udev/udev.conf (and other .conf files) systemd-analyze cat-config udev/rules.d systemd-analyze cat-config environment.d systemd-analyze cat-config environment Directories may be specified with the trailing dash or not. The caveat is that for user configuration, systemd and other tools also look at ~/.config/. It would be nice to support this, but this patch doesn't. "cat-config --user" is rejected, and we may allow it in the future and then extend the search path with directories under ~/.config. What doesn't work (and probably shouldn't because those files cannot be meaningfully concatenated): systemd-analyze cat-config systemd/system (.service, .slice, .socket, ...) systemd-analyze cat-config systemd/user systemd-analyze cat-config systemd/network (.network, .link, and .dnssd) The hardcoding of information about paths in this manner is a bit ugly, but OTOH, it is not too onerous, and at least we have one place where all the schemes are "documented" through code. It'll make us think twice before adding yet another slightly different scheme.
* terminal-util: split out file:// generation from terminal_urlify_path()Lennart Poettering2018-11-301-19/+33
| | | | | This way we can use it at other places, for example when preparing URLs for format_table_set_url()
* Split out pretty-print.c and move pager.c and main-func.h to shared/Zbigniew Jędrzejewski-Szmek2018-11-201-0/+233
This is high-level functionality, and fits better in shared/ (which is for our executables), than in basic/ (which is also for libraries).