Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [sup-devel] [PATCH] Bugfix: Don’t call Ncurses.getch when in shell�out mode
@ 2010-02-19  3:26 Michael Stapelberg
  2010-02-27  8:23 ` [sup-devel] [PATCH] Bugfix: Don\xe2\x80\x99t call Ncurses.getch when in shell\x96out mode Rich Lane
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Stapelberg @ 2010-02-19  3:26 UTC (permalink / raw)
  To: sup-devel

[-- Attachment #1: Type: text/plain, Size: 527 bytes --]

Hi,

(at least for me) the attached patch finally fixes the pinentry-ncurses
problems we were still having (as soon as you press a key, the screen is
garbage).

To quote the commit message:

  Previously, when using threads, Ncurses.getch was called while
  the gpg pinentry was running (as an example of using the shell_out
  method). Now, the Ncurses mutex will be used to wait until shell_out
  mode is finished.

Please have a look if this patch is working for you and merge it for the next
release.

Best regards,
Michael

[-- Attachment #2: 0001-Bugfix-Don-t-call-Ncurses.getch-when-in-shell_out-mo.patch --]
[-- Type: application/octet-stream, Size: 2207 bytes --]

From 4d660530beeb42d192e2da594621b81ff991df10 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Fri, 19 Feb 2010 04:20:49 +0100
Subject: [PATCH] =?UTF-8?q?Bugfix:=20Don=E2=80=99t=20call=20Ncurses.getch=20when=20in=20shell=5Fout=20mode?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Previously, when using threads, Ncurses.getch was called while
the gpg pinentry was running (as an example of using the shell_out
method). Now, the Ncurses mutex will be used to wait until shell_out
mode is finished.
---
 bin/sup           |    2 +-
 lib/sup/buffer.rb |   11 +++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/bin/sup b/bin/sup
index 7824aca..c8eb5b9 100755
--- a/bin/sup
+++ b/bin/sup
@@ -243,7 +243,7 @@ begin
 
   until Redwood::exceptions.nonempty? || $die
     c = begin
-      Ncurses.nonblocking_getch
+      Ncurses.nonblocking_getch BufferManager
     rescue Interrupt
       raise if BufferManager.ask_yes_or_no "Die ungracefully now?"
       BufferManager.draw_screen
diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
index c82fca0..84b3d00 100644
--- a/lib/sup/buffer.rb
+++ b/lib/sup/buffer.rb
@@ -30,13 +30,19 @@ module Ncurses
   def mutex; @mutex ||= Mutex.new; end
   def sync &b; mutex.synchronize(&b); end
 
-  def nonblocking_getch
+  def nonblocking_getch bm=nil
     ## INSANTIY
     ## it is NECESSARY to wrap Ncurses.getch in a select() otherwise all
     ## background threads will be BLOCKED. (except in very modern versions
     ## of libncurses-ruby. the current one on ubuntu seems to work well.)
     if IO.select([$stdin], nil, nil, 0.5)
-      c = Ncurses.getch
+      if bm && bm.shelled?
+        # If we got input while we are shelled, we will drop the input
+        # but use Ncurses.sync to wait until the shell_out is done.
+        Ncurses.sync { nil }
+      else
+        Ncurses.getch
+      end
     end
   end
 
@@ -216,6 +222,7 @@ EOS
   def sigwinch_happened?; @sigwinch_mutex.synchronize { @sigwinch_happened } end
 
   def buffers; @name_map.to_a; end
+  def shelled?; @shelled; end
 
   def focus_on buf
     return unless @buffers.member? buf
-- 
1.6.5


[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [sup-devel] [PATCH] Bugfix: Don\xe2\x80\x99t call Ncurses.getch when in shell\x96out mode
  2010-02-19  3:26 [sup-devel] [PATCH] Bugfix: Don’t call Ncurses.getch when in shell�out mode Michael Stapelberg
@ 2010-02-27  8:23 ` Rich Lane
  2010-02-27 12:48   ` Michael Stapelberg
  0 siblings, 1 reply; 9+ messages in thread
From: Rich Lane @ 2010-02-27  8:23 UTC (permalink / raw)
  To: Michael Stapelberg; +Cc: sup-devel

Excerpts from Michael Stapelberg's message of 2010-02-18 22:26:37 -0500:
> Hi,
> 
> (at least for me) the attached patch finally fixes the pinentry-ncurses
> problems we were still having (as soon as you press a key, the screen is
> garbage).
> 
> To quote the commit message:
> 
>   Previously, when using threads, Ncurses.getch was called while
>   the gpg pinentry was running (as an example of using the shell_out
>   method). Now, the Ncurses mutex will be used to wait until shell_out
>   mode is finished.
> 
> Please have a look if this patch is working for you and merge it for the next
> release.
> 
> Best regards,
> Michael

What's the reason for passing the BufferManager singleton as an
argument?

What does "drop the input" mean?
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [sup-devel] [PATCH] Bugfix: Don\xe2\x80\x99t call Ncurses.getch when in shell\x96out mode
  2010-02-27  8:23 ` [sup-devel] [PATCH] Bugfix: Don\xe2\x80\x99t call Ncurses.getch when in shell\x96out mode Rich Lane
