-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tui: Add Ctrl+u/d, Ctrl+e/y keys to move half page and scroll line #1803
base: master
Are you sure you want to change the base?
Conversation
problem: tui needs to move the cursor to the top and bottom to see the previous or next page code. solution: Add the keys to move the page by plcaing the cursor on the result that you are interested in. Those are functions in vim and I implemented it. you can move and search the result more flexibly. Fixed: namhyung#1802 Signed-off-by: kang-hyuck <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work! I've test it and it works fine.
I'm not sure how @namhyung thinks about this feature, but I have a few comments.
static void tui_window_move_scroll_line_up(struct tui_window *win) | ||
{ | ||
void *node = win->ops->next(win, win->top, true); | ||
|
||
/* cannot go top next */ | ||
if (node == NULL) | ||
return; | ||
|
||
/* can go top next */ | ||
win->top_index++; | ||
if (win->ops->needs_blank(win, win->top, node)) | ||
win->top_index++; | ||
|
||
/* update win->top */ | ||
win->top = node; | ||
|
||
/* update win->curr - out of cursor line case*/ | ||
if (win->top_index > win->curr_index) { | ||
win->curr = win->top; | ||
win->curr_index = win->top_index; | ||
} | ||
} | ||
|
||
static void tui_window_move_scroll_line_down(struct tui_window *win) | ||
{ | ||
void *node = win->ops->prev(win, win->top, true); | ||
|
||
/* cannot go top prev */ | ||
if (node == NULL) | ||
return; | ||
|
||
/* can go top prev */ | ||
win->top_index--; | ||
if (win->ops->needs_blank(win, node, win->top)) // (win, prev_node, curr_node) | ||
win->top_index--; | ||
|
||
/* update win->top */ | ||
win->top = node; | ||
|
||
/* update win->curr - out of cursor line case, cursor must follow top in ranges */ | ||
while (win->curr_index - win->top_index >= LINES - 2) { | ||
/* find prev node */ | ||
node = win->ops->prev(win, win->curr, false); | ||
win->curr_index--; | ||
|
||
/* blank check */ | ||
if (win->ops->needs_blank(win, node, win->curr)) | ||
win->curr_index--; | ||
|
||
/* update win->curr */ | ||
win->curr = node; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they have very similar code structure. So it'd be better to have a common function and use it in both functions. The common function name could be tui_window_move_scroll_line
.
The same common function can be used for tui_window_move_halfpage_up
and tui_window_move_halfpage_down
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they have very similar code structure. So it'd be better to have a common function and use it in both functions. The common function name could be
tui_window_move_scroll_line
.The same common function can be used for
tui_window_move_halfpage_up
andtui_window_move_halfpage_down
as well.
Thank you for reviewing my code !! you are right. I think so, too. In fact, I found that vim
is also using common function for directions, and they manage directions like up and down by using function arguments field.
However, In uftrace
, It seems that all command functions use only one argument, struct tui_window *win
, So I didn't want to break that implicit structure rules. But I can edit it if you want.
int move_cnt = 0; | ||
|
||
/* move win->top */ | ||
while (move_cnt < (LINES - 2) / 2 - 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(LINES - 2) / 2 - 1
can be assigned to a meaningful name at the top of this function.
I also see that your name looks what we want. We want to have it just like it's shown in your official ID card. The name I can see your git author name at https://github.com/namhyung/uftrace/pull/1803.patch.
|
It is so useful to me. Thank you so much @kang-hyuck :D 👍 |
problem:
tui needs to move the cursor to the top and bottom to see the previous
or next page code.
solution:
Add the keys to move the page by plcaing the cursor on the result
that you are interested in.
Those are functions in vim and I implemented it.
you can move and search the result more flexibly.
Fixed: #1802