]> gitweb.factorcode.org Git - factor.git/blob - extra/terminal/macosx/macosx.factor
classes.struct: moving to new/boa instead of <struct>/<struct-boa>
[factor.git] / extra / terminal / macosx / macosx.factor
1 ! Copyright (C) 2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: accessors alien.c-types classes.struct io.streams.c
5 kernel math memoize scratchpad system terminal unix unix.ffi ;
6
7 QUALIFIED-WITH: alien.c-types c
8
9 IN: terminal.macosx
10
11 <PRIVATE
12
13 CONSTANT: IOCPARM_MASK 0x1fff ! parameter length, at most 13 bits
14 CONSTANT: IOC_VOID 0x20000000 ! no parameters
15 CONSTANT: IOC_OUT  0x40000000 ! copy parameters out
16 CONSTANT: IOC_IN   0x80000000 ! copy parameters in
17
18 : _IOC ( inout group num len -- n )
19     [ 8 shift ] 2dip IOCPARM_MASK bitand 16 shift
20     bitor bitor bitor ;
21
22 : _IO ( group num -- n ) [ IOC_VOID ] 2dip 0 _IOC ;
23
24 : _IOCR ( group num len -- n ) [ IOC_OUT ] 3dip _IOC ;
25
26 : _IOCW ( group num len -- n ) [ IOC_IN ] 3dip _IOC ;
27
28 STRUCT: winsize
29 { ws_row c:short }
30 { ws_col c:short }
31 { ws_xpixel c:short }
32 { ws_ypixel c:short } ;
33
34 MEMO: TIOCGWINSZ ( -- x ) CHAR: t 104 winsize heap-size _IOCR ;
35
36 PRIVATE>
37
38 M: macosx (terminal-size)
39     stdout-handle fileno TIOCGWINSZ winsize new
40     [ ioctl ] keep swap 0 < [
41         drop 0 0
42     ] [
43         [ ws_col>> ] [ ws_row>> ] bi
44     ] if ;