lib/sup.rb in sup-0.5 vs lib/sup.rb in sup-0.6

- old
+ new

@@ -4,10 +4,23 @@ require 'thread' require 'fileutils' require 'gettext' require 'curses' +## the following magic enables wide characters when used with a ruby +## ncurses.so that's been compiled against libncursesw. (note the w.) why +## this works, i have no idea. much like pretty much every aspect of +## dealing with curses. cargo cult programming at its best. + +require 'dl/import' +module LibC + extend DL::Importable + dlload Config::CONFIG['arch'] =~ /darwin/ ? "libc.dylib" : "libc.so.6" + extern "void setlocale(int, const char *)" +end +LibC.setlocale(6, "") # LC_ALL == 6 + class Object ## this is for debugging purposes because i keep calling #id on the ## wrong object and i want it to throw an exception def id raise "wrong id called on #{self.inspect}" @@ -31,14 +44,15 @@ end end end module Redwood - VERSION = "0.5" + VERSION = "0.6" BASE_DIR = ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup") CONFIG_FN = File.join(BASE_DIR, "config.yaml") + COLOR_FN = File.join(BASE_DIR, "colors.yaml") SOURCE_FN = File.join(BASE_DIR, "sources.yaml") LABEL_FN = File.join(BASE_DIR, "labels.txt") PERSON_FN = File.join(BASE_DIR, "people.txt") CONTACT_FN = File.join(BASE_DIR, "contacts.txt") DRAFT_DIR = File.join(BASE_DIR, "drafts") @@ -48,26 +62,36 @@ HOOK_DIR = File.join(BASE_DIR, "hooks") YAML_DOMAIN = "masanjin.net" YAML_DATE = "2006-10-01" -## record exceptions thrown in threads nicely + ## record exceptions thrown in threads nicely + @exceptions = [] + @exception_mutex = Mutex.new + + attr_reader :exceptions + def record_exception e, name + @exception_mutex.synchronize do + @exceptions ||= [] + @exceptions << [e, name] + end + end + def reporting_thread name if $opts[:no_threads] yield else ::Thread.new do begin yield rescue Exception => e - $exceptions ||= [] - $exceptions << [e, name] - raise + record_exception e, name end end end end - module_function :reporting_thread + + module_function :reporting_thread, :record_exception, :exceptions ## one-stop shop for yamliciousness def save_yaml_obj object, fn, safe=false if safe safe_fn = "#{File.dirname fn}/safe_#{File.basename fn}"