summaryrefslogtreecommitdiffstats
path: root/src/pacman/util.c
diff options
context:
space:
mode:
authorAnatol Pomozov <anatol.pomozov@gmail.com>2020-03-09 19:54:17 +0100
committerAllan McRae <allan@archlinux.org>2020-03-13 02:24:01 +0100
commit87b74fcd8257e3c2fbf2f2949f0561df7517ce71 (patch)
tree2140c27642963ee12c57d238a1a46f4e85de139d /src/pacman/util.c
parentddd5b0a462e7beb0e086bb51184934868ded3525 (diff)
downloadpacman-87b74fcd8257e3c2fbf2f2949f0561df7517ce71.tar.gz
pacman-87b74fcd8257e3c2fbf2f2949f0561df7517ce71.tar.xz
Hide cursor while pacman is running
Use ASCII control codes to hide cursor at the pacman start and then show the cursor when pacman finishes. It helps to avoid annoying blinking when progress bars are re-drawn. Cursor is reenabled if pacman expects user's input. Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src/pacman/util.c')
-rw-r--r--src/pacman/util.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c
index a640ffb4..a3a85bb9 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -1391,6 +1391,27 @@ static int multiselect_parse(char *array, int count, char *response)
return 0;
}
+void console_cursor_hide(void) {
+ if(isatty(fileno(stdout))) {
+ printf(CURSOR_HIDE_ANSICODE);
+ }
+}
+
+void console_cursor_show(void) {
+ if(isatty(fileno(stdout))) {
+ printf(CURSOR_SHOW_ANSICODE);
+ }
+}
+
+char *safe_fgets_stdin(char *s, int size)
+{
+ char *result;
+ console_cursor_show();
+ result = safe_fgets(s, size, stdin);
+ console_cursor_hide();
+ return result;
+}
+
int multiselect_question(char *array, int count)
{
char *response, *lastchar;
@@ -1427,7 +1448,7 @@ int multiselect_question(char *array, int count)
flush_term_input(fileno(stdin));
- if(safe_fgets(response, response_len, stdin)) {
+ if(safe_fgets_stdin(response, response_len)) {
const size_t response_incr = 64;
size_t len;
/* handle buffer not being large enough to read full line case */
@@ -1443,8 +1464,8 @@ int multiselect_question(char *array, int count)
lastchar = response + response_len - 1;
/* sentinel byte */
*lastchar = 1;
- if(safe_fgets(response + response_len - response_incr - 1,
- response_incr + 1, stdin) == 0) {
+ if(safe_fgets_stdin(response + response_len - response_incr - 1,
+ response_incr + 1) == 0) {
free(response);
return -1;
}
@@ -1494,7 +1515,7 @@ int select_question(int count)
flush_term_input(fileno(stdin));
- if(safe_fgets(response, sizeof(response), stdin)) {
+ if(safe_fgets_stdin(response, sizeof(response))) {
size_t len = strtrim(response);
if(len > 0) {
int n;
@@ -1582,7 +1603,7 @@ static int question(short preset, const char *format, va_list args)
flush_term_input(fd_in);
- if(safe_fgets(response, sizeof(response), stdin)) {
+ if(safe_fgets_stdin(response, sizeof(response))) {
size_t len = strtrim(response);
if(len == 0) {
return preset;