mc Digest, Vol 116, Issue 6

Mike Smithson mdooligan at gmail.com
Fri Dec 20 00:46:36 UTC 2013


On Thu, 19 Dec 2013 04:00:03 -0800, <mc-request at gnome.org> wrote:

> Message: 1
> Date: Thu, 19 Dec 2013 00:02:38 +0100
> From: Konrad Vrba <konrad.vrba at gmail.com>
> To: mc at gnome.org
> Subject: disk usage status in right bottom corner
> Message-ID:
> 	<CAF2Nc0zH_Ew_tbEm44ZS9mJiUiqL0A=iYeV1MaJ6krTtYQuefA at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> hello,
>
> I would like to ask whether it is possible to change the disk  
> status/usage
> information, which is displayed in the botom right corner in midnight
> commander (sorry if I am not using the correct terminology).
>
> The information displayed in my MC is free/total free%
>
> I would prefer to have % of used space, rather than % of free space. It
> might seem trivial, but I canot get used to the idea and it still  
> confuses
> me. It seems to me logical to see what *is*on my disk, rather than what  
> *is
> not*.
>
> Is there some way to adjust this, so that I can for example see just the
> %usage ?
>
> thanks,
> Konrad

You know, that confused me too. It shows free space instead of used space.
df shows size used avail and use%, but mc shows avail/size (free%).

Once again, src/filemanager/panels.c being hacked, around line 1111:
[code]
static void
show_free_space (WPanel * panel)
{
     /* Used to figure out how many free space we have */
     static struct my_statfs myfs_stats;
     /* Old current working directory for displaying free space */
     static char *old_cwd = NULL;

     /* Don't try to stat non-local fs */
     if (!vfs_file_is_local (panel->cwd_vpath) || !free_space)
         return;

     if (old_cwd == NULL || strcmp (old_cwd, vfs_path_as_str  
(panel->cwd_vpath)) != 0)
     {
         char rpath[PATH_MAX];

         init_my_statfs ();
         g_free (old_cwd);
         old_cwd = g_strdup (vfs_path_as_str (panel->cwd_vpath));

         if (mc_realpath (old_cwd, rpath) == NULL)
             return;

         my_statfs (&myfs_stats, rpath);
     }

     if (myfs_stats.avail != 0 || myfs_stats.total != 0)
     {
         Widget *w = WIDGET (panel);
         char buffer1[6], buffer2[6], tmp[BUF_SMALL];

         size_trunc_len (buffer1, sizeof (buffer1) - 1, myfs_stats.avail, 1,
                         panels_options.kilobyte_si);
         size_trunc_len (buffer2, sizeof (buffer2) - 1, myfs_stats.total, 1,
                         panels_options.kilobyte_si);
         g_snprintf (tmp, sizeof (tmp), " %s/%s (%d%%) ", buffer1, buffer2,
                     myfs_stats.total == 0 ? 0 :
                     (int) (100 * (long double) myfs_stats.avail /  
myfs_stats.total));
         widget_move (w, w->lines - 1, w->cols - 2 - (int) strlen (tmp));
         tty_setcolor (NORMAL_COLOR);
         tty_print_string (tmp);
     }
}
[/code]
First, I'd rename the func to panel_show_disk_usage(). Then a bool whether
to show free space or used space. Then mod those size_trunc_len()s on the
bool.

But, in the meantime, for a quick and usable hack, I'd just change that
last bit to:
[code]
     if (myfs_stats.avail != 0 || myfs_stats.total != 0)
     {
         Widget *w = WIDGET (panel);
         char buffer1[6], buffer2[6], tmp[BUF_SMALL];
         uintmax_t used = myfs_stats.total - myfs_stats.avail;

//        size_trunc_len (buffer1, sizeof (buffer1) - 1, myfs_stats.avail,  
1,
//                        panels_options.kilobyte_si);
         size_trunc_len (buffer1, sizeof (buffer1) - 1, used, 1,
                         panels_options.kilobyte_si);
         size_trunc_len (buffer2, sizeof (buffer2) - 1, myfs_stats.total, 1,
                         panels_options.kilobyte_si);
//        g_snprintf (tmp, sizeof (tmp), " %s/%s (%d%%) ", buffer1,  
buffer2,
//                    myfs_stats.total == 0 ? 0 :
//                    (int) (100 * (long double) myfs_stats.avail /  
myfs_stats.total));
         g_snprintf (tmp, sizeof (tmp), " Used %s/%s (%d%%) ", buffer1,  
buffer2,
                     myfs_stats.total == 0 ? 0 :
                     (int) (100 * (long double) used / myfs_stats.total));
         widget_move (w, w->lines - 1, w->cols - 2 - (int) strlen (tmp));
         tty_setcolor (NORMAL_COLOR);
         tty_print_string (tmp);
     }
[/code]

Works for me. I think I'll clean it up and keep it.


-- 
Peace and Cheer



More information about the mc mailing list