Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 210 lines (155 sloc) 6.363 kB
515baab Changed the license to Apache License. Please see the file LICENSE. T…
Mazen Harake authored
1 %%==============================================================================
2 %% Copyright 2010 Erlang Solutions Ltd.
4482ad2 @mazenharake Update outdated email
authored
3 %% Author: Mazen Harake (mazen.harake@gmail.com)
4769266 @mazenharake Merge commit 'd10041ce14e2f1ba8c52ecea267479156ea1e1c9' into input
authored
4 %%
515baab Changed the license to Apache License. Please see the file LICENSE. T…
Mazen Harake authored
5 %% Licensed under the Apache License, Version 2.0 (the "License");
6 %% you may not use this file except in compliance with the License.
7 %% You may obtain a copy of the License at
4769266 @mazenharake Merge commit 'd10041ce14e2f1ba8c52ecea267479156ea1e1c9' into input
authored
8 %%
515baab Changed the license to Apache License. Please see the file LICENSE. T…
Mazen Harake authored
9 %% http://www.apache.org/licenses/LICENSE-2.0
4769266 @mazenharake Merge commit 'd10041ce14e2f1ba8c52ecea267479156ea1e1c9' into input
authored
10 %%
515baab Changed the license to Apache License. Please see the file LICENSE. T…
Mazen Harake authored
11 %% Unless required by applicable law or agreed to in writing, software
12 %% distributed under the License is distributed on an "AS IS" BASIS,
13 %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 %% See the License for the specific language governing permissions and
15 %% limitations under the License.
16 %%==============================================================================
4769266 @mazenharake Merge commit 'd10041ce14e2f1ba8c52ecea267479156ea1e1c9' into input
authored
17
18 -module(cecho).
515baab Changed the license to Apache License. Please see the file LICENSE. T…
Mazen Harake authored
19
4482ad2 @mazenharake Update outdated email
authored
20 -author('mazen.harake@gmail.com').
515baab Changed the license to Apache License. Please see the file LICENSE. T…
Mazen Harake authored
21
4769266 @mazenharake Merge commit 'd10041ce14e2f1ba8c52ecea267479156ea1e1c9' into input
authored
22 -behaviour(application).
23 -include("include/cecho.hrl").
24 -include("include/cecho_commands.hrl").
25
26 %% Behaviour Callbacks
27 -export([start/2, stop/1]).
28
29 %% Application API
30
31 -export([refresh/0, cbreak/0, nocbreak/0, echo/0, noecho/0, addch/1, addstr/1,
f03bcbd @rafaltrojniak werase was not exported
rafaltrojniak authored
32 move/2, getyx/0, getmaxyx/0, curs_set/1, werase/1, erase/0, has_colors/0,
4769266 @mazenharake Merge commit 'd10041ce14e2f1ba8c52ecea267479156ea1e1c9' into input
authored
33 start_color/0, init_pair/3, attron/1, attroff/1, nl/0, nonl/0,
34 scrollok/2, mvaddch/3, mvaddstr/3, newwin/4, delwin/1, wmove/3,
35 waddstr/2, waddch/2, mvwaddstr/4, mvwaddch/4, wrefresh/1, hline/2,
36 whline/3, vline/2, wvline/3, border/8, wborder/9, box/3, getyx/1,
7f6fd67 @mazenharake Added async-input.
authored
37 getmaxyx/1, attron/2, attroff/2, keypad/2, getch/0]).
4769266 @mazenharake Merge commit 'd10041ce14e2f1ba8c52ecea267479156ea1e1c9' into input
authored
38
39 %% =============================================================================
40 %% Application API
41 %% =============================================================================
42 refresh() ->
43 call(?REFRESH).
44
45 cbreak() ->
46 call(?CBREAK).
47
48 nocbreak() ->
49 call(?NOCBREAK).
50
51 echo() ->
52 call(?ECHO).
53
54 noecho() ->
55 call(?NOECHO).
56
57 addch(Char) when is_integer(Char) ->
58 call(?ADDCH, Char).
59
60 addstr(String) when is_list(String) ->
61 Str = lists:flatten(String),
62 call(?ADDSTR, {erlang:iolist_size(Str), Str}).
63
64 move(Y, X) when is_integer(X) andalso is_integer(Y) ->
65 call(?MOVE, {Y, X}).
66
67 getyx() ->
68 getyx(?ceSTDSCR).
69
70 getyx(Window) when is_integer(Window) ->
71 call(?GETYX, Window).
72
73 getmaxyx() ->
74 getmaxyx(?ceSTDSCR).
75
76 getmaxyx(Window) when is_integer(Window) ->
77 call(?GETMAXYX, Window).
78
79 curs_set(Flag) when is_integer(Flag) ->
80 call(?CURS_SET, Flag).
81
82 erase() ->
0122164 Added the werase API to clear a window. The erase API now uses werase
Mazen Harake authored
83 werase(?ceSTDSCR).
84
85 werase(Window) when is_integer(Window) ->
86 call(?WERASE, Window).
4769266 @mazenharake Merge commit 'd10041ce14e2f1ba8c52ecea267479156ea1e1c9' into input
authored
87
88 has_colors() ->
89 call(?HAS_COLORS).
90
91 start_color() ->
92 call(?START_COLOR).
93
94 init_pair(N, FColor, BColor) when is_integer(N) andalso is_integer(FColor)
95 andalso is_integer(BColor) ->
96 call(?INIT_PAIR, {N, FColor, BColor}).
97
98 attron(Mask) ->
99 attron(?ceSTDSCR, Mask).
100
101 attron(Window, Mask) when is_integer(Mask) andalso is_integer(Window) ->
102 call(?WATTRON, {Window, Mask}).
103
104 attroff(Mask) ->
105 attroff(?ceSTDSCR, Mask).
106
107 attroff(Window, Mask) when is_integer(Mask) andalso is_integer(Window) ->
108 call(?WATTROFF, {Window, Mask}).
109
110 nl() ->
111 call(?NL).
112
113 nonl() ->
114 call(?NONL).
115
116 scrollok(Window, BFlag) when is_integer(Window) andalso is_boolean(BFlag) ->
117 call(?SCROLLOK, {Window, BFlag}).
118
119 mvaddch(Y, X, Char) when is_integer(Char) andalso is_integer(X)
120 andalso is_integer(Y) ->
121 call(?MVADDCH, {Y, X, Char}).
122
123 mvaddstr(Y, X, String) when is_list(String) andalso is_integer(X) andalso
124 is_integer(Y) ->
125 Str = lists:flatten(String),
126 call(?MVADDSTR, {Y, X, erlang:iolist_size(Str), Str}).
127
128 newwin(Height, Width, StartY, StartX) when is_integer(Height) andalso
129 is_integer(Width) andalso
130 is_integer(StartY) andalso
131 is_integer(StartX) ->
132 call(?NEWWIN, {Height, Width, StartY, StartX}).
133
134 delwin(Window) when is_integer(Window) ->
135 call(?DELWIN, Window).
136
137 wmove(Window, Y, X) when is_integer(Window) andalso is_integer(Y) andalso
138 is_integer(X) ->
139 call(?WMOVE, {Window, Y, X}).
140
141 waddstr(Window, String) when is_integer(Window) andalso is_list(String) ->
142 Str = lists:flatten(String),
143 call(?WADDSTR, {Window, erlang:iolist_size(Str), Str}).
144
145 waddch(Window, Char) when is_integer(Window) andalso is_integer(Char) ->
146 call(?WADDCH, {Window, Char}).
147
148 mvwaddstr(Window, Y, X, String) when is_integer(Window) andalso is_integer(Y)
149 andalso is_integer(X) andalso
150 is_list(String) ->
151 Str = lists:flatten(String),
152 call(?MVWADDSTR, {Window, Y, X, erlang:iolist_size(Str), Str}).
153
154 mvwaddch(Window, Y, X, Char) when is_integer(Window) andalso is_integer(Y)
155 andalso is_integer(X) ->
156 call(?MVWADDCH, {Window, Y, X, Char}).
157
158 wrefresh(Window) when is_integer(Window) ->
159 call(?WREFRESH, Window).
160
161 hline(Char, MaxN) ->
162 whline(?ceSTDSCR, Char, MaxN).
163
164 whline(Window, Char, MaxN) when is_integer(Window) andalso is_integer(MaxN) ->
165 call(?WHLINE, {Window, Char, MaxN}).
166
167 vline(Char, MaxN) ->
168 wvline(?ceSTDSCR, Char, MaxN).
169
170 wvline(Window, Char, MaxN) when is_integer(Window) andalso is_integer(MaxN) ->
171 call(?WVLINE, {Window, Char, MaxN}).
172
173 border(Ls, Rs, Ts, Bs, TLs, TRs, BLs, BRs) ->
174 wborder(0, Ls, Rs, Ts, Bs, TLs, TRs, BLs, BRs).
175
176 wborder(Window, Ls, Rs, Ts, Bs, TLs, TRs, BLs, BRs)
177 when is_integer(Ls) andalso is_integer(Rs) andalso
178 is_integer(Ts) andalso is_integer(Bs) andalso
179 is_integer(TLs) andalso is_integer(TRs) andalso
180 is_integer(BLs) andalso is_integer(BRs) ->
181 call(?WBORDER, {Window, Ls, Rs, Ts, Bs, TLs, TRs, BLs, BRs}).
182
183 box(Window, Vert, Horz) when is_integer(Window) andalso is_integer(Vert) andalso
184 is_integer(Horz) ->
185 call(?BOX, {Window, Vert, Horz}).
186
187 keypad(Window, BFlag) when is_integer(Window) andalso is_boolean(BFlag) ->
188 call(?KEYPAD, {Window, BFlag}).
189
7f6fd67 @mazenharake Added async-input.
authored
190 getch() ->
191 cecho_srv:getch().
192
4769266 @mazenharake Merge commit 'd10041ce14e2f1ba8c52ecea267479156ea1e1c9' into input
authored
193 %% =============================================================================
194 %% Behaviour Callbacks
195 %% =============================================================================
196 start(_, _) ->
197 cecho_srv:start_link().
198
199 stop(_) ->
200 ok.
201
202 %% =============================================================================
203 %% Internal Functions
204 %% =============================================================================
205 call(Cmd) ->
b401218 Changed so that a call to the c port with no arguments now sends
Mazen Harake authored
206 call(Cmd, undefined).
4769266 @mazenharake Merge commit 'd10041ce14e2f1ba8c52ecea267479156ea1e1c9' into input
authored
207
208 call(Cmd, Args) ->
209 cecho_srv:call(Cmd, Args).
Something went wrong with that request. Please try again.