Changeset c3db721 in mainline for uspace/app/newfile


Ignore:
Timestamp:
2025-10-10T20:35:05Z (5 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
c1383cd
Parents:
0cf3d5f
Message:

Allow aborting file management operation.

Location:
uspace/app/newfile
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/newfile/meson.build

    r0cf3d5f rc3db721  
    2727#
    2828
    29 deps = [ 'fmgt' ]
     29deps = [ 'console', 'fmgt', 'input' ]
    3030src = files('newfile.c')
  • uspace/app/newfile/newfile.c

    r0cf3d5f rc3db721  
    3636#include <errno.h>
    3737#include <fmgt.h>
     38#include <io/console.h>
     39#include <io/cons_event.h>
     40#include <io/kbd_event.h>
    3841#include <stdbool.h>
    3942#include <stdio.h>
     
    4447#define NAME  "newfile"
    4548
     49static bool newfile_abort_query(void *);
    4650static void newfile_progress(void *, fmgt_progress_t *);
    4751
     
    4953static bool quiet = false;
    5054
     55static console_ctrl_t *con;
     56
    5157static fmgt_cb_t newfile_fmgt_cb = {
     58        .abort_query = newfile_abort_query,
    5259        .progress = newfile_progress
    5360};
     
    6269        printf("\t-q           quiet\n");
    6370        printf("\t-size=<cap>  file size (<number>[<kB>|<MB>|...])\n");
     71}
     72
     73/** Called by fmgt to query for user abort.
     74 *
     75 * @param arg Argument (not used)
     76 * @return @c true iff user requested abort
     77 */
     78static bool newfile_abort_query(void *arg)
     79{
     80        cons_event_t event;
     81        kbd_event_t *ev;
     82        errno_t rc;
     83        usec_t timeout;
     84
     85        if (con == NULL)
     86                return false;
     87
     88        timeout = 0;
     89        rc = console_get_event_timeout(con, &event, &timeout);
     90        if (rc != EOK)
     91                return false;
     92
     93        if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) {
     94                ev = &event.ev.key;
     95                if ((ev->mods & KM_ALT) == 0 &&
     96                    (ev->mods & KM_SHIFT) == 0 &&
     97                    (ev->mods & KM_CTRL) != 0) {
     98                        if (ev->key == KC_C)
     99                                return true;
     100                }
     101        }
     102
     103        return false;
    64104}
    65105
     
    93133        uint64_t nbytes = 0;
    94134
     135        con = console_init(stdin, stdout);
     136
    95137        i = 1;
    96138        while (i < argc && argv[i][0] == '-') {
     
    167209
    168210        rc = fmgt_new_file(fmgt, fname, nbytes, sparse ? nf_sparse : nf_none);
     211        if (prog_upd)
     212                printf("\n");
    169213        if (rc != EOK) {
    170214                printf("Error creating file: %s.\n", str_error(rc));
    171215                goto error;
    172216        }
    173 
    174         if (prog_upd)
    175                 printf("\n");
    176217
    177218        free(fname);
Note: See TracChangeset for help on using the changeset viewer.