]> git.cworth.org Git - sup/blobdiff - lib/sup.rb
Remove the now useless PersonManager
[sup] / lib / sup.rb
index ac242ecaf905400e8fdfdb0390768f9c29cb8398..3afac5e012b0e9438434981fa2ebaae068ec9ea4 100644 (file)
@@ -3,8 +3,22 @@ require 'yaml'
 require 'zlib'
 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
@@ -32,13 +46,13 @@ class Module
 end
 
 module Redwood
-  VERSION = "0.2"
+  VERSION = "git"
 
   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")
   SENT_FN    = File.join(BASE_DIR, "sent.mbox")
@@ -49,19 +63,19 @@ module Redwood
   YAML_DOMAIN = "masanjin.net"
   YAML_DATE = "2006-10-01"
 
-## determine encoding and character set
-## probably a better way to do this
-  $ctype = ENV["LC_CTYPE"] || ENV["LANG"] || "en-US.utf-8"
-  $encoding =
-    if $ctype =~ /\.(.*)?/
-      $1
-    else
-      "utf-8"
+  ## 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
 
-## record exceptions thrown in threads nicely
-  $exception = nil
-  def reporting_thread
+  def reporting_thread name
     if $opts[:no_threads]
       yield
     else
@@ -69,19 +83,19 @@ module Redwood
         begin
           yield
         rescue Exception => e
-          $exception ||= e
-          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}"
-      mode = File.stat(fn) if File.exists? fn
+      mode = File.stat(fn).mode if File.exists? fn
       File.open(safe_fn, "w", mode) { |f| f.puts object.to_yaml }
       FileUtils.mv safe_fn, fn
     else
@@ -100,7 +114,6 @@ module Redwood
   end
 
   def start
-    Redwood::PersonManager.new Redwood::PERSON_FN
     Redwood::SentManager.new Redwood::SENT_FN
     Redwood::ContactManager.new Redwood::CONTACT_FN
     Redwood::LabelManager.new Redwood::LABEL_FN
@@ -115,16 +128,17 @@ module Redwood
   def finish
     Redwood::LabelManager.save if Redwood::LabelManager.instantiated?
     Redwood::ContactManager.save if Redwood::ContactManager.instantiated?
-    Redwood::PersonManager.save if Redwood::PersonManager.instantiated?
     Redwood::BufferManager.deinstantiate! if Redwood::BufferManager.instantiated?
   end
 
   ## not really a good place for this, so I'll just dump it here.
+  ##
+  ## a source error is either a FatalSourceError or an OutOfSyncSourceError.
+  ## the superclass SourceError is just a generic.
   def report_broken_sources opts={}
     return unless BufferManager.instantiated?
 
-    broken_sources = Index.usual_sources.select { |s| s.error.is_a? FatalSourceError }
-    File.open("goat", "w") { |f| f.puts Kernel.caller }
+    broken_sources = Index.sources.select { |s| s.error.is_a? FatalSourceError }
     unless broken_sources.empty?
       BufferManager.spawn_unless_exists("Broken source notification for #{broken_sources.join(',')}", opts) do
         TextMode.new(<<EOM)
@@ -141,7 +155,7 @@ EOM
       end
     end
 
-    desynced_sources = Index.usual_sources.select { |s| s.error.is_a? OutOfSyncSourceError }
+    desynced_sources = Index.sources.select { |s| s.error.is_a? OutOfSyncSourceError }
     unless desynced_sources.empty?
       BufferManager.spawn_unless_exists("Out-of-sync source notification for #{broken_sources.join(',')}", opts) do
         TextMode.new(<<EOM)
@@ -176,7 +190,8 @@ if File.exists? Redwood::CONFIG_FN
 else
   require 'etc'
   require 'socket'
-  name = Etc.getpwnam(ENV["USER"]).gecos.split(/,/).first
+  name = Etc.getpwnam(ENV["USER"]).gecos.split(/,/).first rescue nil
+  name ||= ENV["USER"]
   email = ENV["USER"] + "@" + 
     begin
       Socket.gethostbyname(Socket.gethostname).first
@@ -202,6 +217,8 @@ else
     :ask_for_subject => true,
     :confirm_no_attachments => true,
     :confirm_top_posting => true,
+    :discard_snippets_from_encrypted_messages => false,
+    :default_attachment_save_dir => "",
   }
   begin
     FileUtils.mkdir_p Redwood::BASE_DIR
@@ -232,6 +249,15 @@ module Redwood
   module_function :log
 end
 
+## determine encoding and character set
+  $encoding = Locale.current.charset
+  if $encoding
+    Redwood::log "using character set encoding #{$encoding.inspect}"
+  else
+    Redwood::log "warning: can't find character set by using locale, defaulting to utf-8"
+    $encoding = "utf-8"
+  end
+
 ## now everything else (which can feel free to call Redwood::log at load time)
 require "sup/update"
 require "sup/suicide"
@@ -253,6 +279,7 @@ require "sup/tagger"
 require "sup/draft"
 require "sup/poll"
 require "sup/crypto"
+require "sup/horizontal-selector"
 require "sup/modes/line-cursor-mode"
 require "sup/modes/help-mode"
 require "sup/modes/edit-message-mode"