win32console 1.3.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,66 @@
1
+ # The WINDOWS constants
2
+
3
+ module Win32
4
+ class Console
5
+ module Constants
6
+ STD_INPUT_HANDLE = 0xFFFFFFF6
7
+ STD_OUTPUT_HANDLE = 0xFFFFFFF5
8
+ STD_ERROR_HANDLE = 0xFFFFFFF4
9
+ INVALID_HANDLE_VALUE = 0xFFFFFFFF
10
+ GENERIC_READ = 0x80000000
11
+ GENERIC_WRITE = 0x40000000
12
+ FILE_SHARE_READ = 0x00000001
13
+ FILE_SHARE_WRITE = 0x00000002
14
+ CONSOLE_TEXTMODE_BUFFER = 0x00000001
15
+
16
+ FOREGROUND_BLUE = 0x0001
17
+ FOREGROUND_GREEN = 0x0002
18
+ FOREGROUND_RED = 0x0004
19
+ FOREGROUND_INTENSITY = 0x0008
20
+ BACKGROUND_BLUE = 0x0010
21
+ BACKGROUND_GREEN = 0x0020
22
+ BACKGROUND_RED = 0x0040
23
+ BACKGROUND_INTENSITY = 0x0080
24
+
25
+ ENABLE_PROCESSED_INPUT = 0x0001
26
+ ENABLE_LINE_INPUT = 0x0002
27
+ ENABLE_ECHO_INPUT = 0x0004
28
+ ENABLE_WINDOW_INPUT = 0x0008
29
+ ENABLE_MOUSE_INPUT = 0x0010
30
+ ENABLE_PROCESSED_OUTPUT = 0x0001
31
+ ENABLE_WRAP_AT_EOL_OUTPUT = 0x0002
32
+
33
+ KEY_EVENT = 0x0001
34
+ MOUSE_EVENT = 0x0002
35
+ WINDOW_BUFFER_SIZE_EVENT = 0x0004
36
+ MENU_EVENT = 0x0008
37
+ FOCUS_EVENT = 0x0010
38
+
39
+ CAPSLOCK_ON = 0x0080
40
+ ENHANCED_KEY = 0x0100
41
+ NUMLOCK_ON = 0x0020
42
+ SHIFT_PRESSED = 0x0010
43
+ LEFT_CTRL_PRESSED = 0x0008
44
+ RIGHT_CTRL_PRESSED = 0x0004
45
+ LEFT_ALT_PRESSED = 0x0002
46
+ RIGHT_ALT_PRESSED = 0x0001
47
+ SCROLLLOCK_ON = 0x0040
48
+
49
+ MOUSE_WHEELED = 0x0004
50
+ DOUBLE_CLICK = 0x0002
51
+ MOUSE_MOVED = 0x0001
52
+
53
+ FROM_LEFT_1ST_BUTTON_PRESSED = 0x0001
54
+ FROM_LEFT_2ND_BUTTON_PRESSED = 0x0004
55
+ FROM_LEFT_3RD_BUTTON_PRESSED = 0x0008
56
+ FROM_LEFT_4TH_BUTTON_PRESSED = 0x0010
57
+ RIGHTMOST_BUTTON_PRESSED = 0x0002
58
+
59
+ CTRL_C_EVENT = 0x0000
60
+ CTRL_BREAK_EVENT = 0x0001
61
+ CTRL_CLOSE_EVENT = 0x0002
62
+ CTRL_LOGOFF_EVENT = 0x0005
63
+ CTRL_SHUTDOWN_EVENT = 0x0006
64
+ end
65
+ end
66
+ end
@@ -0,0 +1 @@
1
+ require 'Win32/Console/ANSI'
data/tasks/gem.rake ADDED
@@ -0,0 +1,31 @@
1
+ require 'hoe'
2
+
3
+ HOE = Hoe.spec 'win32console' do
4
+ self.version = '1.3.0.beta1'
5
+
6
+ developer 'Gonzalo Garramuno', 'ggarra@advancedsl.com.ar'
7
+ developer 'Justin Bailey', 'jgbailey@gmail.com'
8
+ developer 'Luis Lavena', 'luislavena@gmail.com'
9
+
10
+ self.rubyforge_name = 'winconsole'
11
+
12
+ spec_extras[:required_ruby_version] = Gem::Requirement.new('>= 1.8.6')
13
+
14
+ spec_extras[:extensions] = ["ext/Console_ext/extconf.rb"]
15
+
16
+ extra_rdoc_files.push *FileList['extra/*.rdoc']
17
+
18
+ spec_extras[:rdoc_options] = proc do |rdoc_options|
19
+ rdoc_options << "--exclude" << "ext"
20
+ end
21
+
22
+ extra_dev_deps << ['rake-compiler', "~> 0.7.0"]
23
+ end
24
+
25
+ file "#{HOE.spec.name}.gemspec" => ['Rakefile', 'tasks/gem.rake'] do |t|
26
+ puts "Generating #{t.name}"
27
+ File.open(t.name, 'w') { |f| f.puts HOE.spec.to_yaml }
28
+ end
29
+
30
+ desc "Generate or update the standalone gemspec file for the project"
31
+ task :gemspec => ["#{HOE.spec.name}.gemspec"]
data/tasks/native.rake ADDED
@@ -0,0 +1,14 @@
1
+ # use rake-compiler for building the extension
2
+ require 'rake/extensiontask'
3
+
4
+ Rake::ExtensionTask.new('Console_ext', HOE.spec) do |ext|
5
+ # FIXME: enable cross compilation to build fat binaries
6
+ ext.cross_compile = true
7
+ ext.cross_platform = ['i386-mingw32', 'i386-mswin32-60']
8
+
9
+ # place extension binaries inside lib/X.Y
10
+ if RUBY_PLATFORM =~ /mingw|mswin/
11
+ RUBY_VERSION =~ /(\d+.\d+)/
12
+ ext.lib_dir = "lib/#{$1}"
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "Win32/Console"
4
+
5
+
6
+ a = Win32::Console.new(STD_OUTPUT_HANDLE)
7
+
8
+ puts "Setting cursor to visible and 100% fat"
9
+ a.Cursor(-1,-1,100,1)
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "Win32/Console"
4
+
5
+ a = Win32::Console.new()
6
+ puts "# of Mouse buttons: #{Win32::Console.MouseButtons}"
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "Win32/Console"
4
+
5
+ include Win32::Console::Constants
6
+ a = Win32::Console.new(STD_INPUT_HANDLE)
7
+
8
+ puts "InputChar: Type a phrase then ENTER, please:"
9
+
10
+ x1 = a.InputChar(1)
11
+ puts "Your phrase starts with the character #{x1}"
12
+
13
+
14
+ fdwMode = ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT
15
+
16
+ a.Mode(fdwMode)
17
+
18
+ puts
19
+ puts "PeekInput: Type a character without ENTER or do something, please:"
20
+
21
+ while (x1 = a.PeekInput()).size < 1
22
+ end
23
+
24
+ if x1[0] == KEY_EVENT
25
+ puts "You typed #{x1[5]}='#{x1[5].chr}'"
26
+ else
27
+ print "You did not typed, but "
28
+ case x1[0]
29
+ when MOUSE_EVENT
30
+ puts "used mouse"
31
+ when WINDOW_BUFFER_SIZE_EVENT
32
+ puts "resize window"
33
+ when MENU_EVENT
34
+ puts "called menu"
35
+ when FOCUS_EVENT
36
+ puts "changed focus"
37
+ else
38
+ puts "...should never get here"
39
+ end
40
+ end
41
+
42
+ puts
43
+ puts "Input (as PeekInput keeps event, this reuses PeekInput value):"
44
+ x1 = a.Input()
45
+ if x1[0] == KEY_EVENT
46
+ puts "You typed #{x1[5]}='#{x1[5].chr}'"
47
+ else
48
+ print "You did not typed, but "
49
+ case x1[0]
50
+ when MOUSE_EVENT
51
+ puts "used mouse"
52
+ when WINDOW_BUFFER_SIZE_EVENT
53
+ puts "resize window"
54
+ when MENU_EVENT
55
+ puts "called menu"
56
+ when FOCUS_EVENT
57
+ puts "changed focus"
58
+ else
59
+ puts "...should never get here"
60
+ end
61
+ end
62
+
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "Win32/Console"
4
+
5
+ include Win32::Console::Constants
6
+ a = Win32::Console.new(STD_OUTPUT_HANDLE)
7
+
8
+ puts <<'EOF'
9
+ This is a simple
10
+ test of test to grab
11
+ from the console.
12
+ Hopefully this will work
13
+ easily and merrily.
14
+ This is a simple
15
+ test of test to grab
16
+ from the console.
17
+ Hopefully this will work
18
+ easily and merrily.
19
+ This is a simple
20
+ test of test to grab
21
+ from the console.
22
+ Hopefully this will work
23
+ easily and merrily.
24
+ EOF
25
+
26
+ x1 = a.ReadChar(10,10,10)
27
+ x2 = a.ReadAttr(10,10,10)
28
+ x3 = a.ReadRect(10,10,20,10)
29
+ puts "ReadChar .#{x1}."
30
+ puts x2.class, x2.size
31
+ print "ReadAttr ."
32
+ for i in x2
33
+ print "#{i}|"
34
+ end
35
+ print "\nReadRect ."
36
+
37
+ i = 0
38
+ while i < x3.length-1
39
+ print "#{x3[i]}"
40
+ i += 2
41
+ end
42
+ print "\n "
43
+ i = 1
44
+ while i < x3.length-1
45
+ print "#{x3[i]}|"
46
+ i += 2
47
+ end
48
+ print "\n"
49
+
50
+ #puts "read=",x1
51
+ #print "Attributes:",x2
52
+
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "Win32/Console"
4
+
5
+
6
+ i = 0
7
+ begin
8
+ while i < 99
9
+ if i == 10
10
+ Win32::Console::GenerateCtrlEvent()
11
+ end
12
+ i = i.next
13
+ end
14
+ rescue Exception
15
+ end
16
+
17
+ puts "if i=10, then OK! i=#{i}"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "Win32/Console"
4
+
5
+ a = Win32::Console.new()
6
+
7
+ title = a.Title()
8
+ puts "Old title: \"#{title}\""
9
+
10
+ a.Title("This is a new title")
11
+ title = a.Title()
12
+ puts "I just changed the title to '#{title}'"
13
+
14
+ sleep(5)
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ require 'rubygems'
4
+ require 'term/ansicolor'
5
+ include Term::ANSIColor
6
+ rescue LoadError
7
+ puts "You need term-ansicolor gem installed to run this test"
8
+ puts "Please 'gem install term-ansicolor' and try again."
9
+ end
10
+
11
+ require "benchmark"
12
+ require "Win32/Console/ANSI"
13
+
14
+ Benchmark.bm do |x|
15
+ num = 100
16
+ x.report("#{num} times") {
17
+ 0.upto(num) {
18
+ print "\e[2J"
19
+
20
+ print red, bold, "Usage as constants:", reset, "\n"
21
+
22
+ print clear, "clear", reset, reset, "reset", reset,
23
+ bold, "bold", reset, dark, "dark", reset,
24
+ underscore, "underscore", reset, blink, "blink", reset,
25
+ negative, "negative", reset, concealed, "concealed", reset, "|\n",
26
+ black, "black", reset, red, "red", reset, green, "green", reset,
27
+ yellow, "yellow", reset, blue, "blue", reset, magenta, "magenta", reset,
28
+ cyan, "cyan", reset, white, "white", reset, "|\n",
29
+ on_black, "on_black", reset, on_red, "on_red", reset,
30
+ on_green, "on_green", reset, on_yellow, "on_yellow", reset,
31
+ on_blue, "on_blue", reset, on_magenta, "on_magenta", reset,
32
+ on_cyan, "on_cyan", reset, on_white, "on_white", reset, "|\n\n"
33
+ print "\e[s\e[20P.................."
34
+ }
35
+ }
36
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: win32console
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - Gonzalo Garramuno
8
+ - Justin Bailey
9
+ - Luis Lavena
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2009-12-29 00:00:00 -03:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: rake-compiler
19
+ type: :development
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ~>
24
+ - !ruby/object:Gem::Version
25
+ version: 0.7.0
26
+ version:
27
+ - !ruby/object:Gem::Dependency
28
+ name: hoe
29
+ type: :development
30
+ version_requirement:
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 2.4.0
36
+ version:
37
+ description: |-
38
+ Win32::Console allows controling the windows command line terminal
39
+ thru an OO-interface. This allows you to query the terminal (find
40
+ its size, characters, attributes, etc). The interface and functionality
41
+ should be identical to Perl's counterpart.
42
+
43
+ A port of Perl's Win32::Console and Win32::Console::ANSI modules.
44
+
45
+ This gem packages Gonzalo Garramuno's Win32::Console project, and includes
46
+ a compiled binary for speed. The Win32::Console project's home can be
47
+ found at:
48
+
49
+ http://rubyforge.org/projects/win32console
50
+ email:
51
+ - ggarra@advancedsl.com.ar
52
+ - jgbailey@gmail.com
53
+ - luislavena@gmail.com
54
+ executables: []
55
+
56
+ extensions:
57
+ - ext/Console_ext/extconf.rb
58
+ extra_rdoc_files:
59
+ - History.txt
60
+ - Manifest.txt
61
+ - README.txt
62
+ - extra/Console.rdoc
63
+ - extra/Console_ANSI.rdoc
64
+ files:
65
+ - History.txt
66
+ - Manifest.txt
67
+ - Rakefile
68
+ - README.txt
69
+ - ext/Console_ext/Console.c
70
+ - ext/Console_ext/extconf.rb
71
+ - extra/Console.rdoc
72
+ - extra/Console_ANSI.rdoc
73
+ - lib/win32console.rb
74
+ - lib/Win32/Console.rb
75
+ - lib/Win32/Console/ANSI.rb
76
+ - lib/Win32/Console/api.rb
77
+ - lib/Win32/Console/constants.rb
78
+ - tasks/gem.rake
79
+ - tasks/native.rake
80
+ - test/test_cursor.rb
81
+ - test/test_mouse.rb
82
+ - test/test_readinput.rb
83
+ - test/test_readoutput.rb
84
+ - test/test_sendevent.rb
85
+ - test/test_title.rb
86
+ - test/test_write.rb
87
+ has_rdoc: true
88
+ homepage: http://rubyforge.org/projects/winconsole
89
+ licenses: []
90
+
91
+ post_install_message:
92
+ rdoc_options:
93
+ - --main
94
+ - README.txt
95
+ - --exclude
96
+ - ext
97
+ require_paths:
98
+ - lib
99
+ - ext
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 1.8.6
105
+ version:
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.3.1
111
+ version:
112
+ requirements: []
113
+
114
+ rubyforge_project: winconsole
115
+ rubygems_version: 1.3.5
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Win32::Console allows controling the windows command line terminal thru an OO-interface
119
+ test_files:
120
+ - test/test_mouse.rb
121
+ - test/test_readoutput.rb
122
+ - test/test_write.rb
123
+ - test/test_readinput.rb
124
+ - test/test_sendevent.rb
125
+ - test/test_title.rb
126
+ - test/test_cursor.rb