Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15

Re: [PATCH] Highlight keyboard shortcuts in git-add--interactive

From: Wincent Colaiuta <hidden>
Date: 2016-06-15 22:43:55
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

El 2/12/2007, a las 20:06, Junio C Hamano escribió:
Wincent Colaiuta [off-list ref] writes:
quoted
Unless by "documentation" you meant to somehow expose these in the
interface at runtime... something like this? (applied on top of the
patch I just sent to the list):
I did not recall (and was too lazy to check) if they were documented
already, but as you suggest, I think letting people type ? at the  
prompt
to get a help is always a good idea.  So, instead of doing this part:
quoted
@@ -308,7 +309,7 @@ sub list_and_choose {
 			print "> ";
 		}
 		else {
-			print ">> ";
+			print " (?)>> ";
I'd prefer accepting '?'  as a valid "help me" input and showing
appropriate help for _both_ singleton select and multiple select,
without mentioning " (?)".  For this, your prompt_help_cmd needs to be
enhanced to limit the help to singleton case, though.

That's actually the way I did it the first time, but then decided that  
the singleton prompt help had so little to say that I doubted about  
including it. Something like this, once again on top of the patch I  
posted yesterday ("Fixes for automatic prefix highlighting"):
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 32fb9ea..335c2c6 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -237,7 +237,8 @@ sub is_valid_prefix {
  	    !($prefix =~ /[\s,]/) && # separators
  	    !($prefix =~ /^-/) &&    # deselection
  	    !($prefix =~ /^\d+/) &&  # selection
-	    ($prefix ne '*');        # "all" wildcard
+	    ($prefix ne '*') &&      # "all" wildcard
+	    ($prefix ne '?');        # prompt help
  }

  # given a prefix/remainder tuple return a string with the prefix  
highlighted
@@ -318,6 +319,12 @@ sub list_and_choose {
  		}
  		chomp $line;
  		last if $line eq '';
+		if ($line eq '?') {
+			$opts->{SINGLETON} ?
+			    singleton_prompt_help_cmd() :
+			    prompt_help_cmd();
+			next TOPLOOP;
+		}
  		for my $choice (split(/[\s,]+/, $line)) {
  			my $choose = 1;
  			my ($bottom, $top);
@@ -363,6 +370,28 @@ sub list_and_choose {
  	return @return;
  }

+sub singleton_prompt_help_cmd {
+	print <<\EOF ;
+Prompt help:
+1          - select a numbered item
+foo        - select item based on unique prefix
+           - (empty) select nothing
+EOF
+}
+
+sub prompt_help_cmd {
+	print <<\EOF ;
+Prompt help:
+1          - select a single item
+3-5        - select a range of items
+2-3,6-9    - select multiple ranges
+foo        - select item based on unique prefix
+-...       - unselect specified items
+*          - choose all items
+           - (empty) finish selecting
+EOF
+}
+
  sub status_cmd {
  	list_and_choose({ LIST_ONLY => 1, HEADER => $status_head },
  			list_modified());


Cheers,
Wincent
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help