normal: fix get_logical_num_lines
PATCH 1/1 normal: fix get_logical_num_lines
In menu editing mode, grub2 shows bogus line if the character being edited is at last column of entry. This patch fixes the problem by having the get_logical_num_lines function to calculate correct number of lines.
--- grub-core/normal/menu_entry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/normal/menu_entry.c +1 -1
@@ -128,7 +128,7 @@ get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen) {return (grub_getstringwidth (linep->buf, linep->buf + linep->len, term_screen->term) - / (unsigned ) term_screen->geo.entry_width) +1 ; + / ((unsigned ) term_screen->geo.entry_width +1 )) +1 ; } static void
Signature · 1 line
2.6.3
Quoted 5 lines · Michael Chang
In menu editing mode, grub2 shows bogus line if the character being edited is at last column of entry. This patch fixes the problem by having the
get_logical_num_linesfunction to calculate correct number of lines.
There is one more occurrence in update_screen (); could you check if this needs fix too?
grub_size_t t = grub_getstringwidth (linep->buf, linep->buf + screen->column,
term_screen->term);
y += t / (unsigned) term_screen->geo.entry_width;
Quoted 25 lines
--- grub-core/normal/menu_entry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)grub-core/normal/menu_entry.c +1
-2@@ -128,7 +128,7 @@ get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen) {return (grub_getstringwidth (linep->buf, linep->buf + linep->len, term_screen->term) - / (unsigned ) term_screen->geo.entry_width) +1 ; + / ((unsigned ) term_screen->geo.entry_width +1 )) +1 ; } static void --2.6.3
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 7 lines · Andrei Borzenkov
Quoted 5 lines · Michael Chang
In menu editing mode, grub2 shows bogus line if the character being edited is at last column of entry. This patch fixes the problem by having the
get_logical_num_linesfunction to calculate correct number of lines.
Quoted 6 lines
There is one more occurrence in
update_screen(); could you check if this needs fix too?
grub_size_tt =grub_getstringwidth(linep->buf,linep->buf+screen->column,term_screen->term);y += t / (unsigned)
term_screen->geo.entry_width;
No, as the check followed has bailed it out.
if (t % (unsigned) term_screen->geo.entry_width == 0
&& t != 0 && screen->column == linep->len) y--;
Of course, we can try to make the code more terse by the same fix so that we can remove the check. Should I submit a new patch for that ?
Thanks,
Michael
Quoted 14 lines · Michael Chang
In menu editing mode, grub2 shows bogus line if the character being edited is at last column of entry. This patch fixes the problem by having the
get_logical_num_linesfunction to calculate correct number of lines.--- grub-core/normal/menu_entry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)grub-core/normal/menu_entry.c +0
-0
grub-core/normal/menu_entry.c get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen) · line 131
Quoted 5 lines
grub-core/normal/menu_entry.c +1
-1@@ -128,7 +128,7 @@ get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen) {return (grub_getstringwidth (linep->buf, linep->buf + linep->len, term_screen->term) - / (unsigned ) term_screen->geo.entry_width) +1 ; + / ((unsigned ) term_screen->geo.entry_width +1 )) +1 ;
No, that's wrong. Consider entry_width = 10 and grub_getstringwidth =
21. It needs 3 lines but your change gives only 2.
It sounds like we need
string_width = grub_getstringwidth (linep->buf, linep->buf + linep->len, term_screen->term);
if (!string_width)
return 1;
return (string_width + (unsigned) term_screen->geo.entry_width - 1) / (unsigned) term_screen->geo.entry_width;
Could you test if it works for you?
Quoted 10 lines · Andrei Borzenkov
Quoted 9 lines · Michael Chang
In menu editing mode, grub2 shows bogus line if the character being edited is at last column of entry. This patch fixes the problem by having the
get_logical_num_linesfunction to calculate correct number of lines.--- grub-core/normal/menu_entry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
grub-core/normal/menu_entry.c get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen) · line 131
Quoted 10 lines
grub-core/normal/menu_entry.c +1
-1@@ -128,7 +128,7 @@ get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen) {return (grub_getstringwidth (linep->buf, linep->buf + linep->len, term_screen->term) - / (unsigned ) term_screen->geo.entry_width) +1 ; + / ((unsigned ) term_screen->geo.entry_width +1 )) +1 ;No, that's wrong. Consider
entry_width= 10 andgrub_getstringwidth=
21. It needs 3 lines but your change gives only 2.
Alas! Indeed I am mistaken here. We should minus the numerator by one but not adding one to denominator. Thanks for your check. :)
Quoted 11 lines
It sounds like we need
string_width=grub_getstringwidth(linep->buf,linep->buf+linep->len,term_screen->term);
if (!string_width)
return 1;
return (string_width+ (unsigned)term_screen->geo.entry_width- 1) / (unsigned)term_screen->geo.entry_width;Could you test if it works for you?
Yes. It works great.
Thanks,
Michael
Quoted 10 lines · Michael Chang
Quoted 9 lines · Andrei Borzenkov
It sounds like we need
string_width=grub_getstringwidth(linep->buf,linep->buf+linep->len,term_screen->term);
if (!string_width)
return 1;
return (string_width+ (unsigned)term_screen->geo.entry_width- 1) / (unsigned)term_screen->geo.entry_width;
Quoted 3 lines
Quoted 1 line
Could you test if it works for you?
Yes. It works great.
Hi Andrei,
I found we had a down stream bug opened for the problem a while ago that could be fixed by the patch.
https://bugzilla.suse.com/show_bug.cgi?id=943585
So please consider to commit your patch if you think it's ready to go as well after the testing.
Thanks,
Michael
Quoted 38 lines · Michael Chang
Quoted 10 lines · Andrei Borzenkov
Quoted 9 lines · Michael Chang
In menu editing mode, grub2 shows bogus line if the character being edited is at last column of entry. This patch fixes the problem by having the
get_logical_num_linesfunction to calculate correct number of lines.--- grub-core/normal/menu_entry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 13 lines
grub-core/normal/menu_entry.c get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen) · line 131
Quoted 10 lines
grub-core/normal/menu_entry.c +1
-1@@ -128,7 +128,7 @@ get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen) {return (grub_getstringwidth (linep->buf, linep->buf + linep->len, term_screen->term) - / (unsigned ) term_screen->geo.entry_width) +1 ; + / ((unsigned ) term_screen->geo.entry_width +1 )) +1 ;No, that's wrong. Consider
entry_width= 10 andgrub_getstringwidth=
21. It needs 3 lines but your change gives only 2.Alas! Indeed I am mistaken here. We should minus the numerator by one but not adding one to denominator. Thanks for your check. :)
Quoted 10 lines
It sounds like we need
string_width=grub_getstringwidth(linep->buf,linep->buf+linep->len,term_screen->term);
if (!string_width)
return 1;
return (string_width+ (unsigned)term_screen->geo.entry_width- 1) / (unsigned)term_screen->geo.entry_width;
Quoted 3 lines
Quoted 1 line
Could you test if it works for you?
Yes. It works great.
@Anrei: please go ahead.
Quoted 9 lines
Thanks,
Michael_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel