mirror of
https://github.com/dvorka/hstr.git
synced 2025-01-09 00:18:22 +08:00
Fixed rendering after terminal resize.
This commit is contained in:
parent
2cfa074c13
commit
269ccb8804
1 changed files with 11 additions and 12 deletions
23
src/hstr.c
23
src/hstr.c
|
@ -137,7 +137,7 @@ int print_prompt()
|
||||||
color_attr_on(COLOR_PAIR(HH_COLOR_PROMPT));
|
color_attr_on(COLOR_PAIR(HH_COLOR_PROMPT));
|
||||||
color_attr_on(A_BOLD);
|
color_attr_on(A_BOLD);
|
||||||
}
|
}
|
||||||
mvprintw(Y_OFFSET_PROMPT, xoffset, "%s@%s$ ", user, hostname);
|
mvprintw(Y_OFFSET_PROMPT, xoffset, "%s@%s$ ", (user?user:"me"), (hostname?hostname:"localhost"));
|
||||||
if(hicolor) {
|
if(hicolor) {
|
||||||
color_attr_off(A_BOLD);
|
color_attr_off(A_BOLD);
|
||||||
color_attr_off(COLOR_PAIR(HH_COLOR_PROMPT));
|
color_attr_off(COLOR_PAIR(HH_COLOR_PROMPT));
|
||||||
|
@ -195,7 +195,7 @@ void print_history_label(HistoryItems *history)
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pattern(char *pattern, int y, int x)
|
void print_prefix(char *pattern, int y, int x)
|
||||||
{
|
{
|
||||||
color_attr_on(A_BOLD);
|
color_attr_on(A_BOLD);
|
||||||
mvprintw(y, x, "%s", pattern);
|
mvprintw(y, x, "%s", pattern);
|
||||||
|
@ -233,13 +233,9 @@ unsigned make_selection(char *prefix, HistoryItems *history, int maxSelectionCou
|
||||||
char **source=(defaultOrder?history->raw:history->items);
|
char **source=(defaultOrder?history->raw:history->items);
|
||||||
unsigned count=(defaultOrder?history->rawCount:history->count);
|
unsigned count=(defaultOrder?history->rawCount:history->count);
|
||||||
|
|
||||||
if(prefix && !strlen(prefix)) {
|
|
||||||
prefix=NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i=0; i<count && selectionCount<maxSelectionCount; i++) {
|
for(i=0; i<count && selectionCount<maxSelectionCount; i++) {
|
||||||
if(source[i]) {
|
if(source[i]) {
|
||||||
if(!prefix) {
|
if(!prefix || !strlen(prefix)) {
|
||||||
selection[selectionCount++]=source[i];
|
selection[selectionCount++]=source[i];
|
||||||
} else {
|
} else {
|
||||||
if(caseSensitive) {
|
if(caseSensitive) {
|
||||||
|
@ -428,7 +424,7 @@ void loop_to_select(HistoryItems *history)
|
||||||
if(!skip) {
|
if(!skip) {
|
||||||
c = wgetch(stdscr);
|
c = wgetch(stdscr);
|
||||||
} else {
|
} else {
|
||||||
if(strlen(pattern)>0) {
|
if(strlen(pattern)) {
|
||||||
color_attr_on(A_BOLD);
|
color_attr_on(A_BOLD);
|
||||||
mvprintw(y, basex, "%s", pattern);
|
mvprintw(y, basex, "%s", pattern);
|
||||||
color_attr_off(A_BOLD);
|
color_attr_off(A_BOLD);
|
||||||
|
@ -475,17 +471,20 @@ void loop_to_select(HistoryItems *history)
|
||||||
break;
|
break;
|
||||||
case KEY_RESIZE:
|
case KEY_RESIZE:
|
||||||
print_history_label(history);
|
print_history_label(history);
|
||||||
|
result=print_selection(maxHistoryItems, pattern, history);
|
||||||
|
print_history_label(history);
|
||||||
|
selectionCursorPosition=0;
|
||||||
move(y, basex+strlen(pattern));
|
move(y, basex+strlen(pattern));
|
||||||
break;
|
break;
|
||||||
case K_CTRL_U:
|
case K_CTRL_U:
|
||||||
case K_CTRL_W: // TODO supposed to delete just one word backward
|
case K_CTRL_W: // TODO supposed to delete just one word backward
|
||||||
pattern[0]=0;
|
pattern[0]=0;
|
||||||
print_pattern(pattern, y, basex);
|
print_prefix(pattern, y, basex);
|
||||||
break;
|
break;
|
||||||
case K_CTRL_L:
|
case K_CTRL_L:
|
||||||
toggle_case(pattern, lowercase);
|
toggle_case(pattern, lowercase);
|
||||||
lowercase=!lowercase;
|
lowercase=!lowercase;
|
||||||
print_pattern(pattern, y, basex);
|
print_prefix(pattern, y, basex);
|
||||||
selectionCursorPosition=0;
|
selectionCursorPosition=0;
|
||||||
break;
|
break;
|
||||||
case K_CTRL_H:
|
case K_CTRL_H:
|
||||||
|
@ -494,7 +493,7 @@ void loop_to_select(HistoryItems *history)
|
||||||
if(strlen(pattern)>0) {
|
if(strlen(pattern)>0) {
|
||||||
pattern[strlen(pattern)-1]=0;
|
pattern[strlen(pattern)-1]=0;
|
||||||
x--;
|
x--;
|
||||||
print_pattern(pattern, y, basex);
|
print_prefix(pattern, y, basex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strlen(pattern)>0) {
|
if(strlen(pattern)>0) {
|
||||||
|
@ -563,7 +562,7 @@ void loop_to_select(HistoryItems *history)
|
||||||
|
|
||||||
if(strlen(pattern)<(width-basex-1)) {
|
if(strlen(pattern)<(width-basex-1)) {
|
||||||
strcat(pattern, (char*)(&c));
|
strcat(pattern, (char*)(&c));
|
||||||
print_pattern(pattern, y, basex);
|
print_prefix(pattern, y, basex);
|
||||||
cursorX=getcurx(stdscr);
|
cursorX=getcurx(stdscr);
|
||||||
cursorY=getcury(stdscr);
|
cursorY=getcury(stdscr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue