-
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
Open
kang-hyuck
wants to merge
1
commit into
namhyung:master
Choose a base branch
from
kang-hyuck:tui-add_scroll_halfpage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,12 @@ | |
#define KEY_ESCAPE 27 | ||
#define BLANK 32 | ||
|
||
/* ncurses format - octal number */ | ||
#define KEY_CTRL_D 0004 | ||
#define KEY_CTRL_E 0005 | ||
#define KEY_CTRL_U 0025 | ||
#define KEY_CTRL_Y 0031 | ||
|
||
#define TUI_ASSERT(cond) \ | ||
do { \ | ||
endwin(); \ | ||
|
@@ -150,6 +156,8 @@ static const char *help[] = { | |
"ARROW Navigation", | ||
"PgUp/Dn", | ||
"Home/End", | ||
"Ctrl + u/d Move half page up/down", | ||
"Ctrl + e/y Scroll line up/down", | ||
"Enter Fold/unfold graph or Select session", | ||
"G Show (full) call graph", | ||
"g Show call graph for this function", | ||
|
@@ -2079,6 +2087,170 @@ static void tui_window_move_end(struct tui_window *win) | |
} | ||
} | ||
|
||
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; | ||
} | ||
} | ||
|
||
static void tui_window_move_halfpage_up(struct tui_window *win) | ||
{ | ||
void *node; | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
/* find prev node */ | ||
node = win->ops->prev(win, win->top, true); | ||
|
||
/* cannot go top prev */ | ||
if (node == NULL) | ||
break; | ||
|
||
/* can go top prev */ | ||
win->top_index--; | ||
move_cnt++; | ||
|
||
/* blank check */ | ||
if (win->ops->needs_blank(win, node, win->top)) { | ||
win->top_index--; | ||
move_cnt++; | ||
} | ||
|
||
/* update win->top */ | ||
win->top = node; | ||
} | ||
|
||
/* init move_cnt */ | ||
move_cnt = 0; | ||
|
||
/* move win->curr */ | ||
while (move_cnt < (LINES - 2) / 2 - 1) { | ||
/* find prev node */ | ||
node = win->ops->prev(win, win->curr, false); | ||
|
||
/* cannot go curr prev */ | ||
if (node == NULL) | ||
break; | ||
|
||
/* can go curr prev */ | ||
win->curr_index--; | ||
move_cnt++; | ||
|
||
/* blank check */ | ||
if (win->ops->needs_blank(win, node, win->curr)) { | ||
win->curr_index--; | ||
move_cnt++; | ||
} | ||
|
||
/* update win->curr */ | ||
win->curr = node; | ||
} | ||
} | ||
|
||
static void tui_window_move_halfpage_down(struct tui_window *win) | ||
{ | ||
void *node; | ||
int move_cnt = 0; | ||
|
||
/* move win->top */ | ||
while (move_cnt < (LINES - 2) / 2 - 1) { | ||
/* find next node */ | ||
node = win->ops->next(win, win->top, true); | ||
|
||
/* cannot go top next */ | ||
if (node == NULL) | ||
break; | ||
|
||
/* can go top next */ | ||
win->top_index++; | ||
move_cnt++; | ||
|
||
/* blank check */ | ||
if (win->ops->needs_blank(win, win->top, node)) { | ||
win->top_index++; | ||
move_cnt++; | ||
} | ||
|
||
/* update win->top */ | ||
win->top = node; | ||
} | ||
|
||
/* init move_cnt */ | ||
move_cnt = 0; | ||
|
||
/* move win->curr */ | ||
while (move_cnt < (LINES - 2) / 2 - 1) { | ||
/* find next node */ | ||
node = win->ops->next(win, win->curr, false); | ||
|
||
/* cannot go curr next */ | ||
if (node == NULL) | ||
break; | ||
|
||
/* can go curr next */ | ||
win->curr_index++; | ||
move_cnt++; | ||
|
||
/* blank check */ | ||
if (win->ops->needs_blank(win, win->curr, node)) { | ||
win->curr_index++; | ||
move_cnt++; | ||
} | ||
|
||
/* update win->curr */ | ||
win->curr = node; | ||
} | ||
} | ||
|
||
/* move to the previous sibling */ | ||
static bool tui_window_move_prev(struct tui_window *win) | ||
{ | ||
|
@@ -2770,6 +2942,22 @@ static void tui_main_loop(struct uftrace_opts *opts, struct uftrace_data *handle | |
cancel_search(); | ||
tui_window_move_end(win); | ||
break; | ||
case KEY_CTRL_U: | ||
cancel_search(); | ||
tui_window_move_halfpage_up(win); | ||
break; | ||
case KEY_CTRL_D: | ||
cancel_search(); | ||
tui_window_move_halfpage_down(win); | ||
break; | ||
case KEY_CTRL_E: | ||
cancel_search(); | ||
tui_window_move_scroll_line_up(win); | ||
break; | ||
case KEY_CTRL_Y: | ||
cancel_search(); | ||
tui_window_move_scroll_line_down(win); | ||
break; | ||
case KEY_ENTER: | ||
case '\n': | ||
full_redraw = tui_window_enter(win, win->curr); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.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.
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.