@ 2010-02-27 12:48   ` Michael Stapelberg
  2010-02-27 18:12     ` Rich Lane
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Stapelberg @ 2010-02-27 12:48 UTC (permalink / raw)
  To: Rich Lane; +Cc: sup-devel

Hi Rich,

Excerpts from Rich Lane's message of Sa Feb 27 09:23:39 +0100 2010:
> What's the reason for passing the BufferManager singleton as an
> argument?
I am passing the BufferManager because I could not figure out how to access
it from inside the Ncurses module. Maybe there is a better way, if so, please
tell me :-).

> What does "drop the input" mean?
It means returning nil instead of Ncurses.getch, so maybe a better way of
saying it is "We do not check for input because it would restart Ncurses
while in shell-out mode".

Best regards,
Michael
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [sup-devel] [PATCH] Bugfix: Don\xe2\x80\x99t call Ncurses.getch when in shell\x96out mode
  2010-02-27 12:48   ` Michael Stapelberg
@ 2010-02-27 18:12     ` Rich Lane
  2010-02-27 19:00       ` [sup-devel] [PATCH] Bugfix: Don't call Ncurses.getch when in shell-out mode William Morgan
  2010-02-27 19:27       ` [sup-devel] [PATCH] Bugfix: Don\xe2\x80\x99t call Ncurses.getch when in shell\x96out mode Michael Stapelberg
  0 siblings, 2 replies; 9+ messages in thread
From: Rich Lane @ 2010-02-27 18:12 UTC (permalink / raw)
  To: Michael Stapelberg; +Cc: sup-devel

Excerpts from Michael Stapelberg's message of 2010-02-27 07:48:39 -0500:
> Hi Rich,
> 
> Excerpts from Rich Lane's message of Sa Feb 27 09:23:39 +0100 2010:
> > What's the reason for passing the BufferManager singleton as an
> > argument?
> I am passing the BufferManager because I could not figure out how to access
> it from inside the Ncurses module. Maybe there is a better way, if so, please
> tell me :-).

The reason we use these ugly singleton *Manager objects is to avoid
exactly this kind of plumbing. Since Ncurses is outside the Redwood
namespace you'll need to refer to it as Redwood::BufferManager.

> > What does "drop the input" mean?
> It means returning nil instead of Ncurses.getch, so maybe a better way of
> saying it is "We do not check for input because it would restart Ncurses
> while in shell-out mode".

Ok, that's how I read the code. When I saw "drop" in the comment I
thought it was going to read input and throw it away.
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [sup-devel] [PATCH] Bugfix: Don't call Ncurses.getch when in shell-out mode
  2010-02-27 18:12     ` Rich Lane
@ 2010-02-27 19:00       ` William Morgan
  2010-02-27 19:03         ` Rich Lane
  2010-02-27 19:27       ` [sup-devel] [PATCH] Bugfix: Don\xe2\x80\x99t call Ncurses.getch when in shell\x96out mode Michael Stapelberg
  1 sibling, 1 reply; 9+ messages in thread
From: William Morgan @ 2010-02-27 19:00 UTC (permalink / raw)
  To: sup-devel

Reformatted excerpts from Rich Lane's message of 2010-02-27:
> The reason we use these ugly singleton *Manager objects is to avoid
> exactly this kind of plumbing. Since Ncurses is outside the Redwood
> namespace you'll need to refer to it as Redwood::BufferManager.

I know it's fashionable to call singletons ugly nowadays, but I've never
quite bought into it. Classes are singletons too, and no one calls them
ugly...

