MCPcopy Create free account
hub / github.com/NetHack/NetHack / curses_line_input_dialog

Function curses_line_input_dialog

win/curses/cursdial.c:109–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107 or a wish. Note: EDIT_GETLIN not supported for popup prompting. */
108
109void
110curses_line_input_dialog(
111 const char *prompt,
112 char *answer,
113 int buffer)
114{
115 int map_height, map_width, maxwidth, remaining_buf, winx, winy, count;
116 WINDOW *askwin, *bwin;
117 char *tmpstr;
118 int prompt_width, prompt_height = 1, height = prompt_height,
119 answerx = 0, answery = 0, trylim;
120 char input[BUFSZ];
121
122 /* if messages were being suppressed for the remainder of the turn,
123 re-activate them now that input is being requested */
124 curses_got_input();
125
126 if (buffer > (int) sizeof input)
127 buffer = (int) sizeof input;
128 /* +1: space between prompt and answer; buffer already accounts for \0 */
129 prompt_width = (int) strlen(prompt) + 1 + buffer;
130 maxwidth = term_cols - 2;
131
132 if (iflags.window_inited) {
133 if (!iflags.wc_popup_dialog) {
134 curses_message_win_getline(prompt, answer, buffer);
135 return;
136 }
137 curses_get_window_size(MAP_WIN, &map_height, &map_width);
138 if ((prompt_width + 2) > map_width)
139 maxwidth = map_width - 2;
140 }
141
142 if (prompt_width > maxwidth) {
143 prompt_height = curses_num_lines(prompt, maxwidth);
144 height = prompt_height;
145 prompt_width = maxwidth;
146 tmpstr = curses_break_str(prompt, maxwidth, prompt_height);
147 remaining_buf = buffer - ((int) strlen(tmpstr) - 1);
148 if (remaining_buf > 0) {
149 height += (remaining_buf / prompt_width);
150 if ((remaining_buf % prompt_width) > 0) {
151 height++;
152 }
153 }
154 free(tmpstr);
155 }
156
157 bwin = curses_create_window(TEXT_WIN, prompt_width, height,
158 iflags.window_inited ? UP : CENTER);
159 curses_set_wid_colors(TEXT_WIN, bwin);
160 wrefresh(bwin);
161 getbegyx(bwin, winy, winx);
162 askwin = newwin(height, prompt_width, winy + 1, winx + 1);
163
164 for (count = 0; count < prompt_height; count++) {
165 tmpstr = curses_break_str(prompt, maxwidth, count + 1);
166 mvwaddstr(askwin, count, 0, tmpstr);

Callers 3

curses_asknameFunction · 0.85
curses_getlinFunction · 0.85

Calls 8

curses_got_inputFunction · 0.85
curses_get_window_sizeFunction · 0.85
curses_num_linesFunction · 0.85
curses_break_strFunction · 0.85
curses_create_windowFunction · 0.85
curses_set_wid_colorsFunction · 0.85
curses_destroy_winFunction · 0.85

Tested by

no test coverage detected