Skip to content

Commit

Permalink
. 菜单动态更新日期时间。
Browse files Browse the repository at this point in the history
  setmenu --string=x=y=color="date&time"
  • Loading branch information
yaya committed Aug 1, 2019
1 parent 45e75e0 commit dbc6bc0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 6 deletions.
4 changes: 4 additions & 0 deletions ChangeLog_chenall.txt
@@ -1,4 +1,8 @@
更新说明:
2019-08-01(yaya)
菜单动态更新日期时间。
setmenu --string=x=y=color="date&time"

2019-07-14(yaya)
支持位于 2TB 后的分区。

Expand Down
4 changes: 4 additions & 0 deletions stage2/asm.S
Expand Up @@ -15030,6 +15030,10 @@ ENTRY(console_getkey)
cmpb $0, beep_enable
je 2f
call beep_func
2:
cmpb $0, string_enable
je 2f
call string_refresh
2:
cmpl $0, graphics_inited
je 4b
Expand Down
39 changes: 38 additions & 1 deletion stage2/builtins.c
Expand Up @@ -16470,6 +16470,7 @@ char *p_string= (char *)MENU_TITLE;
extern int new_menu;
unsigned long string_total = 0;
int num_text_char(char *p);
unsigned char string_enable;

static int
setmenu_func(char *arg, int flags)
Expand All @@ -16483,6 +16484,7 @@ setmenu_func(char *arg, int flags)
{
num_string = 0;
string_total = 0;
string_enable = 0;
p_string = (char *)MENU_TITLE;
for (i=0; i<16; i++)
DrawBox[i].index = 0;
Expand All @@ -16503,6 +16505,7 @@ setmenu_func(char *arg, int flags)
{
num_string = 0;
string_total = 0;
string_enable = 0;
p_string = (char *)MENU_TITLE;
goto cont;
}
Expand Down Expand Up @@ -16530,6 +16533,11 @@ setmenu_func(char *arg, int flags)
strings[i].color = val; //color
arg += 2;
strings[i].addr = (int)p_string; //addr
if (grub_memcmp (arg, "date&time\"", 10) == 0)
{
string_enable = i+1;
*arg = '"';
}
p = arg;
while (*p++ != '"');
*(p - 1) = 0;
Expand Down Expand Up @@ -16603,6 +16611,7 @@ setmenu_func(char *arg, int flags)
menu_tab = 0;
num_string = 0;
string_total = 0;
string_enable = 0;
p_string= (char *)MENU_TITLE;
menu_font_spacing = 0;
menu_line_spacing = 0;
Expand Down Expand Up @@ -16828,6 +16837,7 @@ static struct builtin builtin_setmenu =
"--string=[X]=[-]Y=COLOR=\"STRING\" max 16 commands.\n"
"Note: there is no X, position in the middle.\n"
"Note: -Y represents the count from the bottom.\n"
"When STRING is date&time, update date and time dynamically.\n"
" --string= to delete all strings.\n"
"--box x=X y=Y w=W h=H l=L\n"
"Note: W=0 in the middle. L=0 no display border\n"
Expand All @@ -16854,7 +16864,34 @@ static struct builtin builtin_setmenu =
};



unsigned short refresh = 0;
void string_refresh(void)
{
int i = string_enable-1;

if ((cursor_state & 1) == 1)
return;
putchar_hooked = 0;
if (!refresh)
{
unsigned long date, time;

refresh = 250;
get_datetime(&date, &time);
unsigned long long col = current_color_64bit;
current_term->setcolorstate (COLOR_STATE_NORMAL);
gotoxy (strings[i].start_x, strings[i].start_y);
if ((strings[i].color & 0xffffffff00000000) == 0)
current_color_64bit = strings[i].color | (current_color_64bit & 0xffffffff00000000);
else
current_color_64bit = strings[i].color;
grub_printf("%04X-%02X-%02X %02X:%02X:%02X",(date >> 16),(char)(date >> 8),(char)date,(char)(time >> 24),(char)(time >> 16),(char)(time>>8));
current_color_64bit = col;
}
else
refresh--;
return;
}

static int endlocal_func(char *arg, int flags)
{
Expand Down
2 changes: 2 additions & 0 deletions stage2/shared.h
Expand Up @@ -504,6 +504,8 @@ struct string
} __attribute__ ((packed));
extern struct string strings[16];
extern unsigned long string_total;
extern unsigned char string_enable;
extern void string_refresh(void);
#define MENU_TITLE 0x3A8000
#define MENU_TITLE_LENGTH 0x800
/* The Chinese patch will begin at here */
Expand Down
15 changes: 10 additions & 5 deletions stage2/stage2.c
Expand Up @@ -1096,11 +1096,16 @@ run_menu (char *menu_entries, char *config_entries, /*int num_entries,*/ char *h
grub_timeout--;
}

defer(1);
if ((animated_enable) && (grub_timeout >= 0))
animated();
if ((beep_enable) && (grub_timeout >= 0))
beep_func((char *)beep_buf,1);
if (grub_timeout >= 0)
{
defer(1);
if (animated_enable)
animated();
if (beep_enable)
beep_func((char *)beep_buf,1);
if (string_enable)
string_refresh();
}
/* Check for a keypress, however if TIMEOUT has been expired
(GRUB_TIMEOUT == -1) relax in GETKEY even if no key has been
pressed.
Expand Down

0 comments on commit dbc6bc0

Please sign in to comment.