Sha256: 98bfe50895f3b831b029e5232736d725d04e86fa5ea5af8546ba1d51034774da

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

#!/usr/bin/env ruby
# coding: utf-8

require 'mnogootex'


# require 'pathname'

# target = ARGV[0]
# target_path = File.expand_path target
# cfg = Mnogootex::Configuration.new
# cfg.load target_path

require 'tmpdir'
require 'fileutils'
require 'open3'

require 'colorize'

target = ARGV[0]


raise "No parameters given." if ARGV.length.zero?

if ARGV.length == 3
  raise "Unknown command." unless %w{show view open}.include? ARGV[1].downcase
  job = Mnogootex::Job.new cls: ARGV[2], target: File.expand_path(target)
  pdf = Dir.glob("#{job.tmp_dirname}/*.pdf").first
  raise "PDF non esiste." unless File.exist? pdf
  `open #{pdf}`
  exit
end

puts "Mnogootex v#{Mnogootex::VERSION}"

main_path = File.expand_path(target)
main_basename = File.basename main_path
main_dirname = File.dirname main_path

cfg = Mnogootex::Configuration.new
cfg.load main_dirname

raise "File non esiste." unless File.exist? main_path

@documentclasses = cfg['compile_with']

$jobs = []
$threads = []
$draw_threads = []

$threads = []

$anim = cfg['animation'].freeze

STDOUT.sync = true

def draw_status
  icons = $jobs.map do |j|
    icon = $anim[j.ticks % $anim.length]
    case j.thread.status
    when 'sleep', 'run', 'aborting'
      icon.yellow
    when false, nil # exited (normally or w/ error)
      j.success? ? icon.green : icon.red
    end
  end
  print '  Jobs: ' + icons.join + "\r"
end

draw_status

@documentclasses.each_with_index do |cls, index|
  job = Mnogootex::Job.new cls: cls, target: main_path
  job.setup
  job.run

  $jobs << job

  $draw_threads << job.tick_thread
  $threads << job.thread
end

$threads.map(&:join)
$draw_threads.map(&:join)

puts

puts '  Details:'
$jobs.each do |job|
  if job.success?
    puts '    ' + "✔".green + ' ' + File.basename(job.cls)
  else
    puts '    ' + "✘".red + ' ' + File.basename(job.cls)
    puts job.log[2..-2].join.gsub(/^/,' '*6).chomp.red
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mnogootex-0.2.0 exe/mnogootex