-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rb
82 lines (68 loc) · 1.44 KB
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require 'glimmer-dsl-libui'
require_relative 'jfi.rb'
class RJ
include Glimmer
attr_accessor :input
def initialize
@J = JFI.new(find_bin)
create_gui
end
def buttons
horizontal_box {
stretchy false
@run_button = button('eval') {
stretchy false
on_clicked do
@run_button.enabled = false
output = ''
@input.lines(chomp: true).each do |s|
r = @J.run(s)
output << r unless r.empty?
break unless r !~ /\|/
end
@run_button.enabled = true
@output_box.text = output
end
}
# this is somehow more convenient to me than the close button
button('quit') {
stretchy false
on_clicked do
exit(0)
end
}
}
end
def find_bin
if OS.windows?
'j.dll'
elsif OS.linux?
'libj.so'
elsif OS.mac?
'libj.dylib'
else
raise 'Make sure J is installed and set in PATH.'
end
end
def create_gui
window('rj', 1000, 1000) {
margined true
vertical_box {
buttons
horizontal_box {
vertical_box {
non_wrapping_multiline_entry {
text <=> [self, :input]
}
}
vertical_box {
@output_box = non_wrapping_multiline_entry {
read_only true
}
}
}
}
}.show
end
end
RJ.new