Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Eric Sherman <hyperbolist@gmail.com>
To: sup-devel <sup-devel@rubyforge.org>
Subject: Re: [sup-devel] [PATCH] [issue14] poll updates accumulate while idle
Date: Mon, 04 Jan 2010 06:47:46 -0500	[thread overview]
Message-ID: <1262605439-sup-7146@changeling.local> (raw)
In-Reply-To: <1262585888-sup-7490@changeling.local>

Excerpts from Eric Sherman's message of Mon Jan 04 01:20:34 -0500 2010:
> If you were to leave sup running for a long time, this patch would
> enable you to get a glance summary of new mail activity since sup was
> last touched, by letting the poll update message accumulate its tally
> while idle.
> 
> On keystrokes, BufferManager sends an :unidle update if the last
> keystroke occurred more than :idle_threshold seconds ago.  PollManager
> listens for :unidle updates to clear PollTally, which will otherwise
> accumulate.
> 
> * :idle_threshold defaults to 60 seconds if not defined in config.yaml
> * presently no :idle update is sent when becoming idle
> * after-poll behavior is unaffected
> ---
>  lib/sup.rb        |    3 ++-
>  lib/sup/buffer.rb |    5 +++++
>  lib/sup/poll.rb   |   23 +++++++++++++++++++++--
>  3 files changed, 28 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/sup.rb b/lib/sup.rb
> index 840b3fc..a6de0ab 100644
> --- a/lib/sup.rb
> +++ b/lib/sup.rb
> @@ -229,7 +229,8 @@ else
>      :confirm_top_posting => true,
>      :discard_snippets_from_encrypted_messages => false,
>      :default_attachment_save_dir => "",
> -    :sent_source => "sup://sent"
> +    :sent_source => "sup://sent",
> +    :idle_threshold => 60
>    }
>    begin
>      FileUtils.mkdir_p Redwood::BASE_DIR
> diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
> index c826ab9..c34917d 100644
> --- a/lib/sup/buffer.rb
> +++ b/lib/sup/buffer.rb
> @@ -212,6 +212,7 @@ EOS
>      @in_x = ENV["TERM"] =~ /(xterm|rxvt|screen)/
>      @sigwinch_happened = false
>      @sigwinch_mutex = Mutex.new
> +    @idle_since = Time.now
>    end
>  
>    def sigwinch_happened!; @sigwinch_mutex.synchronize { @sigwinch_happened = true } end
> @@ -269,6 +270,8 @@ EOS
>          @focus_buf.mode.cancel_search!
>          @focus_buf.mark_dirty
>        end
> +      UpdateManager.relay self, :unidle, Time.at(@idle_since) if idle?
> +      @idle_since = Time.now
>        @focus_buf.mode.handle_input c
>      end
>    end
> @@ -797,5 +800,7 @@ private
>      end
>      @users
>    end
> +
> +  def idle?; Time.now.to_i - @idle_since.to_i >= ($config[:idle_threshold] || 60); end
>  end
>  end
> diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
> index 4f30505..fb684df 100644
> --- a/lib/sup/poll.rb
> +++ b/lib/sup/poll.rb
> @@ -37,6 +37,8 @@ EOS
>      @polling = false
>      @poll_sources = nil
>      @mode = nil
> +    PollTally.init
> +    UpdateManager.register self
>    end
>  
>    def poll_with_sources
> @@ -45,8 +47,9 @@ EOS
>  
>      BufferManager.flash "Polling for new messages..."
>      num, numi, from_and_subj, from_and_subj_inbox, loaded_labels = @mode.poll
> -    if num > 0
> -      BufferManager.flash "Loaded #{num.pluralize 'new message'}, #{numi} to inbox. Labels: #{loaded_labels.map{|l| l.to_s}.join(', ')}"
> +    PollTally.add :num => num, :num_inbox => numi, :loaded_labels => loaded_labels
> +    if PollTally.num > 0
> +      BufferManager.flash "Loaded #{PollTally.num.pluralize 'new message'}, #{PollTally.num_inbox} to inbox. Labels: #{PollTally.loaded_labels.map{|l| l.to_s}.join(', ')}"
>      else
>        BufferManager.flash "No new messages." 
>      end
> @@ -183,6 +186,22 @@ EOS
>      Index.add_message m
>      UpdateManager.relay self, :added, m
>    end
> +
> +  def handle_unidle_update sender, idle_since; PollTally.clear; end
> +end
> +
> +class PollTally
> +  include Singleton
> +  attr_reader :num, :num_inbox, :loaded_labels
> +
> +  def initialize; @num = 0; @num_inbox = 0; @loaded_labels = Set.new; end
> +  def clear; @num = 0; @num_inbox = 0; @loaded_labels.clear; end
> +
> +  def add opts={}
> +    @num += opts[:num]||0
> +    @num_inbox += opts[:num_inbox]||0
> +    @loaded_labels = Set.new(opts[:loaded_labels] || []) + @loaded_labels
> +  end
>  end
>  
>  end

Oops, please disregard this patch.  If one never goes idle, one can never 
go unidle, and so the PollTally will never clear.  I will resubmit a 
revised patch which clears the PollTally on polling unless idle.
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


      reply	other threads:[~2010-01-04 11:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-04  6:20 Eric Sherman
2010-01-04 11:47 ` Eric Sherman [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1262605439-sup-7146@changeling.local \
    --to=hyperbolist@gmail.com \
    --cc=sup-devel@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox