Commit Graph

60 Commits

Author SHA1 Message Date
rnhmjoj dcdd9030ba
basic/term-util: inline colors_enabled function
There is no need to cache colors_enabled because the function
is now simply calling get_color_mode, which is already cached.
2020-12-15 19:40:30 +01:00
rnhmjoj 25e4608b8b
tree-wide: avoid direct use of color macros 2020-12-15 19:29:42 +01:00
rnhmjoj c4fea19abb
basic/term-util: extend $SYSTEMD_COLORS
This commit extends $SYSTEMD_COLORS to an enum variable (compared to
a simple boolean) which specifies the "colors mode". This means that, in
addition to disabling colors altogether, it's now possible to restrict
the console output to 16 or 256 colors only.
2020-12-15 19:29:42 +01:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Zbigniew Jędrzejewski-Szmek 5ee27251cd basic/terminal-util: rename our replacement highlight-yellow and test both the original and replacement
The fact that we cannot use the "real" yellow color and need to use some other
color is essentially a bug. In this particular case the issue is in urxvt, see
a9009769de. While we work around this by using a
different color, let's not forget that this is just a (hopefullly temporary)
workaround.

https://bugzilla.redhat.com/show_bug.cgi?id=1859886
https://bugzilla.redhat.com/show_bug.cgi?id=1859889
https://bugzilla.redhat.com/show_bug.cgi?id=1859894
2020-07-30 14:43:02 +02:00
Zbigniew Jędrzejewski-Szmek 66bb00590f basic/terminal-util: define all foreground colors
We would add and remove definitions based on which colors were used by other
code. Let's just define all of them to simplify tests and allow easy comparisons
which colors look good.
2020-07-23 15:04:15 +02:00
Lennart Poettering 45d82c3f1c systemctl: ensure underline for "list-unit-files" empty cells 2020-05-06 15:40:15 +02:00
Lennart Poettering a851ba0795 terminal-util: fixate underlined yellow color too
non-underlined yellow uses RGB ANSI sequences while the underlined
version uses the paletted ANSI sequences. Let's unify that and use the
RGB sequence for both cases, so that underlined or not doesn't alter the
color.
2020-04-08 19:43:44 +02:00
Lennart Poettering 26382cab1b Revert "Move verify_vc_kbmode() to terminal-util.c as vt_verify_kbmode()"
This reverts commit bb5ac84d79.
2019-07-18 16:21:02 +02:00
Zbigniew Jędrzejewski-Szmek d35305fe83 basic/log: put location in a dark shade of yellow
It is different then the other colors we use. Tested on gnome-terminal,
urxvt, urxvt -rv, xterm, linux console.
2019-07-02 09:34:12 +02:00
Franck Bui ae1d13db05 terminal-util: introduce openpt_allocate()
Allocating a pty is done in a couple of places so let's introduce a new helper
which does the job.

Also the new function, as well as openpt_in_namespace(), returns both pty
master and slave so the callers don't need to know about the pty slave
allocation details.

For the same reasons machine_openpt() prototype has also been changed to return
both pty master and slave so callers don't need to allocate a pty slave which
might be in a different namespace.

Finally openpt_in_namespace() has been renamed into
openpt_allocate_in_namespace().
2019-06-18 09:26:31 +02:00
Lennart Poettering 1802d5f2cf terminal-util: reset access mode in vt_restore(), too
Only changing ownership back to root is not enough we also need to
change the access mode, otherwise the user might have set 666 first, and
thus allow everyone access before and after the chown().
2019-05-24 15:07:55 +02:00
Zbigniew Jędrzejewski-Szmek a9009769de terminal-util: define yellow as "Khaki3"
Previously used "highlight yellow" was not visible on urxvt, because it
was too light. This color is shown as bold black by urxvt, but at least
it is readable. On other terminals it is shown as various hues of yellow,
pleasant on the eyes and not too bright. The color shown on linux console
could be called orange rather than yellow, but it is still readable.

(I also tried non-highlight "yellow", but it is not as readable.)

This is a follow-up for bb40c12569.
2019-05-17 15:06:59 +02:00
Zbigniew Jędrzejewski-Szmek e6042f682f
Merge pull request #12535 from poettering/color-grey
redefine how we select the ANSI color grey
2019-05-16 21:15:06 +02:00
Lennart Poettering 9725f1a10f
Merge pull request #12378 from rbalint/vt-kbd-reset-check
VT kbd reset check
2019-05-16 16:39:38 +02:00
Lennart Poettering 003aa3e045 terminal-util: add complete set of inline functions for all colors we define
We don#t actually use all combinations, but it's kinda nice if we can
output all combinations in a test, and this is preparation so that we
can do so nicely.
2019-05-10 15:00:55 -04:00
Lennart Poettering 1530bf251a terminal-util: reduce colors we define a bit
three of these colors we never use, so let's drop them. Let's however
add a highlight version of grey, so that at least for all colors we do
define we have all possible styles defined.
2019-05-10 15:00:55 -04:00
Lennart Poettering bb40c12569 terminal-util: define grey as 256color ANSI sequence
Apparently all relevant terminals implement these sequences, including
the Linux kernel, rxvt, xterm, and of course gnome terminal. Hence it
should be OK to use them, and fixate the grey color in a way that maps
to the same color in all terminals.

