git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC] git-add--interactive.perl: Answer questions with a single keypress

From
Suraj N. Kurapati <sunaku@gmail.com>
Date
Nov 5, 2008, 06:15 UTC
Message-ID
<200811042215.31147.sunaku@gmail.com>
From aef6df163b90b9485da1f97a14ffab6d8de9b047 Mon Sep 17 00:00:00 2001
From: Suraj N. Kurapati <sunaku@gmail.com>
Date: Tue, 4 Nov 2008 20:32:34 -0800
Subject: [PATCH] git-add--interactive.perl: Answer questions with a single keypress

Allows the user to answer 'Stage this hunk' questions with a single keypress, just like in Darcs. Previously, the user was forced to press the Return key after every choice, which quickly becomes tiring and burdensome work for the fingers.

Signed-off-by: Suraj N. Kurapati <sunaku@gmail.com>
---
 git-add--interactive.perl |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index b0223c3..1a22968 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -877,6 +877,7 @@ sub patch_update_file {
 	$num = scalar @hunk;
 	$ix = 0;
 
+	require Term::ReadKey;
 	while (1) {
 		my ($prev, $next, $other, $undecided, $i);
 		$other = '';
@@ -920,7 +921,10 @@ sub patch_update_file {
 			print;
 		}
 		print colored $prompt_color, "Stage this hunk [y/n/a/d$other/?]? ";
-		my $line = <STDIN>;
+
+		Term::ReadKey::ReadMode('raw');
+		my $line = Term::ReadKey::ReadKey(0);
+		Term::ReadKey::ReadMode('restore');
 		if ($line) {
 			if ($line =~ /^y/i) {
 				$hunk[$ix]{USE} = 1;
-- 
1.6.0.3
Next: Suraj N. Kurapati
Message 1 of 8 in “git-add--interactive.perl: Answer questions with a single keypress”
  1. git-add--interactive.perl: Answer questions with a single keypressSuraj N. Kurapati, Nov 5, 2008
  2. Suraj N. KurapatiNov 5, 2008
  3. Suraj N. KurapatiNov 5, 2008
  4. Jeff KingNov 6, 2008
  5. Suraj N. KurapatiNov 6, 2008
  6. Junio C HamanoNov 6, 2008
  7. Jeff KingNov 7, 2008
  8. Jeff KingNov 7, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.