author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Thu, 16 Apr 2009 12:49:12 +0200 | |
changeset 53 | 6b3d7e3418c1 |
parent 45 | 7197576fedcf |
child 77 | 49e0babccb23 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
2 |
* test/demos/ncurses.c |
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
0 | 4 |
* |
5 |
* Unicode != UTF-8 |
|
6 |
* unicode with ncursesw ( wide char) |
|
7 |
* gcc $< -lncursesw -o $@ |
|
8 |
*/ |
|
9 |
||
10 |
#include <stdio.h> |
|
11 |
#include <string.h> |
|
12 |
#include <stdlib.h> |
|
13 |
#include <fcntl.h> |
|
14 |
#include <ncursesw/curses.h> |
|
15 |
#include <wchar.h> |
|
16 |
#include <locale.h> |
|
17 |
||
18 |
#ifndef u_char |
|
19 |
typedef unsigned char u_char; |
|
20 |
#endif |
|
21 |
||
22 |
#define ESCAPE 0x1B |
|
23 |
||
24 |
#ifndef get_wch |
|
25 |
extern int get_wch (); |
|
26 |
#endif |
|
27 |
||
28 |
int check_locale () |
|
29 |
{ |
|
30 |
if (!setlocale (LC_CTYPE, "")) { |
|
31 |
perror ("SETLOCALE"); |
|
32 |
return EXIT_FAILURE; |
|
33 |
} |
|
34 |
return EXIT_SUCCESS; |
|
35 |
} |
|
36 |
||
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
27
diff
changeset
|
37 |
wchar_t func (WINDOW * win) |
0 | 38 |
{ |
39 |
wchar_t guess; |
|
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
40 |
|
0 | 41 |
char dest[4]; |
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
42 |
|
0 | 43 |
int maxx; |
44 |
int maxy; |
|
45 |
||
46 |
while (guess != ESCAPE) { |
|
47 |
while ((get_wch (&guess)) != OK) |
|
48 |
/* |
|
49 |
* waiting for multibyte character |
|
50 |
*/ |
|
51 |
; |
|
52 |
||
53 |
maxx = getmaxx (win); |
|
54 |
maxy = getmaxy (win); |
|
55 |
||
56 |
dest[0] = 0; |
|
57 |
dest[1] = 0; |
|
58 |
dest[2] = 0; |
|
59 |
dest[3] = 0; |
|
60 |
if (wctomb (dest, guess) == -1) { |
|
61 |
perror ("WCTOMB"); |
|
62 |
return -1; |
|
63 |
} |
|
64 |
||
65 |
mvprintw (maxy / 2, maxx / 2 - 12, |
|
66 |
"UTF-8: (%2X:%2X:%2X:%2X)\t\t", (u_char) dest[0], |
|
67 |
(u_char) dest[1], (u_char) dest[2], (u_char) dest[3]); |
|
68 |
||
69 |
mvprintw (maxy - 1, 0, "KEY: %2lc\t", guess); |
|
70 |
mvprintw (maxy - 1, maxx - 14, "UNICODE: %4X", guess); |
|
71 |
mvprintw (maxy - 1, maxx / 2 - 10, "Press ESC to quit"); |
|
72 |
} |
|
73 |
return guess; |
|
74 |
} |
|
75 |
||
76 |
int main () |
|
77 |
{ |
|
78 |
wchar_t x; |
|
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
79 |
|
0 | 80 |
WINDOW *win; |
81 |
||
82 |
check_locale (); |
|
83 |
win = initscr (); |
|
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
27
diff
changeset
|
84 |
keypad (win, 1); |
0 | 85 |
noecho (); |
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
27
diff
changeset
|
86 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
27
diff
changeset
|
87 |
x = func (win); |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
27
diff
changeset
|
88 |
|
0 | 89 |
endwin (); |
90 |
printf ("\n"); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
91 |
|
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
92 |
return EXIT_SUCCESS; |
0 | 93 |
} |