(Well, I do, but for different reasons.)
-- 
William <wmorgan-sup@masanjin.net>
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [sup-devel] [PATCH] Bugfix: Don't call Ncurses.getch when in shell-out mode
  2010-02-27 19:00       ` [sup-devel] [PATCH] Bugfix: Don't call Ncurses.getch when in shell-out mode William Morgan
@ 2010-02-27 19:03         ` Rich Lane
  2010-02-27 19:29           ` William Morgan
  0 siblings, 1 reply; 9+ messages in thread
From: Rich Lane @ 2010-02-27 19:03 UTC (permalink / raw)
  To: William Morgan; +Cc: sup-devel

Excerpts from William Morgan's message of 2010-02-27 14:00:30 -0500:
> Reformatted excerpts from Rich Lane's message of 2010-02-27:
> > The reason we use these ugly singleton *Manager objects is to avoid
> > exactly this kind of plumbing. Since Ncurses is outside the Redwood
> > namespace you'll need to refer to it as Redwood::BufferManager.
> 
> I know it's fashionable to call singletons ugly nowadays, but I've never
> quite bought into it. Classes are singletons too, and no one calls them
> ugly...
> 
> (Well, I do, but for different reasons.)

You've never tried to write an Index testsuite :).
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [sup-devel] [PATCH] Bugfix: Don\xe2\x80\x99t call Ncurses.getch when in shell\x96out mode
  2010-02-27 18:12     ` Rich Lane
  2010-02-27 19:00       ` [sup-devel] [PATCH] Bugfix: Don't call Ncurses.getch when in shell-out mode William Morgan
@ 2010-02-27 19:27       ` Michael Stapelberg
  2010-02-27 20:14         ` Rich Lane
  1 sibling, 1 reply; 9+ messages in thread
From: Michael Stapelberg @ 2010-02-27 19:27 UTC (permalink / raw)
  To: Rich Lane; +Cc: sup-devel

Hi Rich,

Excerpts from Rich Lane's message of Sa Feb 27 19:12:19 +0100 2010:
> The reason we use these ugly singleton *Manager objects is to avoid
> exactly this kind of plumbing. Since Ncurses is outside the Redwood
> namespace you'll need to refer to it as Redwood::BufferManager.
Alright. Should I change the patch and re-send it or can you change
these little details?

Best regards,
Michael
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [sup-devel] [PATCH] Bugfix: Don't call Ncurses.getch when in shell-out mode
  2010-02-27 19:03         ` Rich Lane
@ 2010-02-27 19:29           ` William Morgan
  0 siblings, 0 replies; 9+ messages in thread
From: William Morgan @ 2010-02-27 19:29 UTC (permalink / raw)
  To: sup-devel

Reformatted excerpts from Rich Lane's message of 2010-02-27:
> You've never tried to write an Index testsuite :).

What is complicated about it?
-- 
William <wmorgan-sup@masanjin.net>
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [sup-devel] [PATCH] Bugfix: Don\xe2\x80\x99t call Ncurses.getch when in shell\x96out mode
  2010-02-27 19:27       ` [sup-devel] [PATCH] Bugfix: Don\xe2\x80\x99t call Ncurses.getch when in shell\x96out mode Michael Stapelberg
@ 2010-02-27 20:14         ` Rich Lane
  0 siblings, 0 replies; 9+ messages in thread
From: Rich Lane @ 2010-02-27 20:14 UTC (permalink / raw)
  To: Michael Stapelberg; +Cc: sup-devel

Excerpts from Michael Stapelberg's message of 2010-02-27 14:27:45 -0500:
> Excerpts from Rich Lane's message of Sa Feb 27 19:12:19 +0100 2010:
> > The reason we use these ugly singleton *Manager objects is to avoid
> > exactly this kind of plumbing. Since Ncurses is outside the Redwood
> > namespace you'll need to refer to it as Redwood::BufferManager.
> Alright. Should I change the patch and re-send it or can you change
> these little details?

I'll handle it. Applied to master.
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-02-27 20:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-19  3:26 [sup-devel] [PATCH] Bugfix: Don’t call Ncurses.getch when in shell�out mode Michael Stapelberg
2010-02-27  8:23 ` [sup-devel] [PATCH] Bugfix: Don\xe2\x80\x99t call Ncurses.getch when in shell\x96out mode Rich Lane
2010-02-27 12:48   ` Michael Stapelberg
2010-02-27 18:12     ` Rich Lane
2010-02-27 19:00       ` [sup-devel] [PATCH] Bugfix: Don't call Ncurses.getch when in shell-out mode William Morgan
2010-02-27 19:03         ` Rich Lane
2010-02-27 19:29           ` William Morgan
2010-02-27 19:27       ` [sup-devel] [PATCH] Bugfix: Don\xe2\x80\x99t call Ncurses.getch when in shell\x96out mode Michael Stapelberg
2010-02-27 20:14         ` Rich Lane

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox