我正在尝试从ruby
运行sublimeREPL
。我的配置文件如下:
软件包-> SublimeREPL->配置-> Ruby-> pry_repl.rb
require 'rubygems'
gem 'pry'
require 'pry'
require 'pry/input_completer'
require 'socket'
require 'thread'
require 'json'
include Socket::Constants
class PryInput
def readline(prompt)
$stdout.print prompt
$stdout.flush
$stdin.readline
end
end
class PryOutput
# def puts(data="")
def print(data="")
$stdout.puts(data.gsub('`', "'"))
$stdout.flush
end
end
Pry.config.input = PryInput.new()
Pry.config.output = PryOutput.new()
Pry.config.color = false
Pry.config.editor = ARGV[0]
Pry.config.auto_indent = false
Pry.config.correct_indent = false
port = ENV["SUBLIMEREPL_AC_PORT"].to_i
socket = Socket.new(AF_INET, SOCK_STREAM, 0)
sockaddr = Socket.pack_sockaddr_in(port, '127.0.0.1')
socket.connect(sockaddr)
# completer = Pry::InputCompleter.build_completion_proc(binding)
completer = Pry::InputCompleter.new(binding)
def read_netstring(s)
size = 0
while true
ch = s.recvfrom(1)[0]
if ch == ':'
break
end
size = size * 10 + ch.to_i
end
msg = ""
while size != 0
msg += s.recvfrom(size)[0]
size -= msg.length
end
ch = s.recvfrom(1)[0]
return msg
end
# Thread.abort_on_exception = true
t1 = Thread.new do
while true
data = read_netstring(socket)
req = JSON.parse(data)
line = req["line"]
completions = completer.call(req["line"])
response = [line, completions]
response_msg = JSON.dump(response)
payload = response_msg.length.to_s + ":" + response_msg + ","
socket.write(payload)
end
end
Pry.start self
软件包-> SublimeREPL->配置-> Ruby-> Main.sublime-build
[
{
"id":"tools",
"children":[
{
"caption":"SublimeREPL",
"mnemonic":"R",
"id":"SublimeREPL",
"children":[
{
"caption":"Ruby",
"children":[
{
"command":"repl_open",
"caption":"Ruby",
"id":"repl_ruby",
"mnemonic":"R",
"args":{
"type":"subprocess",
"external_id":"ruby",
"encoding":"utf8",
"cmd":{
"windows":[
"ruby.exe",
"${packages}/SublimeREPL/config/Ruby/pry_repl.rb",
"$editor"
],
"linux":[
"/usr/bin/ruby",
"${packages}/SublimeREPL/config/Ruby/pry_repl.rb",
"$editor"
],
"osx":[
"ruby",
"${packages}/SublimeREPL/config/Ruby/pry_repl.rb",
"$editor"
]
},
"soft_quit":"\nexit\n",
"cwd":"$file_path",
"cmd_postfix":"\n",
"autocomplete_server": true,
"syntax":"Packages/Ruby/Ruby.tmLanguage"
}
},
{
"command":"repl_open",
"caption":"Ruby - IRB (deprecated)",
"id":"repl_ruby_irb",
"mnemonic":"I",
"args":{
"type":"subprocess",
"external_id":"ruby",
"encoding":"utf8",
"cmd":{
"windows":[
"irb.bat",
"--noreadline",
"--inf-ruby-mode"
],
"linux":[
"irb",
"--noreadline",
"--inf-ruby-mode"
],
"osx":[
"irb",
"--noreadline",
"--inf-ruby-mode"
]
},
"soft_quit":"\nexit\n",
"cwd":"$file_path",
"cmd_postfix":"\n",
"suppress_echo":true,
"syntax":"Packages/Ruby/Ruby.tmLanguage"
}
}
]
}
]
}
]
}
]
工具->构建系统->新构建系统-> sublimereplruby.sublime-build
{
"target": "run_existing_window_command",
"id": "repl_ruby",
"file": "config/Ruby/Main.sublime-menu"
}
当我尝试通过选择上面的.rb
构建系统来运行任何sublimereplruby.sublime-build
文件时,得到以下输出:
[1] pry(main)>
当我击中Enter
时,我得到了:
/var/lib/gems/2.5.0/gems/pry-0.12.2/lib/pry/pager.rb:150: warning: Insecure world writable dir /usr/lib/jvm/java-8-openjdk-amd64/bin in PATH, mode 040777
=> nil
[2] pry(main)>
我没有得到任何输出。我只有nil
。我今天开始学习Ruby
。因此,我不了解gem
和相关主题。我需要在Ruby
中运行Sublime Text3
。因此,请告诉我如何解决该问题。