Compare commits

..

No commits in common. "main" and "v0.8" have entirely different histories.
main ... v0.8

3 changed files with 17 additions and 22 deletions

View file

View file

View file

@ -70,8 +70,10 @@ def compile(infile, mode)
params = ARGV.join(" ")
err_file = infile.with_extname("err")
system "rubber --inplace #{mode_opt} #{params} #{infile} 2> #{err_file}"
_ret = system "rubber --inplace #{mode_opt} #{params} #{infile} 2> #{err_file}"
File.open(err_file) { |file| puts file.read }
# Remove the output save file if compile was succesful.
# clean(infile) if ret
end
# Start the right viewer based on the mode.
@ -107,7 +109,7 @@ end
## Initialisation
PROGRAM = File.basename($PROGRAM_NAME).freeze
VERSION = "0.9".freeze
VERSION = "0.8".freeze
# Parse the command line options.
# Determine the compile mode from the options.
@ -126,10 +128,8 @@ opts.each do |opt, _arg|
when "--ps"
mode = :ps
when "--pdf"
mode = if mode == :ps
:pspdf
else
:pdf
mode = if mode == :ps then :pspdf
else :pdf
end
when "--version"
puts "#{PROGRAM} #{VERSION}"
@ -172,9 +172,18 @@ viewer_pid =
view(infile, mode)
# If xdvi/evince exits, this program should exit too.
puts "#{PROGRAM}: viewer exited, so will I!"
Process.kill("HUP", pid)
Process.kill("TERM", pid)
end
# Handle signals.
["INT", "TERM", "QUIT"].each do |sig|
Signal.trap(sig) do
Process.kill(sig, viewer_pid)
clean(infile)
exit
end
end
## Main event loop
# Add input file with dependancies to the watch list and start event loop.
@ -187,25 +196,11 @@ dirs.each do |dir|
file_path = (dir + ev.name).to_s
next unless files.include? file_path
puts "#{PROGRAM}: file #{ev.name} modified, compiling #{infile}..."
puts "I: file #{ev.name} modified, compiling #{infile}..."
compile(infile, mode)
reload(infile, mode)
puts
end
end
# Handle signals during the main event loop.
["INT", "TERM", "QUIT"].each do |sig|
Signal.trap(sig) do
puts "#{PROGRAM}: caught signal #{sig}, stopping the viewer..."
Process.kill(sig, viewer_pid)
notifier.stop
end
end
Signal.trap("HUP") { notifier.stop }
# Run the main event loop.
notifier.run
# Clean before finishing!
clean(infile)