Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make running on windows (msys) #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions etc/command/copy_xiki_command_to.rb
Original file line number Diff line number Diff line change
@@ -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."
45 changes: 33 additions & 12 deletions etc/command/xiki_command.rb
Original file line number Diff line number Diff line change
@@ -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'

#
Expand Down Expand Up @@ -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...

Expand Down Expand Up @@ -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

Expand Down
23 changes: 18 additions & 5 deletions etc/command/xiki_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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...
Expand All @@ -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

Expand All @@ -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
Expand Down