| 71 | } |
| 72 | |
| 73 | bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm, |
| 74 | WINDOW* w) |
| 75 | { |
| 76 | int x; |
| 77 | int y; |
| 78 | |
| 79 | FORM* form = fm->GetForm(); |
| 80 | // when not in edit mode, edit mode is entered by pressing enter or i (vim |
| 81 | // binding) |
| 82 | // 10 == enter |
| 83 | if (!this->InEdit && (key != 10 && key != KEY_ENTER && key != 'i')) { |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | this->OriginalString.clear(); |
| 88 | this->Done = false; |
| 89 | |
| 90 | char debugMessage[128]; |
| 91 | |
| 92 | // <Enter> is used to change edit mode (like <Esc> in vi). |
| 93 | while (!this->Done) { |
| 94 | snprintf(debugMessage, sizeof(debugMessage), |
| 95 | "String widget handling input, key: %d", key); |
| 96 | cmCursesForm::LogMessage(debugMessage); |
| 97 | |
| 98 | fm->PrintKeys(); |
| 99 | |
| 100 | getmaxyx(stdscr, y, x); |
| 101 | // If window too small, handle 'q' only |
| 102 | if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) { |
| 103 | // quit |
| 104 | if (key == 'q') { |
| 105 | return false; |
| 106 | } |
| 107 | key = getch(); |
| 108 | continue; |
| 109 | } |
| 110 | |
| 111 | // If resize occurred during edit, move out of edit mode |
| 112 | if (!this->InEdit && (key != 10 && key != KEY_ENTER && key != 'i')) { |
| 113 | return false; |
| 114 | } |
| 115 | // toggle edit with return |
| 116 | if ((key == 10 || key == KEY_ENTER) |
| 117 | // enter edit with i (and not-edit mode) |
| 118 | || (!this->InEdit && key == 'i')) { |
| 119 | this->OnReturn(fm, w); |
| 120 | } else if (key == KEY_DOWN || key == ctrl('n') || key == KEY_UP || |
| 121 | key == ctrl('p') || key == KEY_NPAGE || key == ctrl('d') || |
| 122 | key == KEY_PPAGE || key == ctrl('u')) { |
| 123 | this->SetInEdit(false); |
| 124 | this->OriginalString.clear(); |
| 125 | // trick to force forms to update the field buffer |
| 126 | form_driver(form, REQ_NEXT_FIELD); |
| 127 | form_driver(form, REQ_PREV_FIELD); |
| 128 | return false; |
| 129 | } |
| 130 | // esc |
nothing calls this directly
no test coverage detected