Ideally we'd stick to the more symbolic colors that allow terminal
emulators to implement color styles, but this apparently doesn#t work,
since rxvt maps grey to something unreadable by default.

Note that this change has negative effects besides the non-themability
of the palette: the midrange grey this uses maps to regular white on the
linux console. However, that's probably not too bad: allowing things to
be unreadable on some terminals is probably worse than showing no color
on some terminals.

Fixes: #12482
2019-05-10 15:00:55 -04:00
Zbigniew Jędrzejewski-Szmek 37b8d2f699 basic/log: use colors to highlight messages like journalctl 2019-05-08 09:45:38 +02:00
Balint Reczey bb5ac84d79 Move verify_vc_kbmode() to terminal-util.c as vt_verify_kbmode() 2019-04-24 18:01:40 +02:00
Lennart Poettering ec4b9671b3 resolvectl: color "comment" output grey
Let's de-emphasize the "comment" output a bit, by making it grey.
2018-12-05 18:46:23 +01:00
Franck Bui 27dafac92b terminal-util: introduce vt_release() helper 2018-11-21 14:28:34 +01:00
Franck Bui 6179ede1c5 terminal-util: introduce vt_restore() helper 2018-11-21 14:25:10 +01:00
Zbigniew Jędrzejewski-Szmek 294bf0c34a Split out pretty-print.c and move pager.c and main-func.h to shared/
This is high-level functionality, and fits better in shared/ (which is for
our executables), than in basic/ (which is also for libraries).
2018-11-20 18:40:02 +01:00
Lennart Poettering 37ec0fdd34 tree-wide: add clickable man page link to all --help texts
This is a bit like the info link in most of GNU's --help texts, but we
don't do info but man pages, and we make them properly clickable on
terminal supporting that, because awesome.

