added some notes
[k8lst.git] / modules / slang.st
blobbf718b46e0e4a3b66f59437060c12d2ba9cc3852
2  Little Smalltalk, Version 5
4  Copyright (C) 1987-2005 by Timothy A. Budd
5  Copyright (C) 2007 by Charles R. Childers
6  Copyright (C) 2005-2007 by Danny Reinhold
7  Copyright (C) 2010 by Ketmar // Vampire Avalon
9  ============================================================================
10  This license applies to the virtual machine and to the initial image of
11  the Little Smalltalk system and to all files in the Little Smalltalk
12  packages except the files explicitly licensed with another license(s).
13  ============================================================================
14  Permission is hereby granted, free of charge, to any person obtaining a copy
15  of this software and associated documentation files (the 'Software'), to deal
16  in the Software without restriction, including without limitation the rights
17  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18  copies of the Software, and to permit persons to whom the Software is
19  furnished to do so, subject to the following conditions:
21  The above copyright notice and this permission notice shall be included in
22  all copies or substantial portions of the Software.
24  THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30  DEALINGS IN THE SOFTWARE.
32 Requires [
33   ffi
36 Package [
37   SLang
41 FFI subclass: SLang | SLangSingleton | [
42 |so|
43 ^singleton [
44   SLangSingleton ifNil: [SLangSingleton <- self basicNew open].
45   ^SLangSingleton.
48 open [
49   so <- FFI new: 'libslang'.
50   #(
51     'SLang_getkey_intr_hook'
52     'SLang_getkey'
53     'SLang_init_tty'
54     'SLang_input_pending'
55     'SLang_reset_tty'
56     'SLang_ungetkey'
58     'SLkp_init'
59     'SLkp_getkey'
61     'SLsignal_intr'
63     'SLsmg_cls'
64     'SLsmg_draw_box'
65     'SLsmg_erase_eos'
66     'SLsmg_fill_region'
67     'SLsmg_gotorc'
68     'SLsmg_init_smg'
69     'SLsmg_read_raw'
70     'SLsmg_refresh'
71     'SLsmg_reinit_smg'
72     'SLsmg_reset_smg'
73     'SLsmg_resume_smg'
74     'SLsmg_set_char_set'
75     'SLsmg_set_color'
76     'SLsmg_suspend_smg'
77     'SLsmg_touch_lines'
78     'SLsmg_write_char'
79     'SLsmg_write_nstring'
80     'SLsmg_write_raw'
81     'SLsmg_write_string'
83     'SLtt_beep'
84     'SLtt_get_screen_size'
85     'SLtt_get_terminfo'
86     'SLtt_set_color'
87     'SLtt_set_cursor_visibility'
88     'SLtt_set_mono'
89     'SLtt_tgetstr'
91     'SLtt_Screen_Cols'
92     'SLtt_Screen_Rows'
93     'SLtt_Use_Ansi_Colors'
94   ) do: [ :elem | so add: elem asSymbol ].
97 init [
98   so call: ('SLang_init_tty' asSymbol) args: #(-1 0 0).
99   so call: ('SLtt_get_terminfo' asSymbol).
100   so call: ('SLkp_init' asSymbol).
101   so call: ('SLsmg_init_smg' asSymbol).
102   so call: ('SLtt_set_cursor_visibility' asSymbol) arg: 0.
105 reset [
106   so call: ('SLtt_set_cursor_visibility' asSymbol) arg: 1.
107   so call: ('SLsmg_reset_smg' asSymbol).
108   so call: ('SLang_reset_tty' asSymbol).
111 drawBox: box [
112   so call: ('SLsmg_draw_box' asSymbol) args: box.
115 refresh [
116   so call: ('SLsmg_refresh' asSymbol) arg: 1.
119 screenCols [
120   ^so getInt: ('SLtt_Screen_Cols' asSymbol).
123 screenRows [
124   ^so getInt: ('SLtt_Screen_Rows' asSymbol).
127 pendingInput: t [
128   ^so callInt: ('SLang_input_pending' asSymbol) arg: t.
131 flushInput [
132   [(self pendingInput: 0) ~= 0] whileTrue: [self getKey].
135 getKey [
136   ^so callInt: ('SLkp_getkey' asSymbol).
139 goto: rowCol [
140   so call: ('SLsmg_gotorc' asSymbol) args: rowCol.
143 gotoRow: r col: c [
144   |rowCol|
145   rowCol <- Array new: 2.
146   rowCol at: 1 put: r.
147   rowCol at: 2 put: c.
148   so call: ('SLsmg_gotorc' asSymbol) args: rowCol.
151 writeString: s [
152   so call: ('SLsmg_write_string' asSymbol) arg: s.
155 writeString: s at: rowCol [
156   self goto: rowCol. self writeString: s.
159 normalCharSet [
160   so call: 'SLsmg_set_char_set' asSymbol arg: 0.
163 lineCharSet [
164   so call: 'SLsmg_set_char_set' asSymbol arg: 1.
167 writeChar: c [
168   so call: ('SLsmg_write_char' asSymbol) arg: c.
171 writeChar: c at: rowCol [
172   self goto: rowCol.  self writeChar: c.
175 clearScreen [
176   so call: ('SLsmg_cls' asSymbol).
179 close [
180   so close.
185 Object subclass: SLComponent [
186 | sl top left height width |
187 ^new [
188   ^self basicNew initialize.
191 initialize [
192   sl <- SLang singleton.