mini_term 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3390b9651f5aeaf92e8492f85ef061675d70b0e
4
+ data.tar.gz: 83dafaec60ff3e9b117cd3e323b7c11b59123593
5
+ SHA512:
6
+ metadata.gz: 5646e6678a067d6de0fdfe3236bfca2be7531ca35d9a286bbac96de1717b804403751f23d2e6a6344835088de073bb7c37efb9b85ce008b29cadf9edb7febbd4
7
+ data.tar.gz: 5542f74ac659a59b11cbb07c477d1fe5d3f9650a45a9e25810d036c56670ac53ce66ab340d9b6b7a68b5968362ea7b5245bcf7abb734c3f35c6833910fdd9964
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at peter.c.camilleri@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in mini_term.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 PeterCamilleri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,292 @@
1
+ # MiniTerm
2
+
3
+ The MiniTerm gem is a simple bit of code that seeks to smooth over the bumps
4
+ and pot holes encountered when interacting with the console terminal to create
5
+ console based CLI applications. More than most it also seeks to eliminate
6
+ worries about the nasty cross-platform issues encountered between Windows,
7
+ Linux, and MAC OS-X systems.
8
+
9
+ This code started out its life buried deep within the code of the mini readline
10
+ gem where it helped that gem do its job. A while ago it was realized that the
11
+ services provided were invaluable for a much wider range of development. I was
12
+ increasingly frustrated by my need to "go-around" mini readline to get at some
13
+ of its lower level features. When that happens it is a clear sign that a gem is
14
+ doing too much and has too many responsibilities.
15
+
16
+ That's why the low level terminal functionality was split out into the mini
17
+ term gem contained in this code repository. At the same time, the lessons
18
+ learned from the earlier version of the code have been applied to make this
19
+ code better and also not any more incompatible than needed. Since mini readline
20
+ was the only "user" of the old code, moving out in some new directions should
21
+ not pose a migration issue except for me.
22
+
23
+ Finally, this gem would not be possible without the excellent insight into the
24
+ gnarly world of win_32_api, dl, and fiddle I gained reading and copying the
25
+ code in the [ConnorAtherton/rb-readline](https://github.com/ConnorAtherton/rb-readline)
26
+ project and gem. *Thank You!*
27
+
28
+ So, what hurdles do we expect the mini term gem to overcome? What cross-platform
29
+ issues vex us? After all, it's not as if Ruby ignores the issue of low-level
30
+ console access. It has the io/console and io/wait code libraries. They are
31
+ supposed to give low level access right?
32
+
33
+ And this is the point where the wheels start falling off.
34
+
35
+ * The io/console library has truly awful documentation. Many methods lack any
36
+ sort of description or meaningful parameter names. The developer is left to
37
+ reverse engineering the behavior of the code. The programming process borders
38
+ on the tribal. In this regard, io/wait is OK. Too bad it only plays a limited
39
+ role.
40
+
41
+ * The io/console library does not work correctly under Windows. And before we
42
+ hear a chorus of "Switch to Linux", the anti-windows squad are reminded that
43
+ this is a cross-platform tool, just like Ruby is supposed to be. The issue is
44
+ that raw mode is not so raw under windows. In fact it's so cooked that it more
45
+ resembles a chunk of charcoal! It just plain does not work. Fortunately there
46
+ is an answer. Ruby has access to the various APIs though the 'fiddle' gem.
47
+ This gem is used to emulate the deprecated 'win32api' gem.
48
+
49
+ * Under JRuby, the situation is even worse. The io/console facility is
50
+ incapable of manipulating the tty or console at all. A true non-starter. Only
51
+ here's where things take a twist for the weird. Under Windows, JRuby *does*
52
+ support the 'win32api' gem. It even works! I'm not at all sure how to support
53
+ JRuby under Linux or Mac OS-X.
54
+
55
+ * Working with Rubinius is perhaps the worst of all. Rubinius *still* does not
56
+ run under Windows. Until such time as I am able to develop under a supported
57
+ platform, or can collaborate with someone who can, this is a non-starter. Don't
58
+ stay tuned, don't hold your breath; This problem is *not* going away any time
59
+ soon.
60
+
61
+ #### So! What do we have?
62
+
63
+ This is a matrix of language versions and environments that have are tested or
64
+ have been tested at one time or another.
65
+
66
+ Ruby | Win32 | Win64 | Cygwin | Linux | Mac
67
+ ---------------|---------|---------|---------|---------|---------
68
+ ruby 2.1.6p336 | Yes? | Yes?? | Yes?? | Yes?? | Yes??
69
+ ruby 2.2.3p173 | Yes?? | Yes?? | Yes? | Yes?? | Yes??
70
+ ruby 2.3.3p222 | Yes?? | Yes | Yes?? | Yes?? | Yes??
71
+ jruby 9.1.5.0 | Yes? | Yes?? | Maybe? | Maybe? | Maybe?
72
+
73
+ This table will be updated as more information becomes available. Check the
74
+ [github repository](https://github.com/PeterCamilleri/mini_term) for the
75
+ latest info.
76
+
77
+ Notes:
78
+ * Mini term uses keyword parameters so Ruby 2.0 or later is required. This is
79
+ why older versions of Ruby have been removed from this table.
80
+ * Yes? means that this combination was once tested with very similar code and
81
+ should be OK, we hope. Testing would be nice.
82
+ * Yes?? means that this combination *should* work but needs testing.
83
+
84
+ ## Installation
85
+
86
+ Add this line to your application's Gemfile:
87
+
88
+ ```ruby
89
+ gem 'mini_term'
90
+ ```
91
+
92
+ And then execute:
93
+
94
+ $ bundle
95
+
96
+ Or install it yourself as:
97
+
98
+ $ gem install mini_term
99
+
100
+ ## Usage
101
+
102
+ The mini term can be used in a project with:
103
+
104
+ ```ruby
105
+ require 'mini_term'
106
+ ```
107
+
108
+ ### Interface Summary
109
+
110
+ The following is a brief summary of the public interface of the MiniTerm module:
111
+
112
+ **Constants**
113
+
114
+ VERSION -- A version string of the form "9.9.9"
115
+ DESCRIPTION -- A descriptive string.
116
+ VALID_OPTIONS -- An array of the supported option symbols.
117
+ TERM_TYPE -- Either :windows or :ansi
118
+ TERM_PLATFORM -- One of :windows, :cygwin, :macosx, :linux, or :unix
119
+
120
+ **Methods**
121
+
122
+ open(options), close, open?
123
+ term_info, width, height, ansi?, windows?, java?
124
+ set_posn(row: the_current_row, column:)
125
+ raw {}, raw?, begin_raw_input, end_raw_input
126
+ get_raw_char, has_raw_char? flush
127
+ get_mapped_char, add_map(type) {}, map_types
128
+ print(text), clear_screen
129
+
130
+
131
+ *MiniTerm.open* - Before it can be used, the mini term should be opened. This
132
+ is done with:
133
+
134
+ ```ruby
135
+ MiniTerm.open(options)
136
+ ```
137
+
138
+ The open method can take some optional arguments:
139
+
140
+ pass_ctrl_c: true # The control+c character is passed through to the application.
141
+ pass_ctrl_c: false # (Default) The control+c character is used by the OS.
142
+
143
+ pass_ctrl_s: true # The control+s character is passed through to the application.
144
+ pass_ctrl_s: false # (Default) The control+s character is used by the OS.
145
+
146
+ quiet: true # Suppress various warning messages.
147
+ quiet: false # (Default) Display warning message.
148
+
149
+ strict: true # Invalid options raise an exception.
150
+ strict: false # (Default) Invalid options cause no such fuss.
151
+
152
+
153
+ If an unsupported or invalid option is detected, a warning message is displayed
154
+ unless the quiet option is active. Alternatively, if the strict option is
155
+ enabled, the MiniTermStrict exception is raised in that case.
156
+
157
+ *MiniTerm.close* - The converse to open is close. It takes no arguments.
158
+
159
+ ```ruby
160
+ MiniTerm.close
161
+ ```
162
+
163
+ Rest assured that if your program should forget to close MiniTerm, the gem will
164
+ close itself automatically when your program exits. This ensures that the
165
+ terminal will not be left in a unworkable state. It will also tell you that it
166
+ had to "Force MiniTerm.close" unless it was opened with the quiet: true option.
167
+
168
+ *MiniTerm.terminfo, etc* - These methods return information about the current
169
+ MiniTerm operating environment.
170
+
171
+ ```ruby
172
+ MiniTerm.terminfo # Returns the console's number of [rows, columns]
173
+ MiniTerm.width # Returns the console's number of columns.
174
+ MiniTerm.height # Returns the console's number of rows.
175
+ MiniTerm.ansi? # Is ANSI mode active?
176
+ MiniTerm.windows? # Is Windows mode active?
177
+ MiniTerm.java? # Is Java active?
178
+ ```
179
+
180
+ *MiniTerm.set_posn* - This method is used to place the cursor anywhere on the
181
+ screen or anywhere in the current line.
182
+
183
+ ```ruby
184
+ set_posn(row: the_current_row, column:)
185
+ ```
186
+ Note: If the row parameter is omitted, the row remains on the current row. The
187
+ column parameter is always required.
188
+
189
+ *MiniTerm.raw, etc* - These methods controll the use of raw console input, one
190
+ of the major features provided by the MiniTerm gem. These methods are:
191
+
192
+ ```ruby
193
+ MiniTerm.raw {|self| } # Execute the block with raw mode active.
194
+ MiniTerm.raw? # Is raw mode active now?
195
+ ```
196
+
197
+ *MiniTerm.get_raw_char, etc* - These methods deal with the keyboard in a raw
198
+ mode. They do not echo or wait for the user to press enter or any of those
199
+ other cooked mode things. Keyboard data in the raw!
200
+
201
+ ```ruby
202
+ MiniTerm.get_raw_char # Wait for a keystroke in raw mode.
203
+ MiniTerm.has_raw_char? # Are there any keys waiting?
204
+ MiniTerm.flush # Flush any keys in the buffer.
205
+ ```
206
+
207
+ Note that the get_raw_char method needs to be run with raw mode in effect. See
208
+ the raw methods above for more on that. Also, in raw mode, some keys, especially
209
+ extended keys may be composed of more than one byte. These methods only return
210
+ one byte at a time.
211
+
212
+ *MiniTerm.get_mapped_char, etc* - A mapped character is one or more raw
213
+ characters that are mapped to an array containing a symbol and the characters
214
+ that pathed the mapping to that sysmbol. For example:
215
+
216
+ ```ruby
217
+ [:go_left, "\e[D"]
218
+ ```
219
+
220
+ The conversion process from a stream of raw bytes to commands is done with a
221
+ map. The method MiniTerm.add_map(type) {} takes one argument, the type, and a
222
+ block. The type is currently one of the two terminal types: :windows or :ansi.
223
+ The block also takes one argument, the newly created map. The code can then
224
+ define entries in the map as follows:
225
+
226
+ ```ruby
227
+ MiniTerm.add_map(:ansi) do |map|
228
+ map["\e[D"] = :go_left
229
+ # etc etc etc
230
+ end
231
+ ```
232
+
233
+ Now, the index for each entry represents a sort of path to the command. This
234
+ path must not be ambiguous. For example, the following will generate an error:
235
+
236
+ ```ruby
237
+ MiniTerm.add_map(:ansi) do |map|
238
+ map["\e"] = :cancel
239
+ map["\e[D"] = :go_left
240
+ # etc etc etc
241
+ end
242
+ ```
243
+
244
+ To understand this, imagine that this map were allowed. The user presses the
245
+ left arrow key. This generates the sequence "\e[D". The "\e" is received first
246
+ and mapped to a :cancel command by the first rule. Then the "[D" characters are
247
+ received and most likely inserted as these are printable characters. That is
248
+ not what is wanted because the left arrow key was mapped to the wrong actions.
249
+ This map is ambiguous mapping error is why MiniTerm signals a MiniTermKME error
250
+ when the map is created.
251
+
252
+ The method MiniTerm.map_types list the types for key maps that have been added.
253
+ In most cases this will be [:ansi, :windows]. A map should be defined for each
254
+ of the two term types, unless the application is only intended for one type.
255
+
256
+ #### Exceptions:
257
+
258
+ The mini term gem uses the following exception classes:
259
+
260
+ Exception # From Ruby.
261
+ StandardError # From Ruby.
262
+ MiniTermError # The abstract base exception for mini term.
263
+ MiniTermKME # A keyboard mapping error was detected.
264
+ MiniTermNoMap # No map can be found for the current terminal type.
265
+ MiniTermNotRaw # Raw mode is required for this operation.
266
+ MiniTermStrict # An exception raised due to strictness.
267
+ MiniTermWTF # An internal error happened. This shouldn't happen.
268
+
269
+ ## Contributing
270
+
271
+ 1. Fork it
272
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
273
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
274
+ 4. Push to the branch (`git push origin my-new-feature`)
275
+ 5. Create new Pull Request
276
+
277
+ OR...
278
+
279
+ * Make a suggestion by raising an
280
+ [issue](https://github.com/PeterCamilleri/mini_term/issues)
281
+ . All ideas and comments are welcome.
282
+
283
+ ## License
284
+
285
+ The gem is available as open source under the terms of the
286
+ [MIT License](./LICENSE.txt).
287
+
288
+ ## Code of Conduct
289
+
290
+ Everyone interacting in the mini_term project’s codebases, issue trackers,
291
+ chat rooms and mailing lists is expected to follow the
292
+ [code of conduct](./CODE_OF_CONDUCT.md).
data/exe/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # MiniTerm - Utilities and Demos
2
+
3
+ This section describes the simple utilities and demo programs that are included
4
+ with the mini_term gem. The applications are designed to ease writing and
5
+ testing of programs using mini_term. Then again, some are just for fun.
6
+
7
+ ## mapped_key_test
8
+
9
+ The mapped_key_test program is designed demonstrate the mapped input system.
10
+ The program comes with sample mappings for the supported systems and supports
11
+ the use of alternate maps as well.
12
+
13
+ If no arguments are given, the default maps are used.
14
+ The following shows a sample run with an input of "1234567890 Enter UpArrow
15
+ LeftArrow RightArrow DownArrow Tab Ctrl+z" with the default map under Windows.
16
+
17
+ 42 mysh>mapped_key_test
18
+
19
+ Testing Mapped Keyboard input. Press Ctrl+z to quit.
20
+ Current maps = [:windows, :ansi]
21
+ Current term type = :windows
22
+
23
+ action = :insert_text, text = ["1"]
24
+ action = :insert_text, text = ["2"]
25
+ action = :insert_text, text = ["3"]
26
+ action = :insert_text, text = ["4"]
27
+ action = :insert_text, text = ["5"]
28
+ action = :insert_text, text = ["6"]
29
+ action = :insert_text, text = ["7"]
30
+ action = :insert_text, text = ["8"]
31
+ action = :insert_text, text = ["9"]
32
+ action = :insert_text, text = ["0"]
33
+ action = :enter, text = ["\r"]
34
+ action = :previous_history, text = ["\xE0", "H"]
35
+ action = :go_left, text = ["\xE0", "K"]
36
+ action = :go_right, text = ["\xE0", "M"]
37
+ action = :next_history, text = ["\xE0", "P"]
38
+ action = :auto_complete, text = ["\t"]
39
+ action = :end_of_input, text = ["\u001A"]
40
+
41
+ Alternatively, the path(s) to a Ruby file(s) containing maps can be provided.
42
+ One such file is provided at samples/test_map.rb. this trivial map shows a
43
+ custom map in action.
44
+
45
+ 43 mysh>mapped_key_test samples\test_map.rb
46
+ Requiring 'C:/Sites/mini_term/samples/test_map.rb'
47
+
48
+ Testing Mapped Keyboard input. Press Ctrl+z to quit.
49
+ Current maps = [:windows, :ansi]
50
+ Current term type = :windows
51
+
52
+ action = :unmapped, text = ["1"]
53
+ action = :unmapped, text = ["2"]
54
+ action = :unmapped, text = ["3"]
55
+ action = :unmapped, text = ["4"]
56
+ action = :unmapped, text = ["5"]
57
+ action = :unmapped, text = ["6"]
58
+ action = :unmapped, text = ["7"]
59
+ action = :unmapped, text = ["8"]
60
+ action = :unmapped, text = ["9"]
61
+ action = :unmapped, text = ["0"]
62
+ action = :unmapped, text = ["\t"]
63
+ action = :end_of_input, text = ["\u001A"]
64
+
65
+ As mentioned before, this map doesn't do much but it does illustrate the basics
66
+ of creating a custom map.
67
+
68
+ ## mini_term_code_points
69
+
70
+ The purpose of the mini_term_code_points is to explore the glyphs associated
71
+ with the code points of characters sent to the console. Let's see what plain
72
+ old ASCII looks like:
73
+
74
+ 16 mysh>mini_term_code_points 20 7F
75
+ Code points in the range: 20...7F
76
+ 0 !"#$%&' ()*+,-./ 01234567 89:;<=>?
77
+ 40 @ABCDEFG HIJKLMNO PQRSTUVW XYZ[\]^_ `abcdefg hijklmno pqrstuvw xyz{|}~
78
+
79
+ While the other demo programs make direct use of the mini term gem, this one
80
+ does not. It simply allows the programmer to explore the extent of Unicode
81
+ support in the test environment.
82
+
83
+ Note: By default, the mini_term_code_points displays the first 65536 code
84
+ points which can take a while and will probably scroll away unless you pipe
85
+ it into more (or less) or have a deep scroll back buffer.
86
+
87
+ ## raw_key_test
88
+
89
+ This program is intended as a means to explore the key codes generated by the
90
+ keyboard. This will help in the process of designing a MiniTerm map or the
91
+ custom code to directly handle user input.
92
+
93
+ The program works by taking raw data from the keyboard and simply displaying it
94
+ in hex format. The program exits when the character "Q" is entered.
95
+
96
+ A sample run of this program, under Windows is shown below. In this example the
97
+ keys entered were "1234567890 *F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12* qQ"
98
+ where *F1* through *F12* represent the keyboard's "F" keys and spaces are added
99
+ only for clarity and where not entered.
100
+
101
+ 77 mysh>raw_key_test
102
+ Testing Raw Keyboard input. Press Q to quit.
103
+ [31][32][33][34][35][36][37][38][39][30][00][3B][00][3C][00][3D][00][3E][00][3F]
104
+ [00][40][00][41][00][42][00][43][00][44][E0][85][E0][86][71][51]
105
+
106
+ ## mini_term_blizzard
107
+
108
+ The other programs bundled with mini_term are serious practical utilities. They
109
+ all serve a purpose. The mini_term_blizzard is none of those things! When run,
110
+ it fills the console screen with _snow_.
111
+
112
+ Yup!
113
+
114
+ Snow!
115
+
116
+ If run with no arguments, it uses the asterisk ("*") for the snowflakes. It can
117
+ also take hex arguments that are the code point, or range of code points to be
118
+ used. The following looks really nice on my test machine:
119
+
120
+ mini_term_blizzard 2740 2749