I think it's generally advisable to link up our (brief) --help texts and
our (more comprehensive) man pages a bit, so this should be an easy and
straight-forward way to do it.
2018-08-20 11:33:04 +02:00
Tomsod M 8255430754 show-status: add newline to ephemeral messages
Fixes #6712.  The newline is later reversed, naturally.
2018-07-06 16:35:22 +02:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Lennart Poettering ef31828d06 tree-wide: unify how we define bit mak enums
Let's always write "1 << 0", "1 << 1" and so on, except where we need
more than 31 flag bits, where we write "UINT64(1) << 0", and so on to force
64bit values.
2018-06-12 21:44:00 +02:00
Lennart Poettering cb91deaf77 terminal-util: add a function that shows a pretty separator line
Follow-up for #8824
2018-05-11 08:15:33 +02:00
Zbigniew Jędrzejewski-Szmek 854a42fb2e analyze: add 'cat-config' verb
This is used as 'systemd-analyze show-config systemd/logind.conf', which
will dump
   /etc/systemd/system/user@.service
   /etc/systemd/system/user@.service.d/*.conf
   /run/systemd/system/user@.service.d/*.conf
   /usr/local/lib/systemd/system/user@.service.d/*.conf
   /usr/lib/systemd/system/user@.service.d/*.conf

The idea is to make it easy to dump the configuration using the same locations
and order that systemd programs use themselves (including masking, in the right
order, etc.). This is the generic variant that works with any configuration
scheme that follows the same general rules:

$ systemd-analyze cat-config systemd/system.conf
$ systemd-analyze cat-config systemd/user.conf
$ systemd-analyze cat-config systemd/logind.conf
$ systemd-analyze cat-config systemd/sleep.conf
$ systemd-analyze cat-config systemd/journald.conf
$ systemd-analyze cat-config systemd/journal-remote.conf
$ systemd-analyze cat-config systemd/journal-upload.conf
$ systemd-analyze cat-config systemd/coredump.conf
$ systemd-analyze cat-config systemd/resolved.conf
$ systemd-analyze cat-config systemd/timesyncd.conf
$ systemd-analyze cat-config udev/udev.conf
2018-04-27 10:06:24 +02:00
Zbigniew Jędrzejewski-Szmek 81f5e51368 Move function to cat file & dropins into basic/
This fixes a buglet where the second and later drop-in would not be seperated
properly by a newline.
2018-04-26 13:52:46 +02:00
Lennart Poettering 23b27b39d2 terminal: add internal API to format URLs for display in capable terminals
Newer terminals (in particular gnome-terminal) understand special escape
sequence for formatting clickable links. Let's support that to make our
tool output more clickable where that's appropriate.

For details see this:

https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda

The one big issue is that 'less' currently doesn't grok this, and
doesn't ignore sequence like regular terminal implementations do if they
don't support it. Hence for now, let's disable URL output if a pager is
used. We should revisit that though as soon as less added support for it
and enough time passed for it to enter various distributions.
2018-04-19 18:04:26 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Zbigniew Jędrzejewski-Szmek f6a8265b9a core: drop unnecessary __useless_struct_to_allow_trailing_semicolon__
ISO C does not allow empty statements outside of functions, and gcc
will warn the trailing semicolons when compiling with -pedantic:

  warning: ISO C does not allow extra ‘;’ outside of a function [-Wpedantic]

But our code cannot compile with -pedantic anyway, at least because

  warning: ISO C does not support ‘__PRETTY_FUNCTION__’ predefined identifier [-Wpedantic]

Without -pedatnic, clang and even old gcc (3.4) generate no warnings about
those semicolons, so let's just drop __useless_struct_to_allow_trailing_semicolon__.
2018-03-06 10:41:41 +01:00
Lennart Poettering 6cc7e918ff
Merge pull request #8314 from poettering/rearrange-stdio
refactor how we rearrange fds for stdin/stdout/stderr
2018-03-02 15:42:03 +01:00
Lennart Poettering 8bb2db738e terminal-util: port some generic code over to rearrange_stdio() 2018-03-02 11:42:10 +01:00
Alexander F Rødseth 6d1d8f66e0 Organize the ANSI codes and add missing colors
For consistency.
2018-03-02 08:58:02 +01:00
Lennart Poettering 7b91264852 terminal-util: make resolve_dev_console() less weird
Let's normalize the behaviour: return a negative errno style error code,
and return the resolved string directly as argument.
2018-02-14 17:30:37 +01:00
Lennart Poettering bef41af233 terminal-util: modernize get_kernel_consoles() a bit
Also, make sure when we run in a container, we don't use the data from
/sys at all, but immediately fall back to /dev/console itself.
2018-02-14 14:56:17 +01:00
Lennart Poettering c2b3215941 tty-ask-password-agent: reenable color for boot-time password prompt
The password prompt used to be highlighted, and that was a good thing.
Let's fix things to make the prompt highlighted again.

Fixes: #3853
2018-02-14 14:30:30 +01:00
Lennart Poettering c6063244db terminal-util: when making /dev/null or the console stdio, forget cached terminal features
Let's forget all relevant terminal features we learnt when we make a
console or /dev/null stdin/stdout/stderr.

Also, while we are at it, let's drop the various _unlikely_ and
_likely_ annotiations around the terminal feature caches. In many cases
we call the relevant functions only once in which cases the annotations
are likely to do just harm and no good. After all we can't know if the
specific code will call us just once or many times...
2018-02-13 23:50:26 +01:00
Lennart Poettering 8854d79504 terminal-util: rework acquire_terminal()
This modernizes acquire_terminal() in a couple of ways:

1. The three boolean arguments are replaced by a flags parameter, that
   should be more descriptive in what it does.

2. We now properly handle inotify queue overruns

3. We use _cleanup_ for closing the fds now, to shorten the code quite a
   bit.

Behaviour should not be altered by this.
2018-02-13 21:24:37 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Lennart Poettering 526664f627 systemctl: don't do ANSI underlining on TERM=linux (#6778)
The linux console apparently can't do underlining, hence let's not do it
on the console.

Also see: #6601
2017-09-09 22:48:35 +02:00
Lennart Poettering c83f349c5f terminal: unify code for resetting kbd utf8 mode a bit (#6692)
We have the same code at two places, let's unify that at one place.

Follow-up for #6606
2017-09-01 09:09:32 +09:00
Zbigniew Jędrzejewski-Szmek 5c98198f67 terminal-util: helper macro for highlighting functions 2016-10-17 11:48:12 -04:00
Zbigniew Jędrzejewski-Szmek 16484a8a15 systemctl: use underlines to seperate unit types in listing
(printf("%.*s", -1, "…") is the same as not specifying the precision at all.)

v2: also underline highlighted (failing) units

Fixes #4137.
2016-10-17 11:37:41 -04:00
Lennart Poettering ac96418b4f pager: don't start pager if the terminal is explicitly set to TERM=dumb
As suggested here:

https://bugs.freedesktop.org/show_bug.cgi?id=64737#c8

This adds a new call terminal_is_dumb() and makes use of this where
appropriate.
2016-05-30 18:23:54 +02:00
Werner Fink 6af621248f ask-password: ask for passphrases not only on the first console of /dev/console
but also on all other consoles.  This does help on e.g. mainframes
where often a serial console together with other consoles are
used.  Even rack based servers attachted to both a serial console
as well as having a virtual console do sometimes miss a connected
monitor.

To be able to ask on all terminal devices of /dev/console the devices
are collected. If more than one device are found, then on each of the
terminals a inquiring task for passphrase is forked and do not return
to the caller.

Every task has its own session and its own controlling terminal.
If one of the tasks does handle a password, the remaining tasks
will be terminated.

Also let contradictory options on the command of
systemd-tty-ask-password-agent fail.

Spwan for each device of the system console /dev/console a own process.
Replace the system call wait() with with system call waitid().
Use SIGTERM instead of SIGHUP to get unresponsive childs down.

Port the collect_consoles() function forward to a pulbic and strv
based function "get_kernel_consoles()" in terminal-util.c and use this
in tty-ask-password-agent.c.
2016-05-24 11:57:27 +02:00