forked from jruby/jruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jirb_swing
executable file
·63 lines (55 loc) · 1.7 KB
/
jirb_swing
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
#!/usr/bin/env jruby
#
# IRB in swing
#
# Damian Steer (pldms@mac.com)
require 'jruby'
require 'irb'
require 'irb/completion'
if ARGV.empty?
# default options, esp. useful for jrubyw
ARGV << '--readline' << '--prompt' << 'inf-ruby'
end
import java.awt.Color
import java.awt.Font
import javax.swing.JFrame
import java.awt.EventQueue
# Try to find preferred font family, use otherwise -- err -- otherwise
def find_font(otherwise, style, size, *families)
avail_families = java.awt.GraphicsEnvironment.local_graphics_environment.available_font_family_names
fontname = families.find(proc {otherwise}) { |name| avail_families.include? name }
Font.new(fontname, style, size)
end
text = javax.swing.JTextPane.new
text.font = find_font('Monospaced', Font::PLAIN, 14, 'Monaco', 'Andale Mono')
text.margin = java.awt.Insets.new(8,8,8,8)
text.caret_color = Color.new(0xa4, 0x00, 0x00)
text.background = Color.new(0xf2, 0xf2, 0xf2)
text.foreground = Color.new(0xa4, 0x00, 0x00)
pane = javax.swing.JScrollPane.new
pane.viewport_view = text
frame = JFrame.new('JRuby IRB Console (tab will autocomplete)')
frame.default_close_operation = JFrame::EXIT_ON_CLOSE
frame.set_size(700, 600)
frame.content_pane.add(pane)
tar = org.jruby.demo.TextAreaReadline.new(text,
" Welcome to the JRuby IRB Console [#{JRUBY_VERSION} (#{RUBY_VERSION})]\n\n")
JRuby.objectspace = true # useful for code completion
tar.hook_into_runtime_with_streams(JRuby.runtime)
# We need to show the frame on EDT,
# to avoid deadlocks.
EventQueue.invoke_later {
frame.visible = true
}
# From vanilla IRB
if __FILE__ == $0
IRB.start(__FILE__)
else
# check -e option
if /^-e$/ =~ $0
IRB.start(__FILE__)
else
IRB.setup(__FILE__)
end
end
frame.dispose