mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
terminal-util: rename set_terminal_cursor_position() → terminal_set_cursor_position()
Let's prefix these functions with the subsystem name, and clean them up a bit. Specifically, drop the error logging, it's entirely duplicative, since every single caller does it anyway.
This commit is contained in:
parent
445e57387e
commit
53f0ab5151
@ -1522,19 +1522,13 @@ void get_log_colors(int priority, const char **on, const char **off, const char
|
||||
}
|
||||
}
|
||||
|
||||
int set_terminal_cursor_position(int fd, unsigned int row, unsigned int column) {
|
||||
int r;
|
||||
char cursor_position[STRLEN("\x1B[") + DECIMAL_STR_MAX(int) * 2 + STRLEN(";H") + 1];
|
||||
|
||||
int terminal_set_cursor_position(int fd, unsigned row, unsigned column) {
|
||||
assert(fd >= 0);
|
||||
|
||||
char cursor_position[STRLEN("\x1B[" ";" "H") + DECIMAL_STR_MAX(unsigned) * 2 + 1];
|
||||
xsprintf(cursor_position, "\x1B[%u;%uH", row, column);
|
||||
|
||||
r = loop_write(fd, cursor_position, SIZE_MAX);
|
||||
if (r < 0)
|
||||
return log_warning_errno(r, "Failed to set cursor position, ignoring: %m");
|
||||
|
||||
return 0;
|
||||
return loop_write(fd, cursor_position, SIZE_MAX);
|
||||
}
|
||||
|
||||
int terminal_reset_ansi_seq(int fd) {
|
||||
|
@ -97,9 +97,10 @@ bool isatty_safe(int fd);
|
||||
|
||||
int reset_terminal_fd(int fd, bool switch_to_text);
|
||||
int reset_terminal(const char *name);
|
||||
int set_terminal_cursor_position(int fd, unsigned int row, unsigned int column);
|
||||
int terminal_reset_ansi_seq(int fd);
|
||||
|
||||
int terminal_set_cursor_position(int fd, unsigned row, unsigned column);
|
||||
|
||||
int open_terminal(const char *name, int mode);
|
||||
|
||||
/* Flags for tweaking the way we become the controlling process of a terminal. */
|
||||
|
@ -185,7 +185,7 @@ static int display_emergency_message_fullscreen(const char *message) {
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to clear terminal, ignoring: %m");
|
||||
|
||||
r = set_terminal_cursor_position(fd, 2, 4);
|
||||
r = terminal_set_cursor_position(fd, 2, 4);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m");
|
||||
|
||||
@ -197,7 +197,7 @@ static int display_emergency_message_fullscreen(const char *message) {
|
||||
|
||||
qr_code_start_row = w.ws_row * 3U / 5U;
|
||||
qr_code_start_column = w.ws_col * 3U / 4U;
|
||||
r = set_terminal_cursor_position(fd, 4, 4);
|
||||
r = terminal_set_cursor_position(fd, 4, 4);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m");
|
||||
|
||||
@ -217,7 +217,7 @@ static int display_emergency_message_fullscreen(const char *message) {
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "QR code could not be printed, ignoring: %m");
|
||||
|
||||
r = set_terminal_cursor_position(fd, w.ws_row - 1, w.ws_col * 2U / 5U);
|
||||
r = terminal_set_cursor_position(fd, w.ws_row - 1, w.ws_col * 2U / 5U);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m");
|
||||
|
||||
|
@ -52,7 +52,7 @@ static void print_border(FILE *output, unsigned width, unsigned row, unsigned co
|
||||
if (fd < 0)
|
||||
return (void)log_debug_errno(errno, "Failed to get file descriptor from the file stream: %m");
|
||||
|
||||
r = set_terminal_cursor_position(fd, row, column);
|
||||
r = terminal_set_cursor_position(fd, row, column);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m");
|
||||
|
||||
@ -64,7 +64,7 @@ static void print_border(FILE *output, unsigned width, unsigned row, unsigned co
|
||||
fputs(UNICODE_FULL_BLOCK, output);
|
||||
|
||||
fputs(ANSI_NORMAL "\n", output);
|
||||
r = set_terminal_cursor_position(fd, row + 1, column);
|
||||
r = terminal_set_cursor_position(fd, row + 1, column);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m");
|
||||
}
|
||||
@ -96,7 +96,7 @@ static void write_qrcode(FILE *output, QRcode *qr, unsigned int row, unsigned in
|
||||
if (fd < 0)
|
||||
return (void)log_debug_errno(errno, "Failed to get file descriptor from the file stream: %m");
|
||||
|
||||
r = set_terminal_cursor_position(fd, row + move_down, column);
|
||||
r = terminal_set_cursor_position(fd, row + move_down, column);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m");
|
||||
|
||||
@ -127,7 +127,7 @@ static void write_qrcode(FILE *output, QRcode *qr, unsigned int row, unsigned in
|
||||
|
||||
for (unsigned x = 0; x < 4; x++)
|
||||
fputs(UNICODE_FULL_BLOCK, output);
|
||||
r = set_terminal_cursor_position(fd, row + move_down, column);
|
||||
r = terminal_set_cursor_position(fd, row + move_down, column);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m");
|
||||
move_down += 1;
|
||||
@ -206,7 +206,7 @@ int print_qrcode_full(FILE *out, const char *header, const char *string, unsigne
|
||||
row = tty_height - (qr_code_height / 2 ) - 1;
|
||||
|
||||
if (header) {
|
||||
r = set_terminal_cursor_position(fd, row - 2, tty_width - qr_code_width - 2);
|
||||
r = terminal_set_cursor_position(fd, row - 2, tty_width - qr_code_width - 2);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to move terminal cursor position, ignoring: %m");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user