about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-01-31 16:51:09 +0000
committerJames Booth <boothj5@gmail.com>2015-01-31 16:51:09 +0000
commitfe10f2b2e38818cdc77b226ee498d0956d3bba40 (patch)
tree0224c49267400bd9b7e191a3f9f3fd07a910a4dd
parent2b11baa564e9b558cfc050b5f28505f37900f2c1 (diff)
downloadprofani-tty-fe10f2b2e38818cdc77b226ee498d0956d3bba40.tar.gz
Clear autocompleters on printable chars
-rw-r--r--src/ui/inputwin.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index 649590bc..372048a2 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -91,7 +91,7 @@ cb_linehandler(char *line)
 int
 tab_handler(int count, int key)
 {
-    if (rl_point != rl_end) {
+    if (rl_point != rl_end || !rl_line_buffer) {
         return 0;
     }
 
@@ -126,6 +126,7 @@ create_input_window(void)
     p_rl_timeout.tv_usec = inp_timeout * 1000;
     rl_callback_handler_install(NULL, cb_linehandler);
     rl_bind_key('\t', tab_handler);
+
     inp_win = newpad(1, INP_WIN_MAX);
     wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));;
     keypad(inp_win, TRUE);
@@ -213,6 +214,17 @@ inp_write(char *line, int offset)
     _inp_win_update_virtual();
 }
 
+static int
+_printable(const wint_t ch)
+{
+    char bytes[MB_CUR_MAX+1];
+    size_t utf_len = wcrtomb(bytes, ch, NULL);
+    bytes[utf_len] = '\0';
+    gunichar unichar = g_utf8_get_char(bytes);
+
+    return g_unichar_isprint(unichar) && (ch != KEY_MOUSE);
+}
+
 gboolean
 inp_readline(void)
 {
@@ -225,13 +237,18 @@ inp_readline(void)
     }
 
     if (FD_ISSET(fileno(rl_instream), &fds)) {
+        if (_printable(rl_executing_key)) {
+            cmd_reset_autocomplete();
+        }
+
         rl_callback_read_char();
+
         if (rl_line_buffer && rl_line_buffer[0] != '/') {
             prof_handle_activity();
         }
+
         ui_reset_idle_time();
         inp_nonblocking(TRUE);
-        rl_redisplay();
         inp_write(rl_line_buffer, rl_point);
     } else {
         inp_nonblocking(FALSE);
2' href='#n192'>192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381