ffi-ncurses 0.3.1 → 0.3.2
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.
- data/History.txt +5 -0
- data/Rakefile +5 -1
- data/examples/ncurses-example.rb +197 -0
- data/lib/ffi-ncurses.rb +1 -0
- data/lib/ffi-ncurses/darwin.rb +2 -0
- metadata +3 -2
data/History.txt
CHANGED
data/Rakefile
CHANGED
@@ -13,6 +13,10 @@ rescue LoadError
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
if File.exist?('local/config.rb')
|
17
|
+
load 'local/config.rb'
|
18
|
+
end
|
19
|
+
|
16
20
|
ensure_in_path 'lib'
|
17
21
|
require 'ffi-ncurses'
|
18
22
|
|
@@ -25,7 +29,7 @@ PROJ.authors = ["Sean O'Halpin"]
|
|
25
29
|
PROJ.email = 'sean.ohalpin@gmail.com'
|
26
30
|
PROJ.url = 'http://github.com/seanohalpin/ffi-ncurses'
|
27
31
|
PROJ.summary = "FFI wrapper for ncurses"
|
28
|
-
PROJ.version =
|
32
|
+
PROJ.version = FFI::NCurses::VERSION
|
29
33
|
PROJ.rubyforge.name = 'ffi-ncurses'
|
30
34
|
|
31
35
|
PROJ.description = <<EOT
|
@@ -0,0 +1,197 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# $Id: example.rb,v 1.4 2002/03/04 13:24:29 t-peters Exp $
|
4
|
+
|
5
|
+
# This file provides an example for the usage of the ncurses-ruby module.
|
6
|
+
# Copyright (C) 2002 Tobias Peters <t-peters@users.berlios.de>
|
7
|
+
#
|
8
|
+
# The following license applys only to this file. It is less restrictive
|
9
|
+
# than the license for the rest of the ncurses-ruby distribution.
|
10
|
+
# I've adapted this file from someone else, see below.
|
11
|
+
#
|
12
|
+
# Permission is hereby granted, free of charge, to any person
|
13
|
+
# obtaining a copy of this file
|
14
|
+
# (the "Software"), to deal in the Software without restriction,
|
15
|
+
# including without limitation the rights to use, copy, modify, merge,
|
16
|
+
# publish, distribute, sublicense, and/or sell copies of the Software,
|
17
|
+
# and to permit persons to whom the Software is furnished to do so,
|
18
|
+
# subject to the following conditions:
|
19
|
+
#
|
20
|
+
# The above copyright notice and this permission notice shall be
|
21
|
+
# included in all copies or substantial portions of the Software.
|
22
|
+
#
|
23
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
24
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
25
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
26
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
27
|
+
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
28
|
+
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
29
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
30
|
+
# SOFTWARE.
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
# this file is adapted from an example of the python ncurses binding
|
35
|
+
# pyncurses (http://pyncurses.sf.net/), which has the following copyright
|
36
|
+
# statement:
|
37
|
+
|
38
|
+
# Copyright (c) 2000 by Harry Henry Gebel
|
39
|
+
#
|
40
|
+
# Permission is hereby granted, free of charge, to any person
|
41
|
+
# obtaining a copy of this software and associated documentation files
|
42
|
+
# (the "Software"), to deal in the Software without restriction,
|
43
|
+
# including without limitation the rights to use, copy, modify, merge,
|
44
|
+
# publish, distribute, sublicense, and/or sell copies of the Software,
|
45
|
+
# and to permit persons to whom the Software is furnished to do so,
|
46
|
+
# subject to the following conditions:
|
47
|
+
#
|
48
|
+
# The above copyright notice and this permission notice shall be
|
49
|
+
# included in all copies or substantial portions of the Software.
|
50
|
+
#
|
51
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
52
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
53
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
54
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
55
|
+
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
56
|
+
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
57
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
58
|
+
# SOFTWARE.
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
require "ffi-ncurses"
|
63
|
+
|
64
|
+
module NcursesExtension
|
65
|
+
def method_missing(method, *args, &block)
|
66
|
+
FFI::NCurses.send(method, self.win, *args, &block)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
module Ncurses
|
71
|
+
FALSE = 0
|
72
|
+
TRUE = 1
|
73
|
+
module NCX
|
74
|
+
def COLS
|
75
|
+
FFI::NCurses.getmaxx(FFI::NCurses.stdscr)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
include NCX
|
79
|
+
extend NCX
|
80
|
+
class WINDOW
|
81
|
+
attr_accessor :win
|
82
|
+
def initialize(*args, &block)
|
83
|
+
if block_given?
|
84
|
+
@win = args.first
|
85
|
+
else
|
86
|
+
@win = FFI::NCurses.newwin(*args)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
def method_missing(name, *args)
|
90
|
+
name = name.to_s
|
91
|
+
if (name[0,2] == "mv")
|
92
|
+
test_name = name.dup
|
93
|
+
test_name[2,0] = "w" # insert "w" after"mv"
|
94
|
+
if (FFI::NCurses.respond_to?(test_name))
|
95
|
+
return FFI::NCurses.send(test_name, @win, *args)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
test_name = "w" + name
|
99
|
+
if (FFI::NCurses.respond_to?(test_name))
|
100
|
+
return FFI::NCurses.send(test_name, @win, *args)
|
101
|
+
end
|
102
|
+
FFI::NCurses.send(name, @win, *args)
|
103
|
+
end
|
104
|
+
def respond_to?(name)
|
105
|
+
name = name.to_s
|
106
|
+
if (name[0,2] == "mv" && FFI::NCurses.respond_to?("mvw" + name[2..-1]))
|
107
|
+
return true
|
108
|
+
end
|
109
|
+
FFI::NCurses.respond_to?("w" + name) || FFI::NCurses.respond_to?(name)
|
110
|
+
end
|
111
|
+
def del
|
112
|
+
FFI::NCurses.delwin(@win)
|
113
|
+
end
|
114
|
+
alias delete del
|
115
|
+
end
|
116
|
+
def self.initscr
|
117
|
+
@stdscr = Ncurses::WINDOW.new(FFI::NCurses.initscr) { }
|
118
|
+
end
|
119
|
+
def self.stdscr
|
120
|
+
@stdscr
|
121
|
+
end
|
122
|
+
class << self
|
123
|
+
def method_missing(method, *args, &block)
|
124
|
+
FFI::NCurses.send(method, *args, &block)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def moving(scr)
|
130
|
+
scr.clear() # clear screen
|
131
|
+
scr.move(5,5) # move cursor
|
132
|
+
scr.addstr("move(5,5)")
|
133
|
+
scr.refresh() # update screen
|
134
|
+
sleep(2)
|
135
|
+
scr.move(2,2)
|
136
|
+
scr.addstr("move(2,2)")
|
137
|
+
scr.refresh()
|
138
|
+
sleep(2)
|
139
|
+
scr.move(10, 2)
|
140
|
+
scr.addstr("Press a key to continue")
|
141
|
+
scr.getch()
|
142
|
+
end
|
143
|
+
|
144
|
+
def border(scr)
|
145
|
+
scr.clear()
|
146
|
+
scr.border(*([0]*8)) # calls WINDOW#border(0, 0, 0, 0, 0, 0, 0, 0)
|
147
|
+
scr.move(3,3)
|
148
|
+
scr.addstr("Press a key to continue")
|
149
|
+
scr.getch()
|
150
|
+
end
|
151
|
+
|
152
|
+
def two_borders()
|
153
|
+
# make a new window as tall as the screen and half as wide, in the left half
|
154
|
+
# of the screen
|
155
|
+
one = Ncurses::WINDOW.new(0, Ncurses.COLS() / 2, 0, 0)
|
156
|
+
# make one for the right half
|
157
|
+
two = Ncurses::WINDOW.new(0, Ncurses.COLS() - (Ncurses.COLS() / 2),
|
158
|
+
0, Ncurses.COLS() / 2)
|
159
|
+
one.border(*([0]*8))
|
160
|
+
two.border(*([0]*8))
|
161
|
+
one.move(3,3)
|
162
|
+
two.move(2,5)
|
163
|
+
one.addstr("move(3,3)")
|
164
|
+
two.addstr("move(2,5)")
|
165
|
+
two.move(5,3)
|
166
|
+
two.addstr("Press a key to continue")
|
167
|
+
one.noutrefresh() # copy window to virtual screen, don't update real screen
|
168
|
+
two.noutrefresh()
|
169
|
+
Ncurses.doupdate() # update read screen
|
170
|
+
two.getch()
|
171
|
+
end
|
172
|
+
|
173
|
+
begin
|
174
|
+
# initialize ncurses
|
175
|
+
Ncurses.initscr
|
176
|
+
Ncurses.cbreak # provide unbuffered input
|
177
|
+
Ncurses.noecho # turn off input echoing
|
178
|
+
Ncurses.nonl # turn off newline translation
|
179
|
+
# Ncurses.stdscr.intrflush(false) # turn off flush-on-interrupt
|
180
|
+
# Ncurses.stdscr.keypad(true) # turn on keypad mode
|
181
|
+
# Ncurses.stdscr.addstr("Press a key to continue") # output string
|
182
|
+
# Ncurses.stdscr.getch # get a charachter
|
183
|
+
Ncurses.stdscr.intrflush(Ncurses::FALSE) # turn off flush-on-interrupt
|
184
|
+
Ncurses.stdscr.keypad(Ncurses::TRUE) # turn on keypad mode
|
185
|
+
Ncurses.addstr("Press a key to continue") # output string
|
186
|
+
Ncurses.getch() # get a charachter
|
187
|
+
|
188
|
+
moving(Ncurses.stdscr) # demo of moving cursor
|
189
|
+
border(Ncurses.stdscr) # demo of borders
|
190
|
+
two_borders() # demo of two windows with borders
|
191
|
+
|
192
|
+
ensure
|
193
|
+
Ncurses.echo
|
194
|
+
Ncurses.nocbreak
|
195
|
+
Ncurses.nl
|
196
|
+
Ncurses.endwin
|
197
|
+
end
|
data/lib/ffi-ncurses.rb
CHANGED
data/lib/ffi-ncurses/darwin.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-ncurses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean O'Halpin
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-22 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- examples/example-stdscr.rb
|
52
52
|
- examples/example-windows.rb
|
53
53
|
- examples/example.rb
|
54
|
+
- examples/ncurses-example.rb
|
54
55
|
- ffi-ncurses.gemspec
|
55
56
|
- lib/ffi-ncurses.rb
|
56
57
|
- lib/ffi-ncurses/darwin.rb
|