current time in MC



Dear Christian Hamar and MC users,

I didn't submit all patches I've done under MC knowingly
because I was not sure whether it'll be useful for someone.
One more thing, I'm a novice in Linux and don't know how to
create patches, in particular when I want to do it under the
whole directory. That is why I send you short description
instead of real patch.

In order to add current time in upper right corner you have to 
1) add the following line at the beginning of src/screen.c
#include <sys/time.h>
2) modify the show_dir function in src/screen.c. It must be as
   following

static void
show_dir (WPanel *panel)
{
    char tmp[200];

    time_t timer; // new line
    struct tm *tms;  // new line
    char str[24];  // new line


    set_colors (panel);
    draw_double_box (panel->widget.parent,
                     panel->widget.y, panel->widget.x,
                     panel->widget.lines, panel->widget.cols);

#ifdef HAVE_SLANG
    if (show_mini_info) {
        SLsmg_draw_object (panel->widget.y + llines (panel) + 2,
                           panel->widget.x, SLSMG_LTEE_CHAR);
        SLsmg_draw_object (panel->widget.y + llines (panel) + 2,
                           panel->widget.x + panel->widget.cols - 1,
                           SLSMG_RTEE_CHAR);
    }
#endif                          /* HAVE_SLANG */

    if (panel->active)
        attrset (REVERSE_COLOR);

    widget_move (&panel->widget, 0, 3);

    trim (strip_home_and_password (panel->cwd), tmp,
          max (panel->widget.cols - 7, 0));
    addstr (tmp);
    widget_move (&panel->widget, 0, 1);
    addstr ("<");
    widget_move (&panel->widget, 0, panel->widget.cols - 2);
    addstr (">");

    time(&timer);  // new line
    tms=localtime(&timer);  // new line
    strftime(str,24,"%H:%M",tms);  // new line

    if(strcmp(panel->panel_name,get_nth_panel_name(0)))          // new line
    {                                                            // new line
        widget_move (&panel->widget, 0, panel->widget.cols - 9); // new line
        addstr (str);                                            // new line
    }                                                            // new line
    else                                                         // new line
    {                                                            // new line
        widget_move (&panel->widget, 0, panel->widget.cols - 3);
        addstr ("v");
    }                                                            // new line

    if (panel->active)
        standend ();
}

Short description:
At first I've added new variables: timer, tms and str. Then got the current time
and convert it to the string str (you can change this string format as you like:
seconds, date etc.). Finally add the str to upper MC line to the right panel
(  if(strcmp(panel->panel_name,get_nth_panel_name(0)))   ). It seems to be all.
Time will be refreshed after changing directory, F3, Ctrl+O and other
actions which leads to panels refreshing.


Best regards,
 Vyacheslav                          mailto:vfilyayev d2 khai edu




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]