text: /*
   * MIT License
   *
   * Copyright (c) 2022 Michael Shaw
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy
   * of this software and associated documentation files (the "Software"), to deal
   * in the Software without restriction, including without limitation the rights
   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   * copies of the Software, and to permit persons to whom the Software is
   * furnished to do so, subject to the following conditions:
   *
   * The above copyright notice and this permission notice shall be included in
   * all copies or substantial portions of the Software.
   *
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   * SOFTWARE.
   *
   */
  
  #include <sys/stat.h>
  
  #include "filebox.h"
  #include "util.h"
  
  time_t
  filebox_mtime_sec(char *filename)
  {
      struct stat fbd_stat;
      if (stat(filename, &fbd_stat))
      {
          return 0;
      }
      return fbd_stat.st_mtime;
  }
  
  void
  filebox_progressbar_init(struct filebox_state *state)
  {
      printf("\n");
      printf("\0337");
      printf("\033[0;%dr", state->t_cols - 1);
      printf("\0338");
      printf("\033[1A");
      printf("\033[?25l");
  }
  
  void
  filebox_progressbar_update(struct filebox_state *state, float now, float total)
  {
      printf("\0337");
      printf("\033[%d;0f", state->t_rows - 1);
      printf("%.2f of %.2f MB so far, %.2f%c",
             (now) / (1U << 19),
             (total) / (1U << 19),
             ((now) / (total)) * 100.0f,
             '%');
      printf("\0338");
  }
  
  void
  filebox_progressbar_end(struct filebox_state *state)
  {
      printf("\0337");
      printf("\033[0;%dr", state->t_cols);
      printf("\033[%d;0f", state->t_cols);
      printf("\033[0K");
      printf("\0338");
      printf("\033[?25h");
      printf("\n\n");
  }
  