twirb 0.0.2 → 0.0.3
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 +8 -8
- data/lib/twirb.rb +5 -5
- data/lib/twirb/keywords.rb +214 -0
- data/lib/twirb/manipulation.rb +238 -0
- data/lib/twirb/textgui.rb +117 -0
- data/lib/twirb/version.rb +1 -1
- metadata +6 -9
- data/.gitignore +0 -17
- data/Gemfile +0 -8
- data/LICENSE.txt +0 -22
- data/README.md +0 -48
- data/Rakefile +0 -17
- data/twirb.gemspec +0 -24
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGMzMjU0MzZkYjRhZDY5NzVkZTg0ZjJkOTMxMmUzYTJkYzI1ZWFjNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjhhMTBlMDUwNmYwY2JkYzU4N2RmZTgzNzRlODdkNDVlNzkyMjAwNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjIyODUxOWY4MmI4NjA5ZGFlZDRiNGQwMWNhNDEzYzZjZjI5MWM3Mzg5M2Ey
|
10
|
+
YTY4OGUzNTVkMjc4NDQ0ZjFkZTk1ZmVkODc5OGQwZTgwNzczNzY3N2Y5M2Zi
|
11
|
+
NjhjOGJiMTg0YjVjMzZlM2ZjODE5NWM2OTY5M2Y5ODA3ZWIzOTk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzdmZDVkYjExNzc3NjE4NjRjMzg1MDUzZmNhMTU2YTQxNGFkYmE3MzcwMzJj
|
14
|
+
MmRhYTFmNmM5ZTEwMmU4MDJlYzc0NDZkYTBkOTNkZWU4NTNmOTZkNDcyYjUy
|
15
|
+
ODQ1YmJkNDQyOGY0ZDg4Mjc0ZDg4NmJjMzFlMmYyOGMzMWMwOWQ=
|
data/lib/twirb.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require "tk"
|
2
|
-
require "tkextlib/tile"
|
3
|
-
|
4
|
-
require 'keywords'
|
5
|
-
require 'manipulation'
|
6
|
-
require 'textgui'
|
2
|
+
#require "tkextlib/tile"
|
3
|
+
#$LOAD_PATH << './lib'
|
4
|
+
require 'twirb/keywords'
|
5
|
+
require 'twirb/manipulation'
|
6
|
+
require 'twirb/textgui'
|
7
7
|
require 'twirb/version'
|
8
8
|
|
9
9
|
|
@@ -0,0 +1,214 @@
|
|
1
|
+
module Keywords
|
2
|
+
attr_reader :keywords
|
3
|
+
def setup
|
4
|
+
@keywords = Hash.new do |h, k|
|
5
|
+
m = /^(?<constant>[A-Z])|(?<symbol>:)|(?<inst_var>@)|(?<double_arr><<)|(?<percent>%)|(?<semi_col>;)|(?<dot_com>\.|\,)|/.match(k)
|
6
|
+
if m[0] != ""
|
7
|
+
h[k] = lambda do |k, i, ind|
|
8
|
+
m.names.each {|name| send(name, k) if m[name] != nil}
|
9
|
+
end
|
10
|
+
else
|
11
|
+
h[k] = lambda do |n, i, ind|
|
12
|
+
if !@def_name.empty?
|
13
|
+
@def_name.clear
|
14
|
+
add("#{n}", 'red')
|
15
|
+
else
|
16
|
+
@div << n
|
17
|
+
add("#{n}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
@keywords[" "] = lambda do |n, i, ind|
|
24
|
+
add("#{n}")
|
25
|
+
end
|
26
|
+
|
27
|
+
%w{self true false nil return super}.each do |w|
|
28
|
+
@keywords[w] = lambda do |n, i, ind|
|
29
|
+
add("#{n}", 'DarkOrange')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
%w{class def module alias}.each do |w|
|
34
|
+
@keywords[w] = lambda do |n, i, ind|
|
35
|
+
@def_name << n if w == "def"
|
36
|
+
add("#{n}", 'blue')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
(0..9).to_a.map {|n| n.to_s}.each do |w|
|
41
|
+
@keywords[w] = lambda do |n, i, ind|
|
42
|
+
@div << n
|
43
|
+
add("#{n}", 'brown')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
["if",
|
48
|
+
"while",
|
49
|
+
"do",
|
50
|
+
"{", "}",
|
51
|
+
"case",
|
52
|
+
"require", "include", "require_relative",
|
53
|
+
"lambda", "proc", "yield",
|
54
|
+
"begin",
|
55
|
+
"unless",
|
56
|
+
"then", "and", "or", "not", "|", "&&",
|
57
|
+
"until", "for", "in",
|
58
|
+
"retry", "redo",
|
59
|
+
"next", "break",
|
60
|
+
"attr_accessor", "attr_reader", "attr_writer"].each do |w|
|
61
|
+
if w == "}"
|
62
|
+
@keywords[w] = lambda do |n, i, ind|
|
63
|
+
@div.clear
|
64
|
+
if !@literal_array.empty?
|
65
|
+
@literal_array.clear
|
66
|
+
add("#{n}", 'violet')
|
67
|
+
else
|
68
|
+
add("#{n}", 'red')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
else
|
72
|
+
@keywords[w] = lambda do |n, i, ind|
|
73
|
+
@div.clear #if w == "{"
|
74
|
+
add("#{n}", 'red') {@reference_word << n if n == "require"}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
["elsif", "rescue", "else", "when"].each do |w|
|
80
|
+
@keywords[w] = lambda do |n, i, ind|
|
81
|
+
@div.clear
|
82
|
+
num1 = 4 if @num_lin <= 99
|
83
|
+
num1 = 5 if @num_lin >= 100
|
84
|
+
num2 = num1 + 2
|
85
|
+
if !@list_end_words.empty? && i == 0 #@mod.empty?
|
86
|
+
delete(num1, num2)
|
87
|
+
end
|
88
|
+
add("#{n}", 'red')
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
@keywords["end"] = lambda do |n, i, ind|
|
94
|
+
num1 = 4 if @num_lin <= 99
|
95
|
+
num1 = 5 if @num_lin >= 100
|
96
|
+
num2 = num1 + 2
|
97
|
+
if !@list_end_words.empty? && i == 0 && ind == 0
|
98
|
+
delete(num1, num2)
|
99
|
+
end
|
100
|
+
end_method(n, i, ind)
|
101
|
+
end
|
102
|
+
|
103
|
+
@keywords["\\"] = lambda do |n, i, ind|
|
104
|
+
@div.clear
|
105
|
+
add("#{n}", 'violet')
|
106
|
+
end
|
107
|
+
|
108
|
+
["%q{", "%Q{", "%r{", "%{", "%w{", "%W{"].each do |w|
|
109
|
+
@keywords[w] = lambda do |n, i, ind|
|
110
|
+
@literal_array << n
|
111
|
+
add("#{n}", 'violet')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
["%q[", "%Q[", "%r[", "%[", "%w[", "%W["].each do |w|
|
116
|
+
@keywords[w] = lambda do |n, i, ind|
|
117
|
+
@literal_array_square << n
|
118
|
+
add("#{n}", 'violet')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
["%q(", "%Q(", "%r(", "%(", "%w(", "%W("].each do |w|
|
123
|
+
@keywords[w] = lambda do |n, i, ind|
|
124
|
+
@literal_array_parenthesis << n
|
125
|
+
add("#{n}", 'violet')
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
@keywords["=begin"] = lambda do |n, i, ind|
|
131
|
+
@comments_multiline << n
|
132
|
+
add("#{n}", 'grey90')
|
133
|
+
end
|
134
|
+
|
135
|
+
@keywords["=end"] = lambda do |n, i, ind|
|
136
|
+
@comments_multiline.clear
|
137
|
+
add("#{n}", 'grey90')
|
138
|
+
end
|
139
|
+
|
140
|
+
@keywords["#"] = lambda do |n, i, ind|
|
141
|
+
@comments << n
|
142
|
+
add("#{n}", 'grey90')
|
143
|
+
end
|
144
|
+
|
145
|
+
@keywords['"'] = lambda do |n, i, ind|
|
146
|
+
@double_quote << n
|
147
|
+
add("#{n}", 'violet')
|
148
|
+
end
|
149
|
+
|
150
|
+
@keywords["'"] = lambda do |n, i, ind|
|
151
|
+
@single_quote << n
|
152
|
+
add("#{n}", 'violet')
|
153
|
+
end
|
154
|
+
|
155
|
+
@keywords["/"] = lambda do |n, i, ind|
|
156
|
+
@regex << n if @div.length == 1 || @div.empty?
|
157
|
+
add("#{n}", 'violet')
|
158
|
+
end
|
159
|
+
|
160
|
+
%w{+ - * = < > ! ~ ?}.each do |w|
|
161
|
+
@keywords[w] = lambda do |n, i, ind|
|
162
|
+
@div.clear
|
163
|
+
@reference_word << n if n == "=" || n == "<" || n == ">"
|
164
|
+
add("#{n}", 'red')
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
@keywords["]"] = lambda do |n, i, ind|
|
169
|
+
@div << n
|
170
|
+
if !@literal_array_square.empty?
|
171
|
+
@literal_array_square.clear
|
172
|
+
add("#{n}", 'violet')
|
173
|
+
else
|
174
|
+
add("#{n}")
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
@keywords[")"] = lambda do |n, i, ind|
|
179
|
+
if !@literal_array_parenthesis.empty?
|
180
|
+
@literal_array_parenthesis.pop
|
181
|
+
add("#{n}", 'violet')
|
182
|
+
else
|
183
|
+
add("#{n}", 'not_imp')
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
%w{ ( [ }.each do |w|
|
188
|
+
@keywords[w] = lambda do |n, i, ind|
|
189
|
+
@div.clear
|
190
|
+
@reference_word << n if n == "("
|
191
|
+
add("#{n}")
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
%w{constant symbol inst_var double_arr percent semi_col dot_com}.each do |m|
|
198
|
+
define_method(m) do |k|
|
199
|
+
@div << k if m == "constant" || m == "inst_var"
|
200
|
+
@div.clear if m == "symbol" || m == "double_arr" || m == "semi_col" || m == "dot_com" || m == "percent"
|
201
|
+
#@multiline_str << k if m == "double_arr"
|
202
|
+
@start_multiline_str << k if m == "double_arr" and !("0".."9").include?(k[2])
|
203
|
+
@delimiter_multi_str << k if m == "percent" and %w{| ! " $ = - ^}.include?(k[k.length - 1])
|
204
|
+
#@mod << k if m == "semi_col"
|
205
|
+
@def_name.clear if m == "semi_col"
|
206
|
+
@reference_word << k if m == "semi_col"
|
207
|
+
add(k, 'green') if m == "constant"
|
208
|
+
add(k, 'yellow') if m == "symbol"
|
209
|
+
add(k, 'brown') if m == "inst_var"
|
210
|
+
add(k, 'violet') if m == "double_arr" || m == "percent"
|
211
|
+
add(k) if m == "semi_col" || m == "dot_com"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
@@ -0,0 +1,238 @@
|
|
1
|
+
module Manipulation
|
2
|
+
|
3
|
+
def add(word, color = "no color")
|
4
|
+
@entry.send("insert", 'end', word, color)
|
5
|
+
yield if block_given?
|
6
|
+
end
|
7
|
+
|
8
|
+
def delete(num1, num2)
|
9
|
+
@entry.send("delete", "end -1 lines + #{num1} chars", "end -1 lines + #{num2} chars")
|
10
|
+
end
|
11
|
+
|
12
|
+
def total_delete
|
13
|
+
@entry.send("delete", "1.0", "end")
|
14
|
+
end
|
15
|
+
|
16
|
+
def interpolate(word)
|
17
|
+
@interpolation << word if word == '#{'
|
18
|
+
@interpolation.pop if word == '}'
|
19
|
+
end
|
20
|
+
|
21
|
+
def method_missing(method, *args)
|
22
|
+
end_array = {"literal_array" => "}", "literal_array_square" => "]", "literal_array_parenthesis" => ")"}
|
23
|
+
if args[0] == end_array[method.to_s] && @interpolation.empty?
|
24
|
+
@keywords[args[0]].call(args[0], args[1], args[2])
|
25
|
+
else
|
26
|
+
add(args[0], 'violet') {@literal_array_parenthesis << args[0] if args[0] == "(" and @interpolation.empty? and method.to_s == "literal_array_parenthesis"}
|
27
|
+
interpolate(args[0])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def comments_multiline(word, i, ind)
|
32
|
+
if word != "=end"
|
33
|
+
@keywords["=begin"].call(word, i, ind)
|
34
|
+
else
|
35
|
+
@keywords["=end"].call(word, i, ind)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def single_quote(word, i, ind)
|
40
|
+
#if /\$*\'/.eql?(word)
|
41
|
+
if word == "'" || word == "$'" || word == "?'"
|
42
|
+
@single_quote.clear
|
43
|
+
add(word, 'violet')
|
44
|
+
else
|
45
|
+
@keywords["'"].call(word, i, ind)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def regex(word, i, ind)
|
50
|
+
if word == '/' || word == "?/" and @interpolation.empty?
|
51
|
+
@regex.clear
|
52
|
+
add(word, 'violet')
|
53
|
+
else
|
54
|
+
add(word, 'violet')
|
55
|
+
interpolate(word)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def double_quote(word, i, ind)
|
61
|
+
#if /%*"/.eql?(word) and @interpolation.empty?
|
62
|
+
if word == '"' || word == '%"' || word == '?"' and @interpolation.empty?
|
63
|
+
@double_quote.clear
|
64
|
+
add(word, 'violet')
|
65
|
+
else
|
66
|
+
#@keywords['"'].call(word, i, ind)
|
67
|
+
add(word, "violet")
|
68
|
+
interpolate(word)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def comments(word, i, ind)
|
73
|
+
@keywords["#"].call(word, i, ind)
|
74
|
+
end
|
75
|
+
|
76
|
+
def multiline_str(word, i, ind)
|
77
|
+
@multiline_str[0][2] != "-" ? @end_str = @multiline_str[0][2..@multiline_str[0].length] : @end_str = @multiline_str[0][3..@multiline_str[0].length]
|
78
|
+
if word == @end_str.gsub(/["\']/, "") && i == 0 && ind == 0
|
79
|
+
add(word, 'violet')
|
80
|
+
@multiline_str.clear
|
81
|
+
@start_multiline_str.shift
|
82
|
+
else
|
83
|
+
add(word, 'violet')
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def delimiter_multi_str(word, i, ind)
|
88
|
+
@end_multi_str = @delimiter_multi_str[0][@delimiter_multi_str[0].length - 1]
|
89
|
+
if word == @end_multi_str
|
90
|
+
add(word, 'violet')
|
91
|
+
@delimiter_multi_str.clear
|
92
|
+
else
|
93
|
+
add(word, 'violet')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def delimiter_multi_arr(word, i, ind)
|
98
|
+
@end_multi_arr = @delimiter_multi_arr[0][2]
|
99
|
+
if word == @end_multi_arr
|
100
|
+
add(word, 'violet')
|
101
|
+
@delimiter_multi_arr.clear
|
102
|
+
else
|
103
|
+
add(word, 'violet')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def instances_for_different_color
|
108
|
+
%w{@literal_array @double_quote @single_quote @regex @comments @multiline_str @comments_multiline @delimiter_multi_str @delimiter_multi_arr @literal_array_square @literal_array_parenthesis}
|
109
|
+
end
|
110
|
+
|
111
|
+
def are_not_empty?
|
112
|
+
instances_for_different_color.any? {|kw| !instance_variable_get(kw).empty?}
|
113
|
+
end
|
114
|
+
|
115
|
+
def str(word, i, ind = 0)
|
116
|
+
if are_not_empty?
|
117
|
+
instances_for_different_color.each {|instance| send("#{instance.sub("@", "")}", word, i, ind) unless instance_variable_get(instance).empty?}
|
118
|
+
else
|
119
|
+
@reference_word.clear if !word_to_indent?(word) && word !~ /\s+/
|
120
|
+
@keywords[word].call(word, i, ind)
|
121
|
+
end
|
122
|
+
include_word_for_indentation_and_optional_do(word, i, ind)
|
123
|
+
end
|
124
|
+
|
125
|
+
def include_word_for_indentation_and_optional_do(word, i, ind)
|
126
|
+
@list_end_words << word if words_related_to_end?(word, i, ind) && empty_list?
|
127
|
+
@optional_do << word if optional_do?(word, i, ind)
|
128
|
+
end
|
129
|
+
|
130
|
+
def word_to_indent?(word)
|
131
|
+
%w{if unless until for def class module case while begin}.any? {|kw| kw == word}
|
132
|
+
end
|
133
|
+
|
134
|
+
def optional_do?(word, i, ind)
|
135
|
+
%w{if while until}.any? {|kw| kw == word && i == 0 && ind == 0}
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
def end_method(word, i, ind)
|
140
|
+
if @list_end_words.empty? || ind != 0
|
141
|
+
add(word)
|
142
|
+
else
|
143
|
+
@keywords[@list_end_words.last].call(word, i, ind)
|
144
|
+
@list_end_words.pop
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def new_line
|
149
|
+
highlight
|
150
|
+
add("\n")
|
151
|
+
end
|
152
|
+
|
153
|
+
def convert
|
154
|
+
@auto_highlight = false
|
155
|
+
@a = @entry.value
|
156
|
+
@a.gsub!(/^\d*\)/, "")
|
157
|
+
@entry.delete(1.0, 'end')
|
158
|
+
add(@a)
|
159
|
+
end
|
160
|
+
|
161
|
+
def analyze(word, i)
|
162
|
+
words = word.split(/(\\[\'\"\/\#{\\]|%[wWqQr]?[|\=\^!\"\$-]|\$[\']*|\^|\=begin|\=end|\||\<\<\-?["\']?\w+["\']?|\.|!|\?[\"\'\/]?|%[wWqQr]?[\{\[\(]|\/|{|}|"|\'|\+|\-|\=|\~|\*|\\|\<|\>|\[|\]|\#{|\#|\d|\:\:|\)|\;|\,|&&|\()/)
|
163
|
+
words.each_with_index do |w, ind|
|
164
|
+
str(w, i, ind)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def punctuation?(word)
|
169
|
+
view = word.scan(/\\[\'\"\/\#{\\]|%[wWqQr]?[|\=\^!\"\$-]|\$[\']*|\^|\=begin|\=end|\||\<\<\-?["\']?\w+["\']?|\.|!|\?[\"\'\/]?|%[wWqQr]?[\{\[\(]|\/|\(|\)|{|}|"|\'|\[|\]|\+|\*|\\|\=|\~|\-|\<|\>|\d|\:\:|\#{|\#|\;|\,|&&/)
|
170
|
+
return true if view.length != 0
|
171
|
+
end
|
172
|
+
|
173
|
+
def words_related_to_end?(word, i, ind)
|
174
|
+
(((i == 0 && ind == 0) || !@reference_word.empty?) && (word_to_indent?(word))) || (word == "do" && @optional_do.empty?)
|
175
|
+
end
|
176
|
+
|
177
|
+
def other_word(word, i)
|
178
|
+
if punctuation?(word)
|
179
|
+
analyze(word, i)
|
180
|
+
else
|
181
|
+
str(word, i)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def empty_list?
|
186
|
+
instances_for_different_color.all? {|inst| instance_variable_get(inst).empty?}
|
187
|
+
end
|
188
|
+
|
189
|
+
def indent
|
190
|
+
%w{module class def if case while do begin unless until for}.each {|n| add(" " * @list_end_words.count(n))}
|
191
|
+
end
|
192
|
+
|
193
|
+
def empty_array
|
194
|
+
(%w{@list_end_words @def_name @reference_word @interpolation @optional_do @start_multiline_str} +
|
195
|
+
instances_for_different_color).each {|inst| instance_variable_set(inst, [])}
|
196
|
+
end
|
197
|
+
|
198
|
+
def clear_array
|
199
|
+
[@comments, @def_name, @div, @reference_word, @optional_do].each {|n| n.clear}
|
200
|
+
@multiline_str << @start_multiline_str[0] unless @start_multiline_str.empty?
|
201
|
+
end
|
202
|
+
|
203
|
+
def set_number(i)
|
204
|
+
num = "%03d" % i if @num_lin >= 100
|
205
|
+
num = "%02d" % i if @num_lin <= 99
|
206
|
+
add("#{num})", 'grey')
|
207
|
+
add(" ")
|
208
|
+
end
|
209
|
+
|
210
|
+
def start_indentation_and_number(i)
|
211
|
+
clear_array
|
212
|
+
set_number(i)
|
213
|
+
indent
|
214
|
+
end
|
215
|
+
|
216
|
+
def add_text(text_for_indentation_and_syntax_highlight)
|
217
|
+
@text = text_for_indentation_and_syntax_highlight
|
218
|
+
@num_lin = @text.split(/\n/).length
|
219
|
+
total_delete
|
220
|
+
@text.gsub(/^\d*\)/, "").each_line.with_index(1) do |line, i|
|
221
|
+
add("\n") unless i == 1
|
222
|
+
start_indentation_and_number(i)
|
223
|
+
line.sub(/^\s+/, "").gsub(/\n/, "").split(/(\s+)/).each_with_index do |word, i|
|
224
|
+
other_word(word, i)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def highlight
|
230
|
+
if @auto_highlight
|
231
|
+
empty_array
|
232
|
+
add_text(@entry.value)
|
233
|
+
else
|
234
|
+
add(' ')
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
#require "./keywords"
|
2
|
+
|
3
|
+
class TextGui
|
4
|
+
include Keywords
|
5
|
+
def initialize
|
6
|
+
setup
|
7
|
+
@auto_highlight = true
|
8
|
+
#@mod = []
|
9
|
+
#@list = []
|
10
|
+
@div = []
|
11
|
+
@style_font = TkFont.new('helvetica 14')
|
12
|
+
var = TkVariable.new
|
13
|
+
status = TkVariable.new
|
14
|
+
root = TkRoot.new
|
15
|
+
root.title = "new file"
|
16
|
+
$scroll = Tk::Tile::Scrollbar.new(root) {orient 'vertical';
|
17
|
+
command proc {|*args|
|
18
|
+
$entr.yview(*args)}}.grid :column => 2, :row => 0, :sticky => 'ns'
|
19
|
+
$entr = @entry = TkText.new(root) {undo true;width 80;height 14;wrap 'none';
|
20
|
+
yscrollcommand(proc{|first, last| $scroll.set(first, last)}) }.grid :column => 0, :row => 0, :columnspan => 2, :sticky => 'nwes'
|
21
|
+
@lbl = Tk::Tile::Label.new(root) {textvariable;
|
22
|
+
anchor 'w'}.grid :column => 0, :row => 1, :sticky => 'we'
|
23
|
+
@lbl['textvariable'] = var
|
24
|
+
#@lbl.grid('row' => 1, 'column' => 1)
|
25
|
+
@lbl_sin = Tk::Tile::Label.new(root) {textvariable;
|
26
|
+
anchor 'w'}.grid :column => 1, :row => 1, :sticky => 'we'
|
27
|
+
|
28
|
+
sz = Tk::Tile::SizeGrip.new(root).grid :column => 2, :row => 1, :sticky => 'se'
|
29
|
+
TkGrid.columnconfigure root, 0, :weight => 1
|
30
|
+
TkGrid.rowconfigure root, 0, :weight => 1
|
31
|
+
|
32
|
+
###########
|
33
|
+
@lbl_sin['textvariable'] = status
|
34
|
+
m = TkTextMark.new(@entry, '1.0')
|
35
|
+
@entry.font = @style_font
|
36
|
+
configure_text
|
37
|
+
@edit_mode = true
|
38
|
+
command_keyboard(var, status, m)
|
39
|
+
root.bind("Control-Key-o", proc {open_file(root)})
|
40
|
+
root.bind("Control-Key-s", proc {save_file(root, status)})
|
41
|
+
end
|
42
|
+
|
43
|
+
def execute_code
|
44
|
+
@t = @entry.value
|
45
|
+
@t.gsub!(/^\d*\)/, "")
|
46
|
+
begin
|
47
|
+
print " => ", eval(@t).inspect, "\n"
|
48
|
+
rescue Exception => e
|
49
|
+
print e.inspect, "\n"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def open_file(root)
|
54
|
+
@file = Tk.getOpenFile
|
55
|
+
begin
|
56
|
+
a = File.read(@file)
|
57
|
+
root.title = @file
|
58
|
+
rescue
|
59
|
+
a = ""
|
60
|
+
@file = nil
|
61
|
+
end
|
62
|
+
@entry.delete('1.0', 'end') if @file
|
63
|
+
@entry.insert('end', "#{a}") if @file
|
64
|
+
end
|
65
|
+
|
66
|
+
def command_keyboard(var, status, m)
|
67
|
+
@entry.bind("Key", proc do
|
68
|
+
var.value = @entry.index(m)
|
69
|
+
status.value = "auto mode" if @edit_mode and @auto_highlight
|
70
|
+
end)
|
71
|
+
@entry.bind("Double-Key-Escape", proc {@edit_mode = true})
|
72
|
+
@entry.bind("Escape", proc {status.value = "edit mode"; @edit_mode = false})
|
73
|
+
@entry.bind("Double-Key-Return", proc {new_line})
|
74
|
+
@entry.bind("Key-Return", proc do |e|
|
75
|
+
e.widget.callback_continue unless @edit_mode
|
76
|
+
highlight
|
77
|
+
end)
|
78
|
+
@entry.bind("Control-Key-q", proc {convert;status.value = "text mode" unless @auto_highlight})
|
79
|
+
@entry.bind("Control-Key-w", proc {@auto_highlight = true})
|
80
|
+
@entry.bind("Control-Key-e", proc {execute_code})
|
81
|
+
@entry.bind("space", proc do |e|
|
82
|
+
#e.widget.callback_break if @auto_highlight
|
83
|
+
e.widget.callback_continue unless @edit_mode
|
84
|
+
highlight
|
85
|
+
end)
|
86
|
+
end
|
87
|
+
|
88
|
+
def configure_text
|
89
|
+
%w{blue yellow brown red green violet grey90 DarkOrange}.each do |color|
|
90
|
+
@entry.tag_configure(color, :foreground => color)
|
91
|
+
end
|
92
|
+
@entry.tag_configure('grey', :background => 'grey', :relief => 'raised')
|
93
|
+
@entry.tag_configure('black', :background => 'white', :relief => 'raised')
|
94
|
+
end
|
95
|
+
|
96
|
+
def save_file(root, status)
|
97
|
+
@txtt = @entry.value
|
98
|
+
@txtt.gsub!(/^\d*\)/, "")
|
99
|
+
if @file
|
100
|
+
File.open(@file, "w") do |f|
|
101
|
+
f.puts @txtt
|
102
|
+
end
|
103
|
+
status.value = "saved"
|
104
|
+
else
|
105
|
+
@file = Tk.getSaveFile
|
106
|
+
begin
|
107
|
+
File.open(@file, "w") do |f|
|
108
|
+
f.puts @txtt
|
109
|
+
end
|
110
|
+
root.title = @file
|
111
|
+
rescue
|
112
|
+
root.title = "new file"
|
113
|
+
@file = nil
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/lib/twirb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twirb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antonio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -47,14 +47,11 @@ executables:
|
|
47
47
|
extensions: []
|
48
48
|
extra_rdoc_files: []
|
49
49
|
files:
|
50
|
-
- .
|
51
|
-
-
|
52
|
-
-
|
53
|
-
- README.md
|
54
|
-
- Rakefile
|
55
|
-
- lib/twirb.rb
|
50
|
+
- lib/twirb/keywords.rb
|
51
|
+
- lib/twirb/manipulation.rb
|
52
|
+
- lib/twirb/textgui.rb
|
56
53
|
- lib/twirb/version.rb
|
57
|
-
- twirb.
|
54
|
+
- lib/twirb.rb
|
58
55
|
- bin/twirb
|
59
56
|
homepage: http://www.twirb.org
|
60
57
|
licenses:
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2013 Antonio
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# Twirb
|
2
|
-
|
3
|
-
Simple Ruby text editor as a ruby gem
|
4
|
-
==============================================
|
5
|
-
|
6
|
-
This is a little tool with syntax highlighting and indentation for writing ruby code and execute it directly in your terminal thanks to some useful command listed below: It can be used in three different ways:
|
7
|
-
auto mode(default option): automatic syntax highlighting and indentation and numerated lines while writing your code.
|
8
|
-
edit mode: if you want to add some thing to the code written so far you can activate the edit mode hitting Escape-key: in this way automatic indentation and highlight will be deactivated in order to allow changes.
|
9
|
-
After that you can reactivat auto mode hitting double-key-Escape and then space key: in this way the code that you added will be automatic formatted and you can continue writing in auto mode.
|
10
|
-
text mode: pressing control-q the code will be converted as if in a text file making all the changes you want. You can reactivate auto mode every time you want just hitting control-w and then space key. the code will be automatic formatted.
|
11
|
-
You can execute the code you have written so far just pressing control-e: in this way the code will be executed on your terminal as if in irb.
|
12
|
-
For other commands and instructions visit http://www.twirb.org
|
13
|
-
|
14
|
-
## Installation
|
15
|
-
|
16
|
-
Twirb needs "tk" that is the standard graphical user interface for Ruby.
|
17
|
-
The Ruby Tk bindings are distributed with Ruby but Tk is a separate installation. Windows users can download a single click Tk installation from ActiveState's ActiveTcl(http://www.activestate.com/activetcl/downloads)
|
18
|
-
|
19
|
-
Mac and Linux users may not need to install it because there is a great chance that its already installed along with OS but if not, you can download prebuilt packages or get the source from the Tcl Developer Xchange(http://www.tcl.tk/software/tcltk/downloadnow84.tml).
|
20
|
-
For more details you can visit Tkdocs(http://www.tkdocs.com/tutorial/install.html)
|
21
|
-
|
22
|
-
Add this line to your application's Gemfile:
|
23
|
-
|
24
|
-
gem 'twirb'
|
25
|
-
|
26
|
-
And then execute:
|
27
|
-
|
28
|
-
$ bundle
|
29
|
-
|
30
|
-
Or install it yourself as:
|
31
|
-
|
32
|
-
$ gem install twirb
|
33
|
-
|
34
|
-
## Usage
|
35
|
-
|
36
|
-
you can use it simply typing
|
37
|
-
|
38
|
-
$ twirb
|
39
|
-
|
40
|
-
in the command line.
|
41
|
-
|
42
|
-
## Contributing
|
43
|
-
|
44
|
-
1. Fork it
|
45
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
-
5. Create new Pull Request
|
data/Rakefile
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require 'rdoc/task'
|
3
|
-
|
4
|
-
task :default => [:test]
|
5
|
-
|
6
|
-
desc %Q|Run test(s) in project 'test' folder|
|
7
|
-
task :test do
|
8
|
-
tests = Dir.glob("test/*_{spec,test}.rb").join(' ')
|
9
|
-
ruby tests
|
10
|
-
end
|
11
|
-
|
12
|
-
desc %Q|Generates documentation|
|
13
|
-
RDoc::Task.new do |rdoc|
|
14
|
-
rdoc.main = "README.md"
|
15
|
-
rdoc.rdoc_files.include("README.md", "lib/*.rb", 'bin/*.rb')
|
16
|
-
end
|
17
|
-
|
data/twirb.gemspec
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'twirb/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "twirb"
|
8
|
-
spec.version = Twirb::VERSION
|
9
|
-
spec.authors = ["Antonio"]
|
10
|
-
spec.email = ["antalby@hotmail.com"]
|
11
|
-
spec.description = %q{Twirb is a Ruby text-editor and an alternative to irb, with syntax highlighting and indentation for writing ruby code and executing it directly in your terminal}
|
12
|
-
spec.summary = %q{twirb is a ruby text editor}
|
13
|
-
spec.homepage = "http://www.twirb.org"
|
14
|
-
spec.license = "MIT"
|
15
|
-
spec.executables << 'twirb'
|
16
|
-
|
17
|
-
spec.files = `git ls-files`.split($/)
|
18
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
-
spec.require_paths = ["lib"]
|
21
|
-
|
22
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
-
spec.add_development_dependency "rake"
|
24
|
-
end
|