Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kang-hyuck
Copy link
Contributor

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

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]>
@honggyukim honggyukim added the tui label Aug 14, 2023
Copy link
Collaborator

@honggyukim honggyukim left a 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.

Comment on lines +2090 to +2142
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;
}
}
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

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) {
Copy link
Collaborator

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.

@honggyukim
Copy link
Collaborator

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 kang-hyuck should be like Kang Hyuck or Hyuck Kang

I can see your git author name at https://github.com/namhyung/uftrace/pull/1803.patch.

From faacac77ea4fbf37922dd1441f5f32ad05a79bb6 Mon Sep 17 00:00:00 2001
From: kang-hyuck <[email protected]>
        ...
Fixed: #1802
Signed-off-by: kang-hyuck <[email protected]>

@MichelleJin12
Copy link
Contributor

It is so useful to me. Thank you so much @kang-hyuck :D 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tui: Ask about addtional features for tui
3 participants