src/input.c

Wed, 29 Aug 2018 13:45:13 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 29 Aug 2018 13:45:13 +0200
changeset 63
611332453da0
parent 55
54ea19938d57
permissions
-rw-r--r--

move log has now three columns and starts scrolling after 45 moves

universe@3 1 /*
universe@3 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
universe@3 3 *
universe@55 4 * Copyright 2016 Mike Becker. All rights reserved.
universe@3 5 *
universe@3 6 * Redistribution and use in source and binary forms, with or without
universe@3 7 * modification, are permitted provided that the following conditions are met:
universe@3 8 *
universe@3 9 * 1. Redistributions of source code must retain the above copyright
universe@3 10 * notice, this list of conditions and the following disclaimer.
universe@3 11 *
universe@3 12 * 2. Redistributions in binary form must reproduce the above copyright
universe@3 13 * notice, this list of conditions and the following disclaimer in the
universe@3 14 * documentation and/or other materials provided with the distribution.
universe@3 15 *
universe@3 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@3 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@3 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
universe@3 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
universe@3 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
universe@3 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
universe@3 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
universe@3 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
universe@3 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
universe@3 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
universe@3 26 * POSSIBILITY OF SUCH DAMAGE.
universe@3 27 *
universe@3 28 */
universe@3 29
universe@3 30 #include "input.h"
universe@32 31 #include <string.h>
universe@31 32 #include <ctype.h>
universe@3 33
universe@7 34 int prompt_yesno(char *msg) {
universe@7 35 printw("%s (y/n)? ", msg);
universe@7 36 refresh();
universe@3 37 noecho();
universe@3 38 int ch;
universe@3 39 do {
universe@3 40 ch = getch();
universe@3 41 } while (ch != 'y' && ch != 'n');
universe@3 42 echo();
universe@3 43
universe@3 44 return ch == 'y';
universe@3 45 }
universe@30 46
universe@32 47 int mvwasyncgetnstr(WINDOW* w,int y,int x,char *str,size_t *pos,size_t len) {
universe@32 48 mvwaddnstr(w, y, x, str, *pos);
universe@30 49 wrefresh(w);
universe@30 50 int c = wgetch(w);
universe@30 51
universe@30 52 if (c != ERR) {
universe@30 53 switch (c) {
universe@32 54 case KEY_DOWN:
universe@30 55 case '\n':
universe@32 56 str[*pos] = '\0';
universe@32 57 *pos = 0;
universe@39 58 waddch(w,'\n');
universe@30 59 return 1;
universe@30 60 case KEY_BACKSPACE:
universe@30 61 case KEY_LEFT:
universe@38 62 if ((*pos) > 0) {
universe@38 63 str[--(*pos)] = '\0';
universe@38 64 }
universe@30 65 break;
universe@30 66 default:
universe@32 67 if (isprint(c) && *pos < len-1) {
universe@32 68 str[(*pos)++] = (char) c;
universe@30 69 }
universe@30 70 }
universe@30 71 }
universe@30 72
universe@30 73 return 0;
universe@30 74 }

mercurial