summaryrefslogtreecommitdiff
path: root/dselect/kt.c
blob: d322c68bf025a8044c8b7ef3f6af21ec4d3e8699 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <ncurses/curses.h>

struct kd { int v; const char *n; } kds[]= {
#include "curkeys.inc"
};

int main(int argc, char **argv) {
  int n=0, c, y,x;
  struct kd *kdp;

  initscr(); cbreak(); noecho(); nonl();
  keypad(stdscr,TRUE);
  getmaxyx(stdscr,y,x);
  mvprintw(5,5,"q to quit; b to beep; (y%d x%d)",y,x);

  for (;;) {
    refresh();
    c= getch(); if (c==ERR) { endwin(); perror("err"); exit(1); }
    for (kdp=kds; kdp->v != -1 && kdp->v != c; kdp++);
    n++; mvprintw(10 + (n%4),10,"n %10d  keycode %4d  %-10s  F0 + %4d",n,c,
                  kdp->n ? kdp->n : "<none>", c-KEY_F0);
    if (c == 'q') break;
    if (c == 'b') beep();
  }
  endwin();
  return 0;
}