Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src/pacman/callback.c
diff options
context:
space:
mode:
authorAnatol Pomozov <anatol.pomozov@gmail.com>2020-11-03 17:04:38 -0800
committerAllan McRae <allan@archlinux.org>2020-11-26 16:10:26 +1000
commitdb4092e33dacc6a0bb8afd283a82e6f4327cb865 (patch)
treefe41f19f74250430a985311920a1ae7d1d4d1f27 /src/pacman/callback.c
parent2859a6eefcb465a382267c6e5981192c6a54f5bb (diff)
Move cursor to the end of the screen at the SIGINT
It requires exposing 'move cursor to the end' function in a pacman header file. We use it as a chance to make naming of the cursor management functions more consistent. Note that there is still possibility of a race condition in the cursor update logic. 'update cursor index variable' and 'send ASCII control symbols to console' is not an atomic operation. So if an SIGINT is received between these two action then cursor position is going to be screwed. Fixes FS#67973 Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src/pacman/callback.c')
-rw-r--r--src/pacman/callback.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 53518101..12ab952f 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -92,8 +92,6 @@ struct pacman_multibar_ui {
struct pacman_multibar_ui multibar_ui = {0};
-static void cursor_goto_end(void);
-
void multibar_move_completed_up(bool value) {
multibar_ui.move_completed_up = value;
}
@@ -226,7 +224,7 @@ static int number_length(size_t n)
void cb_event(alpm_event_t *event)
{
if(config->print) {
- cursor_goto_end();
+ console_cursor_move_end();
return;
}
switch(event->type) {
@@ -389,7 +387,7 @@ void cb_event(alpm_event_t *event)
case ALPM_EVENT_DB_RETRIEVE_FAILED:
case ALPM_EVENT_PKG_RETRIEVE_DONE:
case ALPM_EVENT_PKG_RETRIEVE_FAILED:
- cursor_goto_end();
+ console_cursor_move_end();
flush_output_list();
on_progress = 0;
break;
@@ -694,7 +692,7 @@ static int dload_progressbar_enabled(void)
}
/* Goto the line that corresponds to num-th active download */
-static void cursor_goto_bar(int num)
+static void console_cursor_goto_bar(int num)
{
if(num > multibar_ui.cursor_lineno) {
console_cursor_move_down(num - multibar_ui.cursor_lineno);
@@ -705,9 +703,9 @@ static void cursor_goto_bar(int num)
}
/* Goto the line *after* the last active progress bar */
-static void cursor_goto_end(void)
+void console_cursor_move_end(void)
{
- cursor_goto_bar(multibar_ui.active_downloads_num);
+ console_cursor_goto_bar(multibar_ui.active_downloads_num);
}
/* Returns true if element with the specified name is found, false otherwise */
@@ -849,7 +847,7 @@ static void dload_init_event(const char *filename, alpm_download_event_init_t *d
bar->rate = 0.0;
multibar_ui.active_downloads = alpm_list_add(multibar_ui.active_downloads, bar);
- cursor_goto_end();
+ console_cursor_move_end();
printf(_(" %s downloading...\n"), filename);
multibar_ui.cursor_lineno++;
multibar_ui.active_downloads_num++;
@@ -894,7 +892,7 @@ static void dload_progress_event(const char *filename, alpm_download_event_progr
bar->total_size = data->total;
bar->xfered = data->downloaded;
- cursor_goto_bar(index);
+ console_cursor_goto_bar(index);
draw_pacman_progress_bar(bar);
fflush(stdout);
}
@@ -920,7 +918,7 @@ static void dload_complete_event(const char *filename, alpm_download_event_compl
bar->total_size = data->total;
if(data->result == 1) {
- cursor_goto_bar(index);
+ console_cursor_goto_bar(index);
printf(_(" %s is up to date"), bar->filename);
/* The line contains text from previous status. Erase these leftovers. */
console_erase_line();
@@ -947,16 +945,16 @@ static void dload_complete_event(const char *filename, alpm_download_event_compl
multibar_ui.active_downloads->data = bar;
baritem->data = former_topbar;
- cursor_goto_bar(index);
+ console_cursor_goto_bar(index);
draw_pacman_progress_bar(former_topbar);
index = 0;
}
- cursor_goto_bar(index);
+ console_cursor_goto_bar(index);
draw_pacman_progress_bar(bar);
} else {
- cursor_goto_bar(index);
+ console_cursor_goto_bar(index);
printf(_(" %s failed to download"), bar->filename);
console_erase_line();
}