rubytext 0.0.15
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 +7 -0
- data/README.md +14 -0
- data/lib/rubytext.rb +267 -0
- data/lib/version.rb +6 -0
- data/rubytext.gemspec +29 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fe02a727ad28e192c4578215c9135f418f1c0e88
|
4
|
+
data.tar.gz: fa7091c1920092f1d449499ee1cf969977d2963a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2ba3f8c5d824a60039d9d982dce8709f914ec47136fe2c38b449df58deec73c16777fee6a8a8143fb2d8e28003eb1bc7a191b369849ddc772873f6acc564c1be
|
7
|
+
data.tar.gz: b7df132242683378422ec75c576cbf8e8fd2880fcac97496a2806770c5adcb8464b0426bddbaf535e82ade9ca0e6291a0dc72d9a1c6c6e9183a47695e142b042
|
data/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
RubyText
|
2
|
+
--------
|
3
|
+
|
4
|
+
RubyText is a curses wrapper that is in the early experimental
|
5
|
+
stages. The code has bugs. Running it may cause general bad luck
|
6
|
+
as well as demon infestation.
|
7
|
+
|
8
|
+
For now, just run the `examples/demo.rb` program.
|
9
|
+
|
10
|
+
There is also `examples/ide.rb` ("world's simplest Ruby IDE").
|
11
|
+
It is _very_ dumb. :)
|
12
|
+
|
13
|
+
*More later...*
|
14
|
+
|
data/lib/rubytext.rb
ADDED
@@ -0,0 +1,267 @@
|
|
1
|
+
$LOAD_PATH << "lib"
|
2
|
+
|
3
|
+
require 'curses'
|
4
|
+
|
5
|
+
require 'version' # skeleton + version
|
6
|
+
|
7
|
+
X = Curses # shorthand
|
8
|
+
|
9
|
+
def debug(*args)
|
10
|
+
return unless $debug
|
11
|
+
$debug.puts *args
|
12
|
+
end
|
13
|
+
|
14
|
+
module RubyText
|
15
|
+
|
16
|
+
module Keys
|
17
|
+
Down = 258
|
18
|
+
Up = 259
|
19
|
+
Left = 260
|
20
|
+
Right = 261
|
21
|
+
Enter = 10
|
22
|
+
F1 = 265
|
23
|
+
F2 = 266
|
24
|
+
F3 = 267
|
25
|
+
F4 = 268
|
26
|
+
F5 = 269
|
27
|
+
F6 = 270
|
28
|
+
F7 = 271
|
29
|
+
F8 = 272
|
30
|
+
F9 = 273
|
31
|
+
F10 = 274
|
32
|
+
F11 = 275
|
33
|
+
F12 = 276
|
34
|
+
end
|
35
|
+
|
36
|
+
Colors = %w[black blue cyan green
|
37
|
+
magenta red white yellow]
|
38
|
+
|
39
|
+
class Window
|
40
|
+
def self.main
|
41
|
+
debug "Entering Window.main"
|
42
|
+
@main_win = X.init_screen
|
43
|
+
X.start_color
|
44
|
+
X.init_pair(1, X::COLOR_BLACK, X::COLOR_WHITE)
|
45
|
+
X.stdscr.bkgd(X.color_pair(1)|X::A_NORMAL)
|
46
|
+
rows, cols = @main_win.maxy, @main_win.maxx
|
47
|
+
debug "About to call .make"
|
48
|
+
@screen = self.make(@main_win, rows, cols, 0, 0, false)
|
49
|
+
@screen
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.make(cwin, high, wide, r0, c0, border)
|
53
|
+
debug "make: #{[cwin, high, wide, r0, c0, border]}"
|
54
|
+
obj = self.allocate
|
55
|
+
debug "Allocate returned a #{obj.class}"
|
56
|
+
obj.instance_eval do
|
57
|
+
debug " Inside instance_eval..."
|
58
|
+
@outer = @win = cwin
|
59
|
+
@wide, @high, @r0, @c0 = wide, high, r0, c0
|
60
|
+
@border = border
|
61
|
+
@rows, @cols = high, wide
|
62
|
+
@width, @height = @cols + 2, @rows + 2 if @border
|
63
|
+
end
|
64
|
+
obj
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# debug "Setting STDSCR to Window.main"
|
70
|
+
|
71
|
+
STDSCR = RubyText::Window.main
|
72
|
+
$stdscr = STDSCR
|
73
|
+
|
74
|
+
###
|
75
|
+
|
76
|
+
module RubyText
|
77
|
+
|
78
|
+
# For passing through arbitrary method calls
|
79
|
+
# to the lower level...
|
80
|
+
|
81
|
+
def self.method_missing(name, *args)
|
82
|
+
debug "method_missing: #{name} #{args.inspect}"
|
83
|
+
if name[0] == '_'
|
84
|
+
X.send(name[1..-1], *args)
|
85
|
+
else
|
86
|
+
raise "#{name} #{args.inspect}" # NoMethodError
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def RubyText.window(high, wide, r0, c0, border=false)
|
91
|
+
RubyText::Window.new(high, wide, r0, c0, border)
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.start(*args, log: nil, fg: nil, bg: nil)
|
95
|
+
$debug = File.new(log, "w") if log
|
96
|
+
fg ||= :white
|
97
|
+
bg ||= :black
|
98
|
+
debug "fg = #{fg} is not a valid color" unless Colors.include?(fg.to_s)
|
99
|
+
debug "bg = #{bg} is not a valid color" unless Colors.include?(bg.to_s)
|
100
|
+
fg = X.const_get("COLOR_#{fg.upcase}")
|
101
|
+
bg = X.const_get("COLOR_#{bg.upcase}")
|
102
|
+
X.init_pair(1, bg, fg)
|
103
|
+
X.stdscr.bkgd(X.color_pair(1)|X::A_NORMAL)
|
104
|
+
X.noecho
|
105
|
+
X.stdscr.keypad(true)
|
106
|
+
X.cbreak # by default
|
107
|
+
|
108
|
+
args.each do |arg|
|
109
|
+
case arg
|
110
|
+
when :raw
|
111
|
+
X.raw
|
112
|
+
when :echo
|
113
|
+
X.echo
|
114
|
+
when :noecho
|
115
|
+
X.noecho
|
116
|
+
when :color
|
117
|
+
X.start_color
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.hide_cursor
|
123
|
+
X.curs_set(0)
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.show_cursor
|
127
|
+
X.curs_set(1)
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.show_cursor!
|
131
|
+
X.curs_set(2) # Doesn't work?
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
class RubyText::Window
|
137
|
+
Vert, Horiz = X::A_VERTICAL, X::A_HORIZONTAL # ?|, ?- # "\u2502", "\u2500"
|
138
|
+
|
139
|
+
attr_reader :win, :rows, :cols, :width, :height
|
140
|
+
|
141
|
+
def initialize(high=nil, wide=nil, r0=1, c0=1, border=false)
|
142
|
+
debug "RT::Win.init: #{[high, wide, r0, c0, border]}"
|
143
|
+
@wide, @high, @r0, @c0 = wide, high, r0, c0
|
144
|
+
@border = border
|
145
|
+
@win = X::Window.new(high, wide, r0, c0)
|
146
|
+
debug "outer = #{@win.inspect}"
|
147
|
+
debug "@border = #@border"
|
148
|
+
if @border
|
149
|
+
@win.box(Vert, Horiz)
|
150
|
+
@outer = @win
|
151
|
+
@outer.refresh
|
152
|
+
debug "About to call again: params = #{[high-2, wide-2, r0+1, c0+1]}"
|
153
|
+
@win = X::Window.new(high-2, wide-2, r0+1, c0+1) # relative now??
|
154
|
+
else
|
155
|
+
@outer = @win
|
156
|
+
end
|
157
|
+
@rows, @cols = @win.maxy, @win.maxx # unnecessary really...
|
158
|
+
@width, @height = @cols + 2, @rows + 2 if @border
|
159
|
+
@win.refresh
|
160
|
+
end
|
161
|
+
|
162
|
+
def delegate_output(sym, *args)
|
163
|
+
args = [""] if args.empty?
|
164
|
+
debug "#{sym}: args = #{args.inspect}"
|
165
|
+
args.map!(&:inspect) if sym == :p
|
166
|
+
str = sprintf(*args)
|
167
|
+
str << "\n" if sym != :print && str[-1] != "\n"
|
168
|
+
@win.addstr(str)
|
169
|
+
@win.refresh
|
170
|
+
end
|
171
|
+
|
172
|
+
def puts(*args)
|
173
|
+
delegate_output(:puts, *args)
|
174
|
+
end
|
175
|
+
|
176
|
+
def print(*args)
|
177
|
+
delegate_output(:print, *args)
|
178
|
+
end
|
179
|
+
|
180
|
+
def p(*args)
|
181
|
+
delegate_output(:p, *args)
|
182
|
+
end
|
183
|
+
|
184
|
+
def rcprint(r, c, *args)
|
185
|
+
self.go(r, c) { self.print *args }
|
186
|
+
end
|
187
|
+
|
188
|
+
def rcprint!(r, c, *args)
|
189
|
+
@win.setpos(r, c) # Cursor isn't restored
|
190
|
+
self.print *args
|
191
|
+
end
|
192
|
+
|
193
|
+
def go(r, c)
|
194
|
+
save = self.rc
|
195
|
+
@win.setpos(r, c)
|
196
|
+
if block_given?
|
197
|
+
yield
|
198
|
+
go(*save) # No block here!
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def rc
|
203
|
+
[@win.cury, @win.curx]
|
204
|
+
end
|
205
|
+
|
206
|
+
def clear
|
207
|
+
@win.clear
|
208
|
+
end
|
209
|
+
|
210
|
+
def output(&block)
|
211
|
+
$stdscr = self
|
212
|
+
block.call
|
213
|
+
$stdscr = STDSCR
|
214
|
+
end
|
215
|
+
|
216
|
+
def [](r, c)
|
217
|
+
save = self.rc
|
218
|
+
@win.setpos r, c
|
219
|
+
ch = @win.inch
|
220
|
+
@win.setpos *save
|
221
|
+
ch
|
222
|
+
# go(r, c) { ch = @win.inch }
|
223
|
+
end
|
224
|
+
|
225
|
+
def []=(r, c, char)
|
226
|
+
@win.setpos(r, c)
|
227
|
+
@win.addstr(char[0])
|
228
|
+
end
|
229
|
+
|
230
|
+
def boxme
|
231
|
+
@outer.box(Vert, Horiz)
|
232
|
+
@outer.refresh
|
233
|
+
end
|
234
|
+
|
235
|
+
def refresh
|
236
|
+
@win.refresh
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
|
241
|
+
####
|
242
|
+
|
243
|
+
### Stick stuff into Kernel for top level
|
244
|
+
|
245
|
+
module Kernel
|
246
|
+
private
|
247
|
+
def puts(*args) # Doesn't affect STDOUT.puts, etc.
|
248
|
+
$stdscr.puts(*args)
|
249
|
+
end
|
250
|
+
|
251
|
+
def print(*args)
|
252
|
+
$stdscr.print(*args)
|
253
|
+
end
|
254
|
+
|
255
|
+
def p(*args)
|
256
|
+
$stdscr.p(*args)
|
257
|
+
end
|
258
|
+
|
259
|
+
def rcprint(r, c, *args)
|
260
|
+
$stdscr.rcprint r, c, *args
|
261
|
+
end
|
262
|
+
|
263
|
+
def getch
|
264
|
+
X.getch
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
data/lib/version.rb
ADDED
data/rubytext.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'find'
|
3
|
+
|
4
|
+
$LOAD_PATH << "lib"
|
5
|
+
|
6
|
+
require "version"
|
7
|
+
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
system("rm -f *.gem")
|
10
|
+
s.name = 'rubytext'
|
11
|
+
s.version = RubyText::VERSION
|
12
|
+
s.date = Date.today.strftime("%Y-%m-%d")
|
13
|
+
s.summary = "A thick wrapper for Curses"
|
14
|
+
s.description = "Uses the curses gem and extends functionality and ease of use in Ruby."
|
15
|
+
s.authors = ["Hal Fulton"]
|
16
|
+
s.email = 'rubyhacker@gmail.com'
|
17
|
+
# s.executables << "rubytext-demo"
|
18
|
+
s.add_runtime_dependency 'curses'
|
19
|
+
|
20
|
+
# Files...
|
21
|
+
main = Find.find("lib").to_a
|
22
|
+
|
23
|
+
misc = %w[./README.md ./rubytext.gemspec]
|
24
|
+
# test = Find.find("test").to_a
|
25
|
+
|
26
|
+
s.files = main + misc # + test
|
27
|
+
s.homepage = 'https://github.com/Hal9000/rubytext'
|
28
|
+
s.license = "Ruby License"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubytext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.15
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hal Fulton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: curses
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Uses the curses gem and extends functionality and ease of use in Ruby.
|
28
|
+
email: rubyhacker@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- "./README.md"
|
34
|
+
- "./rubytext.gemspec"
|
35
|
+
- lib/rubytext.rb
|
36
|
+
- lib/version.rb
|
37
|
+
homepage: https://github.com/Hal9000/rubytext
|
38
|
+
licenses:
|
39
|
+
- Ruby License
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.2.2
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: A thick wrapper for Curses
|
61
|
+
test_files: []
|