Example #1
0
static void rm_fmt_progress_print_bar(RmSession *session, RmFmtHandlerProgress *self, int width, FILE *out) {
    int cells = width * self->percent;

    /* true when we do not know when 100% is reached.
     * Show a moving something in this case.
     * */
    bool is_unknown = self->percent > 1.1;


    fprintf(out, "[");
    for(int i = 0; i < width - 2; ++i) {
        if(i < cells) {
            if(is_unknown) {
                if((int)self->last_unknown_pos % 4 == i % 4) {
                    fprintf(out, "%so%s", MAYBE_BLUE(session), MAYBE_RESET(session));
                } else if((int)self->last_unknown_pos % 2 == i % 2) {
                    fprintf(out, "%sO%s", MAYBE_YELLOW(session), MAYBE_RESET(session));
                } else {
                    fprintf(out, " ");
                }
            } else {
                fprintf(out, "#");
            }
        } else if(i == cells) {
            fprintf(out, "%s>%s", MAYBE_YELLOW(session), MAYBE_RESET(session));
        } else {
            fprintf(out, "%s-%s", MAYBE_BLUE(session), MAYBE_RESET(session));
        }
    }
    fprintf(out, "]");

    self->last_unknown_pos = fmod(self->last_unknown_pos + 0.005, width - 2);
}
Example #2
0
static void rm_fmt_elem(_U RmSession *session, RmFmtHandler *parent, FILE *out,
                        RmFile *file) {
    RmFmtHandlerProgress *self = (RmFmtHandlerProgress *)parent;

    if(file->lint_type == RM_LINT_TYPE_UNIQUE_FILE) {
        /* pretty output should not contain this */
        return;
    }

    self->elems_written++;

    if(file->lint_type != self->last_lint_type) {
        fprintf(out, "\n%s#%s %s:\n", MAYBE_YELLOW(out, session),
                MAYBE_RESET(out, session),
                _(RM_LINT_TYPE_TO_DESCRIPTION[file->lint_type]));
        self->last_lint_type = file->lint_type;
    }

    fprintf(out, "    %s", rm_fmt_command_color(session, file, out));

    const char *format = RM_LINT_TYPE_TO_COMMAND[file->lint_type];
    switch(file->lint_type) {
    case RM_LINT_TYPE_BADUID:
        fprintf(out, format, self->user);
        break;
    case RM_LINT_TYPE_BADGID:
        fprintf(out, format, self->group);
        break;
    case RM_LINT_TYPE_BADUGID:
        fprintf(out, format, self->user, self->group);
        break;
    case RM_LINT_TYPE_DUPE_CANDIDATE:
        if(file->is_original) {
            fprintf(out, "ls");
        } else {
            fprintf(out, "%s", format);
        }
        break;
    case RM_LINT_TYPE_DUPE_DIR_CANDIDATE:
        if(file->is_original) {
            fprintf(out, "ls -la");
        } else {
            fprintf(out, "%s", format);
        }
        break;
    default:
        fprintf(out, "%s", format);
    }

    RM_DEFINE_PATH(file);
    char *esc_path = rm_util_strsub(file_path, "'", "'\"'\"'");
    fprintf(out, "%s '%s'\n", MAYBE_RESET(out, session), esc_path);
    g_free(esc_path);
}
Example #3
0
static void rm_fmt_elem(_U RmSession *session, RmFmtHandler *parent, FILE *out, RmFile *file) {
    RmFmtHandlerProgress *self = (RmFmtHandlerProgress *) parent;
    self->elems_written++;

    if(file->lint_type != self->last_lint_type) {
        fprintf(
            out, "\n%s#%s %s:\n",
            MAYBE_YELLOW(session),
            MAYBE_RESET(session),
            _(RM_LINT_TYPE_TO_DESCRIPTION[file->lint_type])
        );
        self->last_lint_type = file->lint_type;
    }

    fprintf(out, "    %s", rm_fmt_command_color(session, file));

    const char *format = RM_LINT_TYPE_TO_COMMAND[file->lint_type];

    switch(file->lint_type) {
    case RM_LINT_TYPE_BADUID:
        fprintf(out, format, self->user);
        break;
    case RM_LINT_TYPE_BADGID:
        fprintf(out, format, self->group);
        break;
    case RM_LINT_TYPE_BADUGID:
        fprintf(out, format, self->user, self->group);
        break;
    case RM_LINT_TYPE_DUPE_CANDIDATE:
        if(file->is_original) {
            fprintf(out, "ls");
        } else {
            fprintf(out, "%s", format);
        }
        break;
    case RM_LINT_TYPE_DUPE_DIR_CANDIDATE:
        if(file->is_original) {
            fprintf(out, "ls -la");
        } else {
            fprintf(out, "%s", format);
        }
        break;
    default:
        fprintf(out, "%s", format);
    }

    fprintf(out, "%s %s\n", MAYBE_RESET(session), file->path);
}
Example #4
0
static void rm_fmt_progress_format_text(RmSession *session, RmFmtHandlerProgress *self,
                                        int max_len, FILE *out) {
    /* This is very ugly, but more or less required since we need to translate
     * the text to different languages and still determine the right textlength.
     */

    char num_buf[32] = {0};
    char preproc_buf[128] = {0};
    memset(num_buf, 0, sizeof(num_buf));
    memset(preproc_buf, 0, sizeof(preproc_buf));

    switch(self->last_state) {
    case RM_PROGRESS_STATE_TRAVERSE:
        self->percent = 2.0;
        self->text_len = g_snprintf(
            self->text_buf, sizeof(self->text_buf), "%s (%s%d%s %s / %s%d%s + %s%d%s %s)",
            _("Traversing"), MAYBE_GREEN(out, session), session->total_files,
            MAYBE_RESET(out, session), _("usable files"), MAYBE_RED(out, session),
            session->ignored_files, MAYBE_RESET(out, session), MAYBE_RED(out, session),
            session->ignored_folders, MAYBE_RESET(out, session),
            _("ignored files / folders"));
        break;
    case RM_PROGRESS_STATE_PREPROCESS:
        self->percent = 2.0;
        rm_fmt_progress_format_preprocess(session, preproc_buf, sizeof(preproc_buf), out);
        self->text_len = g_snprintf(
            self->text_buf, sizeof(self->text_buf), "%s (%s / %s %s%" LLU "%s %s)",
            _("Preprocessing"), preproc_buf, _("found"), MAYBE_RED(out, session),
            session->other_lint_cnt, MAYBE_RESET(out, session), _("other lint"));
        break;
    case RM_PROGRESS_STATE_SHREDDER:
        self->percent = 1.0 - ((gdouble)session->shred_bytes_remaining /
                               (gdouble)session->shred_bytes_after_preprocess);
        rm_util_size_to_human_readable(session->shred_bytes_remaining, num_buf,
                                       sizeof(num_buf));
        self->text_len = g_snprintf(
            self->text_buf, sizeof(self->text_buf),
            "%s (%s%" LLU "%s %s %s%" LLU "%s %s; %s%s%s %s %s%" LLU "%s %s)",
            _("Matching"), MAYBE_RED(out, session), session->dup_counter,
            MAYBE_RESET(out, session), _("dupes of"), MAYBE_YELLOW(out, session),
            session->dup_group_counter, MAYBE_RESET(out, session), _("originals"),
            MAYBE_GREEN(out, session), num_buf, MAYBE_RESET(out, session),
            _("to scan in"), MAYBE_GREEN(out, session), session->shred_files_remaining,
            MAYBE_RESET(out, session), _("files"));
        break;
    case RM_PROGRESS_STATE_MERGE:
        self->percent = 1.0;
        self->text_len = g_snprintf(self->text_buf, sizeof(self->text_buf),
                                    _("Merging files into directories (stand by...)"));
        break;
    case RM_PROGRESS_STATE_INIT:
    case RM_PROGRESS_STATE_PRE_SHUTDOWN:
    case RM_PROGRESS_STATE_SUMMARY:
    default:
        self->percent = 0;
        memset(self->text_buf, 0, sizeof(self->text_buf));
        break;
    }

    /* Support unicode messages - tranlsated text might contain some. */
    self->text_len = g_utf8_strlen(self->text_buf, self->text_len);

    /* Get rid of colors to get the correct length of the text. This is
     * necessary to correctly guess the length of the displayed text in cells.
     */
    int text_iter = 0;
    for(char *iter = &self->text_buf[0]; *iter; iter++) {
        if(*iter == '\x1b') {
            char *jump = strchr(iter, 'm');
            if(jump != NULL) {
                self->text_len -= jump - iter + 1;
                iter = jump;
                continue;
            }
        }

        if(text_iter >= max_len) {
            *iter = 0;
            self->text_len = text_iter;
            break;
        }

        text_iter++;
    }
}
Example #5
0
static void rm_fmt_progress_format_text(RmSession *session, RmFmtHandlerProgress *self, int max_len) {
    char num_buf[32] = {0};
    memset(num_buf, 0, sizeof(num_buf));

    switch(self->last_state) {
    case RM_PROGRESS_STATE_TRAVERSE:
        self->percent = 2.0;
        self->text_len = g_snprintf(
                             self->text_buf, sizeof(self->text_buf),
                             "%s (%s%"LLU"%s %s / %s%"LLU"%s + %s%"LLU"%s %s)",
                             _("Traversing"),
                             MAYBE_GREEN(session), session->total_files, MAYBE_RESET(session),
                             _("usable files"),
                             MAYBE_RED(session), session->ignored_files, MAYBE_RESET(session),
                             MAYBE_RED(session), session->ignored_folders, MAYBE_RESET(session),
                             _("ignored files / folders")
                         );
        break;
    case RM_PROGRESS_STATE_PREPROCESS:
        self->percent = 2.0;
        self->text_len = g_snprintf(
                             self->text_buf, sizeof(self->text_buf),
                             "%s (%s %s%"LLU"%s / %s %s%"LLU"%s %s)",
                             _("Preprocessing"),
                             _("reduces files to"),
                             MAYBE_GREEN(session), session->total_filtered_files, MAYBE_RESET(session),
                             _("found"),
                             MAYBE_RED(session), session->other_lint_cnt, MAYBE_RESET(session),
                             _("other lint")
                         );
        break;
    case RM_PROGRESS_STATE_SHREDDER:
        self->percent = 1.0 - ((gdouble)session->shred_files_remaining) / ((gdouble)session->total_filtered_files);
        rm_util_size_to_human_readable(session->shred_bytes_remaining, num_buf, sizeof(num_buf));
        self->text_len = g_snprintf(
                             self->text_buf, sizeof(self->text_buf),
                             "%s (%s%"LLU"%s %s %s%"LLU"%s %s; %s%s%s %s %s%"LLU"%s %s)",
                             _("Matching files"),
                             MAYBE_RED(session), session->dup_counter, MAYBE_RESET(session),
                             _("dupes of"),
                             MAYBE_YELLOW(session), session->dup_group_counter, MAYBE_RESET(session),
                             _("originals"),
                             MAYBE_GREEN(session), num_buf, MAYBE_RESET(session),
                             _("to scan in "),
                             MAYBE_GREEN(session), session->shred_files_remaining, MAYBE_RESET(session),
                             _("files")
                         );
        break;
    case RM_PROGRESS_STATE_MERGE:
        self->percent = 2.0;
        self->text_len = g_snprintf(self->text_buf, sizeof(self->text_buf),
                                    _("Merging files into directories (stand by...)"));
        break;
    case RM_PROGRESS_STATE_INIT:
    case RM_PROGRESS_STATE_SUMMARY:
    default:
        self->percent = 0;
        memset(self->text_buf, 0, sizeof(self->text_buf));
        break;
    }

    /* Get rid of colors */
    int text_iter = 0;
    for(char *iter = &self->text_buf[0]; *iter; iter++) {
        if(*iter == '\x1b') {
            char *jump = strchr(iter, 'm');
            if(jump != NULL) {
                self->text_len -= jump - iter + 1;
                iter = jump;
                continue;
            }
        }

        if(text_iter >= max_len) {
            *iter = 0;
            self->text_len = text_iter;
            break;
        }

        text_iter++;
    }
}