]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/basic/terminal-util.h
terminal-util: introduce vt_restore() helper
[thirdparty/systemd.git] / src / basic / terminal-util.h
index d60956455b9655161007ee468c8339e46d24cf34..2d931114e498e1fb358683809123a4dc4ee41216 100644 (file)
@@ -1,12 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 #pragma once
 
-/***
-  This file is part of systemd.
-
-  Copyright 2010 Lennart Poettering
-***/
-
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -56,6 +50,9 @@
 /* Erase characters until the end of the line */
 #define ANSI_ERASE_TO_END_OF_LINE "\x1B[K"
 
+/* Move cursor up one line */
+#define ANSI_REVERSE_LINEFEED "\x1BM"
+
 /* Set cursor to top left corner and clear screen */
 #define ANSI_HOME_CLEAR "\x1B[H\x1B[2J"
 
@@ -67,16 +64,16 @@ int open_terminal(const char *name, int mode);
 /* Flags for tweaking the way we become the controlling process of a terminal. */
 typedef enum AcquireTerminalFlags {
         /* Try to become the controlling process of the TTY. If we can't return -EPERM. */
-        ACQUIRE_TERMINAL_TRY = 0,
+        ACQUIRE_TERMINAL_TRY        = 0,
 
         /* Tell the kernel to forcibly make us the controlling process of the TTY. Returns -EPERM if the kernel doesn't allow that. */
-        ACQUIRE_TERMINAL_FORCE = 1,
+        ACQUIRE_TERMINAL_FORCE      = 1,
 
         /* If we can't become the controlling process of the TTY right-away, then wait until we can. */
-        ACQUIRE_TERMINAL_WAIT = 2,
+        ACQUIRE_TERMINAL_WAIT       = 2,
 
         /* Pick one of the above, and then OR this flag in, in order to request permissive behaviour, if we can't become controlling process then don't mind */
-        ACQUIRE_TERMINAL_PERMISSIVE = 4,
+        ACQUIRE_TERMINAL_PERMISSIVE = 1 << 2,
 } AcquireTerminalFlags;
 
 int acquire_terminal(const char *name, AcquireTerminalFlags flags, usec_t timeout);
@@ -133,6 +130,7 @@ DEFINE_ANSI_FUNC(highlight_red,              HIGHLIGHT_RED);
 DEFINE_ANSI_FUNC(highlight_green,            HIGHLIGHT_GREEN);
 DEFINE_ANSI_FUNC(highlight_yellow,           HIGHLIGHT_YELLOW);
 DEFINE_ANSI_FUNC(highlight_blue,             HIGHLIGHT_BLUE);
+DEFINE_ANSI_FUNC(highlight_magenta,          HIGHLIGHT_MAGENTA);
 DEFINE_ANSI_FUNC(normal,                     NORMAL);
 
 DEFINE_ANSI_FUNC_UNDERLINE(underline,                  UNDERLINE, NORMAL);
@@ -156,3 +154,4 @@ int open_terminal_in_namespace(pid_t pid, const char *name, int mode);
 
 int vt_default_utf8(void);
 int vt_reset_keyboard(int fd);
+int vt_restore(int fd);