diff --git a/etc/command/copy_xiki_command_to.rb b/etc/command/copy_xiki_command_to.rb index c1e629a1..c22271cd 100644 --- a/etc/command/copy_xiki_command_to.rb +++ b/etc/command/copy_xiki_command_to.rb @@ -1,34 +1,49 @@ +is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/) + +if is_windows + require 'win32/pipe' + include Win32 +end + # # Used to "install" the 'xiki' shell command (copy it to # /usr/local/bin/) when installing Xiki manually from source # rather than as a gem. # dest = ARGV[0] +xiki_dir = Dir.pwd -if ! dest - puts "Usage (run it from the xiki project dir):\n\n $ etc/command/copy_xiki_command_to.rb /usr/bin/xiki" - exit -end -if dest !~ /xiki$/ - puts "The path you pass should end with 'xiki'. Such as:\n\n $ etc/command/copy_xiki_command_to.rb /usr/bin/xiki" - exit -end +if is_windows + puts "plase crate a xiki.bat file somewhere in your PATH with this content -puts "Putting the 'xiki' shell command at: + start ruby \"#{xiki_dir}/bin/xiki\" - #{dest} -" +thanks" +else + if ! dest + puts "Usage (run it from the xiki project dir):\n\n $ etc/command/copy_xiki_command_to.rb /usr/bin/xiki" + exit + end + if dest !~ /xiki$/ + puts "The path you pass should end with 'xiki'. Such as:\n\n $ etc/command/copy_xiki_command_to.rb /usr/bin/xiki" + exit + end + puts "Putting the 'xiki' shell command at: -source = "etc/command/xiki_wrapper" + #{dest} + " + + source = "etc/command/xiki_wrapper" -xiki_dir = Dir.pwd -puts "" # Blank line + puts "" # Blank line -txt = File.read source -txt.sub! /\(xiki_dir\)/, xiki_dir + txt = File.read source + txt.sub! /\(xiki_dir\)/, xiki_dir -File.open(dest, "w", 0755) { |f| f << txt } + File.open(dest, "w", 0755) { |f| f << txt } + + puts "Finished." +end -puts "Finished." diff --git a/etc/command/xiki_command.rb b/etc/command/xiki_command.rb index 45e8f5fa..d083d9fa 100644 --- a/etc/command/xiki_command.rb +++ b/etc/command/xiki_command.rb @@ -1,5 +1,12 @@ require 'timeout' require 'json' + +is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/) + +if is_windows + require 'win32/pipe' + include Win32 +end # require 'xiki/environment' # @@ -62,16 +69,22 @@ def self.run wasnt_running = false begin - `mkfifo -m 600 /tmp/xikirequest` if ! File.exists?("/tmp/xikirequest") # Always create first, so they have to be pipes and can't be files - `mkfifo -m 600 /tmp/xikiresponse` if ! File.exists?("/tmp/xikiresponse") + if is_windows + Pipe::Client.new("xikirequest") do |out| + out.write path + out.close + end + else + `mkfifo -m 600 /tmp/xikirequest` if ! File.exists?("/tmp/xikirequest") # Always create first, so they have to be pipes and can't be files + `mkfifo -m 600 /tmp/xikiresponse` if ! File.exists?("/tmp/xikiresponse") # Try writing to pipe... - open("/tmp/xikirequest", 'w+') do |out| - out.puts path - out.flush # do this when we're done writing data - out.close - end + open("/tmp/xikirequest", 'w+') do |out| + out.puts path + out.flush # do this when we're done writing data + out.close + end # Try reading from pipe... @@ -154,17 +167,25 @@ def self.get_response timeout(3) do # timeout(0.5) do # timeout(1.5) do - open("/tmp/xikiresponse", "r+") do |response| + if is_windows + Pipe::Server.new("xikiresponse") do |responsee| + responsee.connect + response = responsee.read + responsee.close + end + else + open("/tmp/xikiresponse", "r+") do |response| - # old TODO Try using select here, to see if there's data avaliable - # old IO.select ["/tmp/xikiresponse"] + # old TODO Try using select here, to see if there's data avaliable + # old IO.select ["/tmp/xikiresponse"] - response = response.gets # will block if there's nothing in the pipe + response = response.gets # will block if there's nothing in the pipe + end + end response.strip! response.gsub! "\036", "\n" # Escape linebreaks as 036 char (record separator) return "" if @@dont_show_output self.add_coloring response - end end end diff --git a/etc/command/xiki_process.rb b/etc/command/xiki_process.rb index dfe671f5..c7da999c 100644 --- a/etc/command/xiki_process.rb +++ b/etc/command/xiki_process.rb @@ -7,6 +7,13 @@ require 'xiki/core/menu' require 'xiki/core/launcher' +is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/) + +if is_windows + require 'win32/pipe' + include Win32 +end + Xiki.init # Make named pipes for input and output @@ -15,8 +22,9 @@ class XikiProcess def self.run - open('/tmp/xikirequest', 'r+') do |f| - open('/tmp/xikiresponse', 'w+') do |response| + is_windows?Pipe::Server.new('xikirequest'):open('/tmp/xikirequest', 'r+') do |f| + if is_windows then f.connect end + is_windows?Pipe::Client.new('xikiresponse'):open('/tmp/xikiresponse', 'w+') do |response| loop do # Read request... @@ -34,7 +42,7 @@ def self.run # Turn keys into symbols options = options.reduce({}){ |acc, o| acc[o[0].to_sym] = o[1]; acc } - path = f.gets + path = is_windows?f.read:f.gets path.strip! end @@ -54,8 +62,13 @@ def self.run menu_output = menu_output.to_s menu_output.gsub! "\n", "\036" # Escape linebreaks as 036 char (record separator) - response.puts menu_output - response.flush + if is_windows + response.write menu_output + response.close + else + response.puts menu_output + response.flush + end end end end