{"thread":{"id":"16177","subject":"[PATCH/RFC] git-add--interactive.perl: Answer questions with a single keypress","startedAt":"2008-11-05T06:15:23Z","lastAt":"2008-11-07T19:19:41Z","messageCount":8,"participants":["Suraj N. Kurapati","Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"94960","messageId":"200811042215.31147.sunaku@gmail.com","threadId":"16177","inReplyTo":null,"subject":"[PATCH/RFC] git-add--interactive.perl: Answer questions with a single keypress","fromName":"Suraj N. Kurapati","fromEmail":"sunaku@gmail.com","sentAt":"2008-11-05T06:15:23Z","receivedAt":"2008-11-05T06:15:23Z","isPatch":true,"sender":{"key":"sunaku@gmail.com","avatar":"https://gravatar.com/avatar/30b9a72c51e7281e513a6cbb3591675166b9655a12454b8641a21194155d42ca?d=mp&s=160"},"body":"From aef6df163b90b9485da1f97a14ffab6d8de9b047 Mon Sep 17 00:00:00 2001\nFrom: Suraj N. Kurapati <sunaku@gmail.com>\nDate: Tue, 4 Nov 2008 20:32:34 -0800\nSubject: [PATCH] git-add--interactive.perl: Answer questions with a single keypress\n\nAllows the user to answer 'Stage this hunk' questions with a\nsingle keypress, just like in Darcs.  Previously, the user\nwas forced to press the Return key after every choice, which\nquickly becomes tiring and burdensome work for the fingers.\n\nSigned-off-by: Suraj N. Kurapati <sunaku@gmail.com>\n---\n git-add--interactive.perl |    6 +++++-\n 1 files changed, 5 insertions(+), 1 deletions(-)\n\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex b0223c3..1a22968 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -877,6 +877,7 @@ sub patch_update_file {\n \t$num = scalar @hunk;\n \t$ix = 0;\n \n+\trequire Term::ReadKey;\n \twhile (1) {\n \t\tmy ($prev, $next, $other, $undecided, $i);\n \t\t$other = '';\n@@ -920,7 +921,10 @@ sub patch_update_file {\n \t\t\tprint;\n \t\t}\n \t\tprint colored $prompt_color, \"Stage this hunk [y/n/a/d$other/?]? \";\n-\t\tmy $line = <STDIN>;\n+\n+\t\tTerm::ReadKey::ReadMode('raw');\n+\t\tmy $line = Term::ReadKey::ReadKey(0);\n+\t\tTerm::ReadKey::ReadMode('restore');\n \t\tif ($line) {\n \t\t\tif ($line =~ /^y/i) {\n \t\t\t\t$hunk[$ix]{USE} = 1;\n-- \n1.6.0.3\n\n\n"},{"id":"94961","messageId":"200811042231.19124.sunaku@gmail.com","threadId":"16177","inReplyTo":"200811042215.31147.sunaku@gmail.com","subject":"Re: [PATCH/RFC v2] git-add--interactive.perl: Answer questions with a single keypress","fromName":"Suraj N. Kurapati","fromEmail":"sunaku@gmail.com","sentAt":"2008-11-05T06:31:19Z","receivedAt":"2008-11-05T06:31:19Z","isPatch":true,"sender":{"key":"sunaku@gmail.com","avatar":"https://gravatar.com/avatar/30b9a72c51e7281e513a6cbb3591675166b9655a12454b8641a21194155d42ca?d=mp&s=160"},"body":"Allows the user to answer 'Stage this hunk' questions with a\nsingle keypress, just like in Darcs.  Previously, the user was\nforced to press the Return key after every choice they made.\nThis quickly becomes tiring, burdensome work for the fingers.\n\nSigned-off-by: Suraj N. Kurapati <sunaku@gmail.com>\n---\n git-add--interactive.perl |    5 ++++-\n 1 files changed, 4 insertions(+), 1 deletions(-)\n\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex b0223c3..a824984 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -877,6 +877,8 @@ sub patch_update_file {\n \t$num = scalar @hunk;\n \t$ix = 0;\n \n+\trequire Term::ReadKey;\n+\tTerm::ReadKey::ReadMode('raw');\n \twhile (1) {\n \t\tmy ($prev, $next, $other, $undecided, $i);\n \t\t$other = '';\n@@ -920,7 +922,7 @@ sub patch_update_file {\n \t\t\tprint;\n \t\t}\n \t\tprint colored $prompt_color, \"Stage this hunk [y/n/a/d$other/?]? \";\n-\t\tmy $line = <STDIN>;\n+\t\tmy $line = Term::ReadKey::ReadKey(0);\n \t\tif ($line) {\n \t\t\tif ($line =~ /^y/i) {\n \t\t\t\t$hunk[$ix]{USE} = 1;\n@@ -998,6 +1000,7 @@ sub patch_update_file {\n \t\t\t}\n \t\t}\n \t}\n+\tTerm::ReadKey::ReadMode('restore');\n \n \tmy $n_lofs = 0;\n \tmy @result = ();\n-- \n1.6.0.3\n\n\n"},{"id":"94983","messageId":"200811050959.25824.sunaku@gmail.com","threadId":"16177","inReplyTo":"200811042215.31147.sunaku@gmail.com","subject":"Re: [PATCH/RFC v3] git add -i: Answer questions with a single keypress","fromName":"Suraj N. Kurapati","fromEmail":"sunaku@gmail.com","sentAt":"2008-11-05T17:59:25Z","receivedAt":"2008-11-05T17:59:25Z","isPatch":true,"sender":{"key":"sunaku@gmail.com","avatar":"https://gravatar.com/avatar/30b9a72c51e7281e513a6cbb3591675166b9655a12454b8641a21194155d42ca?d=mp&s=160"},"body":"Allows the user to answer 'Stage this hunk' questions with a\nsingle keypress, just like in Darcs.  Previously, the user was\nforced to press the Return key after every choice they made.\nThis quickly becomes tiring, burdensome work for the fingers.\n\nSigned-off-by: Suraj N. Kurapati <sunaku@gmail.com>\n---\n git-add--interactive.perl |    5 ++++-\n 1 files changed, 4 insertions(+), 1 deletions(-)\n\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex b0223c3..b71905e 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -877,6 +877,8 @@ sub patch_update_file {\n \t$num = scalar @hunk;\n \t$ix = 0;\n \n+\trequire Term::ReadKey;\n+\tTerm::ReadKey::ReadMode('cbreak');\n \twhile (1) {\n \t\tmy ($prev, $next, $other, $undecided, $i);\n \t\t$other = '';\n@@ -920,7 +922,7 @@ sub patch_update_file {\n \t\t\tprint;\n \t\t}\n \t\tprint colored $prompt_color, \"Stage this hunk [y/n/a/d$other/?]? \";\n-\t\tmy $line = <STDIN>;\n+\t\tmy $line = Term::ReadKey::ReadKey(0);\n \t\tif ($line) {\n \t\t\tif ($line =~ /^y/i) {\n \t\t\t\t$hunk[$ix]{USE} = 1;\n@@ -998,6 +1000,7 @@ sub patch_update_file {\n \t\t\t}\n \t\t}\n \t}\n+\tTerm::ReadKey::ReadMode('restore');\n \n \tmy $n_lofs = 0;\n \tmy @result = ();\n-- \n1.6.0.3\n\n\n"},{"id":"95034","messageId":"20081106084230.GA4407@sigill.intra.peff.net","threadId":"16177","inReplyTo":"200811050959.25824.sunaku@gmail.com","subject":"Re: [PATCH/RFC v3] git add -i: Answer questions with a single keypress","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-11-06T08:42:36Z","receivedAt":"2008-11-06T08:42:36Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Nov 05, 2008 at 09:59:25AM -0800, Suraj N. Kurapati wrote:\n\n> Allows the user to answer 'Stage this hunk' questions with a\n> single keypress, just like in Darcs.  Previously, the user was\n> forced to press the Return key after every choice they made.\n> This quickly becomes tiring, burdensome work for the fingers.\n\nI think this is a reasonable goal, but I have a few questions/concerns.\n\n - There are three versions of your patch, but nobody has commented.\n   Clearly we can see what changed, but it is not clear what advantage\n   one patch has over the other. Care to elaborate?\n\n - Term::ReadKey, while common, is not part of base perl. So I think\n   using it needs to be conditional, and on systems without it we can\n   degrade to the current behavior.\n\n - There's no facility in your patch for restoring the terminal if we\n   break out of the loop in an unexpected way (e.g., via the user\n   hitting ^C).\n\n - This only enhances one particular input, the patch loop. It is\n   probably worth being consistent and allowing these behavior for other\n   menus (though the numeric inputs are a bit trickier).\n\n-Peff\n"},{"id":"95057","messageId":"200811060815.16797.sunaku@gmail.com","threadId":"16177","inReplyTo":"20081106084230.GA4407@sigill.intra.peff.net","subject":"Re: [PATCH/RFC v3] git add -i: Answer questions with a single keypress","fromName":"Suraj N. Kurapati","fromEmail":"sunaku@gmail.com","sentAt":"2008-11-06T16:15:16Z","receivedAt":"2008-11-06T16:15:16Z","isPatch":true,"sender":{"key":"sunaku@gmail.com","avatar":"https://gravatar.com/avatar/30b9a72c51e7281e513a6cbb3591675166b9655a12454b8641a21194155d42ca?d=mp&s=160"},"body":"On Thursday 06 November 2008 00:42:36 Jeff King wrote:\n> On Wed, Nov 05, 2008 at 09:59:25AM -0800, Suraj N. Kurapati wrote:\n> > Allows the user to answer 'Stage this hunk' questions with a\n> > single keypress, just like in Darcs.  Previously, the user was\n> > forced to press the Return key after every choice they made.\n> > This quickly becomes tiring, burdensome work for the fingers.\n>\n> I think this is a reasonable goal, but I have a few questions/concerns.\n>\n>  - There are three versions of your patch, but nobody has commented.\n>    Clearly we can see what changed, but it is not clear what advantage\n>    one patch has over the other. Care to elaborate?\n\nv1 and v2 make the mistake of setting raw mode, which prevent the user from \npressing Control-C to exit the program.  v3 fixes this by using cbreak mode.\n\n>  - Term::ReadKey, while common, is not part of base perl. So I think\n>    using it needs to be conditional, and on systems without it we can\n>    degrade to the current behavior.\n\nThe git-svn.perl script also uses Term::ReadKey.  Since it is already in the \ngit source repository, I thought it was okay to use Term::ReadKey.\n\n>  - There's no facility in your patch for restoring the terminal if we\n>    break out of the loop in an unexpected way (e.g., via the user\n>    hitting ^C).\n\nGood point.  I'll try to address this in a v4 patch.\n\n>  - This only enhances one particular input, the patch loop. It is\n>    probably worth being consistent and allowing these behavior for other\n>    menus (though the numeric inputs are a bit trickier).\n\nUnderstood.\n"},{"id":"95061","messageId":"7vk5bgiy18.fsf@gitster.siamese.dyndns.org","threadId":"16177","inReplyTo":"200811060815.16797.sunaku@gmail.com","subject":"Re: [PATCH/RFC v3] git add -i: Answer questions with a single keypress","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-11-06T17:06:59Z","receivedAt":"2008-11-06T17:06:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Suraj N. Kurapati\" <sunaku@gmail.com> writes:\n\n> On Thursday 06 November 2008 00:42:36 Jeff King wrote:\n>> On Wed, Nov 05, 2008 at 09:59:25AM -0800, Suraj N. Kurapati wrote:\n>> > Allows the user to answer 'Stage this hunk' questions with a\n>> > single keypress, just like in Darcs.  Previously, the user was\n>> > forced to press the Return key after every choice they made.\n>> > This quickly becomes tiring, burdensome work for the fingers.\n>>\n>> I think this is a reasonable goal, but I have a few questions/concerns.\n>>\n>>  - There are three versions of your patch, but nobody has commented.\n>>    Clearly we can see what changed, but it is not clear what advantage\n>>    one patch has over the other. Care to elaborate?\n>\n> v1 and v2 make the mistake of setting raw mode, which prevent the user from \n> pressing Control-C to exit the program.  v3 fixes this by using cbreak mode.\n\nWhen I was reading the last round I noticed the above change myself, but\nit is customary to write this kind of \"patch changelog\" under --- line in\nyour patch around here.  That way you can save everybody's time.\n\nThanks.  And thanks, Jeff, for being a good reviewer.\n \n"},{"id":"95136","messageId":"20081107191910.GA15218@coredump.intra.peff.net","threadId":"16177","inReplyTo":"200811060815.16797.sunaku@gmail.com","subject":"Re: [PATCH/RFC v3] git add -i: Answer questions with a single keypress","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-11-07T19:19:10Z","receivedAt":"2008-11-07T19:19:10Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Nov 06, 2008 at 08:15:16AM -0800, Suraj N. Kurapati wrote:\n\n> v1 and v2 make the mistake of setting raw mode, which prevent the user from \n> pressing Control-C to exit the program.  v3 fixes this by using cbreak mode.\n\nOK, makes sense.\n\n> The git-svn.perl script also uses Term::ReadKey.  Since it is already in the \n> git source repository, I thought it was okay to use Term::ReadKey.\n\nWe are not always consistent with such things, and git-add--interactive\nis a little \"more core\" than git-svn, I think. Still, maybe I am being\noverly cautious. We can always try it and see who complains. ;)\n\nI think considering this improvement:\n\n> >  - This only enhances one particular input, the patch loop. It is\n> >    probably worth being consistent and allowing these behavior for other\n> >    menus (though the numeric inputs are a bit trickier).\n> \n> Understood.\n\nit makes sense to factor the ReadKey procedure into a separate function\nanyway. At which point it should be easy enough to substitute in the\noriginal behavior if there is no ReadKey.\n\nSide note: I don't know if such people exist, but I suppose it is\npossible that somebody would _prefer_ the old behavior. In which case\nfactoring it out will also make it easier to predicate the behavior on a\nconfig variable, if people want that.\n\n-Peff\n"},{"id":"95137","messageId":"20081107191941.GB15218@coredump.intra.peff.net","threadId":"16177","inReplyTo":"7vk5bgiy18.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH/RFC v3] git add -i: Answer questions with a single keypress","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-11-07T19:19:41Z","receivedAt":"2008-11-07T19:19:41Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Nov 06, 2008 at 09:06:59AM -0800, Junio C Hamano wrote:\n\n> Thanks.  And thanks, Jeff, for being a good reviewer.\n\nYou're welcome. I'm trying to lead by example. :)\n\n-Peff\n"}]}