Module: MiniTerm
- Defined in:
- lib/mini_term.rb,
lib/mini_term/ansi.rb,
lib/mini_term/version.rb,
lib/mini_term/windows.rb,
lib/mini_term/ansi/output.rb,
lib/mini_term/windows/link.rb,
lib/mini_term/ansi/set_posn.rb,
lib/mini_term/common/mapper.rb,
lib/mini_term/ansi/raw_input.rb,
lib/mini_term/ansi/term_info.rb,
lib/mini_term/windows/output.rb,
lib/mini_term/common/char_defs.rb,
lib/mini_term/common/raw_input.rb,
lib/mini_term/common/term_info.rb,
lib/mini_term/windows/set_posn.rb,
lib/mini_term/windows/raw_input.rb,
lib/mini_term/windows/term_info.rb,
lib/mini_term/windows/win_32_api.rb,
lib/mini_term/common/mapped_input.rb
Overview
Get input from the user in mapped mode. (Common Code)
Defined Under Namespace
Constant Summary collapse
- TERM_PLATFORM =
What operating platform is in effect?
case host_os when /mswin|msys|mingw|bccwin|wince|emc/ :windows when /cygwin/ :cygwin when /darwin|mac os/ :macosx when /linux/ :linux when /solaris|bsd/ :unix else raise "Unknown os: #{host_os.inspect}" end
- TERM_TYPE =
(TERM_PLATFORM == :windows) ? :windows : :ansi
- TERM_JAVA =
Is Java present in the environment?
(RUBY_PLATFORM =~ /java/) ? true : false
- VALID_OPTIONS =
What options are supported in this Windows?
[:quiet, :strict, :pass_ctrl_s, :pass_ctrl_c].freeze
- VERSION =
"0.1.4".freeze
- DESCRIPTION =
"mini_term: A portable encapsulation of the console terminal.".freeze
- STDIN_ID =
The magic numbers for the handles.
-10
- STDOUT_ID =
-11
- BELL =
"\x07"- LINE_FEED =
"\x0A"- CARRIAGE_RETURN =
"\x0D"- ESCAPE =
"\x1B"- PREFIX_00 =
These are mostly used in Windows maps.
0x00.chr
- PREFIX_E0 =
0xE0.chr
- FLUSH_SLEEP =
Control values for flush.
0.01- FLUSH_COUNT =
3- WAIT_SLEEP =
The sleep interval waiting for a key to be pressed.
0.02- TERM_MODE_MASK =
0xFFFFFFFF- ENABLE_LINE_INPUT =
0x00000002- ENABLE_PROCESSED_INPUT =
0x00000001
Class Method Summary collapse
-
.add_map(type, &defn_block) ⇒ Object
Add a terminal mapping.
-
.ansi? ⇒ Boolean
Is this ANSI?.
-
.beep ⇒ Object
Sound a beep.
-
.clear_screen ⇒ Object
Clear the screen and home the cursor.
- .close ⇒ Object
-
.flush ⇒ Object
Flush the keyboard buffer.
-
.get_mapped_char(&block) ⇒ Object
Get a mapped character.
-
.get_raw_char ⇒ Object
Get a uncooked character keystroke.
-
.has_raw_char? ⇒ Boolean
Is there a character waiting?.
-
.height ⇒ Object
What is the terminal height in rows?.
-
.java? ⇒ Boolean
Are we running under Java?.
-
.map_types ⇒ Object
What terminal types are mapped?.
- .open(options = {}) ⇒ Object
-
.print(text) ⇒ Object
Put some text onto the screen.
-
.raw ⇒ Object
Execute the block with input in raw mode.
-
.raw? ⇒ Boolean
Is raw mode in effect?.
-
.set_posn(row: get_cursor_row, column:) ⇒ Object
Set the row (optional) and column of the cursor.
-
.stdin_handle ⇒ Object
Well, stdin’s handle in particular.
-
.stdout_handle ⇒ Object
Well, stdout’s handle in particular.
-
.term_info ⇒ Object
Get term_info [rows, cols].
-
.term_open? ⇒ Boolean
Is the mini_term open just now?.
-
.width ⇒ Object
What is the terminal width in characters?.
-
.windows? ⇒ Boolean
Is this Windows?.
Class Method Details
.add_map(type, &defn_block) ⇒ Object
Add a terminal mapping.
17 18 19 |
# File 'lib/mini_term/common/mapped_input.rb', line 17 def self.add_map(type, &defn_block) @maps[type] = Mapper.new(&defn_block) end |
.ansi? ⇒ Boolean
Is this ANSI?
44 45 46 |
# File 'lib/mini_term.rb', line 44 def self.ansi? TERM_TYPE == :ansi end |
.beep ⇒ Object
Sound a beep
13 14 15 16 17 |
# File 'lib/mini_term/ansi/output.rb', line 13 def self.beep STDERR.write(BELL) STDERR.flush self end |
.clear_screen ⇒ Object
Clear the screen and home the cursor
20 21 22 23 |
# File 'lib/mini_term/ansi/output.rb', line 20 def self.clear_screen STDOUT.print("\e[f\e[2J") self end |
.close ⇒ Object
15 16 17 18 19 |
# File 'lib/mini_term/common/term_info.rb', line 15 def self.close end_raw_input if raw? @term_open = false @options = nil end |
.flush ⇒ Object
Flush the keyboard buffer.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mini_term/common/raw_input.rb', line 27 def self.flush result = "" raw do |input| FLUSH_COUNT.times do sleep(FLUSH_SLEEP) break unless input.has_raw_char? result << input.get_raw_char end end result end |
.get_mapped_char(&block) ⇒ Object
Get a mapped character. Note: The block is for testing only.
22 23 24 25 26 |
# File 'lib/mini_term/common/mapped_input.rb', line 22 def self.get_mapped_char(&block) mapper = @maps[MiniTerm::TERM_TYPE] proc = block_given? ? block : Proc.new { get_raw_char } raw { mapper.get_mapped_char(&proc) } end |
.get_raw_char ⇒ Object
Get a uncooked character keystroke.
12 13 14 15 |
# File 'lib/mini_term/ansi/raw_input.rb', line 12 def self.get_raw_char fail MiniTermNotRaw, "Not in raw mode." unless raw? STDIN.getch end |
.has_raw_char? ⇒ Boolean
Is there a character waiting?
7 8 9 |
# File 'lib/mini_term/ansi/raw_input.rb', line 7 def self.has_raw_char? raw { STDIN.ready? } end |
.height ⇒ Object
What is the terminal height in rows?
40 41 42 |
# File 'lib/mini_term/common/term_info.rb', line 40 def self.height term_info[0] end |
.java? ⇒ Boolean
Are we running under Java?
49 50 51 |
# File 'lib/mini_term.rb', line 49 def self.java? TERM_JAVA end |
.map_types ⇒ Object
What terminal types are mapped?
12 13 14 |
# File 'lib/mini_term/common/mapped_input.rb', line 12 def self.map_types @maps.keys end |
.open(options = {}) ⇒ Object
9 10 11 12 13 |
# File 'lib/mini_term/common/term_info.rb', line 9 def self.open( = {}) @term_open = true @options = end |
.print(text) ⇒ Object
Put some text onto the screen.
7 8 9 10 |
# File 'lib/mini_term/ansi/output.rb', line 7 def self.print(text) STDOUT.print(text) self end |
.raw ⇒ Object
Execute the block with input in raw mode.
19 20 21 22 23 24 |
# File 'lib/mini_term/common/raw_input.rb', line 19 def self.raw begin_raw_input unless (already_raw = raw?) yield(self) ensure end_raw_input unless already_raw end |
.raw? ⇒ Boolean
Is raw mode in effect?
14 15 16 |
# File 'lib/mini_term/common/raw_input.rb', line 14 def self.raw? @raw_input end |
.set_posn(row: get_cursor_row, column:) ⇒ Object
Set the row (optional) and column of the cursor.
7 8 9 10 11 12 13 14 15 |
# File 'lib/mini_term/ansi/set_posn.rb', line 7 def self.set_posn(row: nil, column:) if row STDOUT.print("\e[#{row};#{column}f") else STDOUT.print("\e#{column}G") end self end |
.stdin_handle ⇒ Object
Well, stdin’s handle in particular.
23 24 25 |
# File 'lib/mini_term/windows/link.rb', line 23 def self.stdin_handle get_handle(STDIN_ID) end |
.stdout_handle ⇒ Object
Well, stdout’s handle in particular.
18 19 20 |
# File 'lib/mini_term/windows/link.rb', line 18 def self.stdout_handle get_handle(STDOUT_ID) end |
.term_info ⇒ Object
Get term_info [rows, cols]
7 8 9 |
# File 'lib/mini_term/ansi/term_info.rb', line 7 def self.term_info IO.console.winsize end |
.term_open? ⇒ Boolean
Is the mini_term open just now?
22 23 24 |
# File 'lib/mini_term/common/term_info.rb', line 22 def self.term_open? @term_open end |
.width ⇒ Object
What is the terminal width in characters?
35 36 37 |
# File 'lib/mini_term/common/term_info.rb', line 35 def self.width term_info[1] end |
.windows? ⇒ Boolean
Is this Windows?
39 40 41 |
# File 'lib/mini_term.rb', line 39 def self.windows? TERM_TYPE == :windows end |