Skip to content
This repository

Add +ESC key binding #120

Closed
wants to merge 1 commit into from

2 participants

Iwasaki Yudai Jonas Fonseca
Iwasaki Yudai
yudai commented

Mainly for emacs users, I'd like to introduce a new form to define key bindings with a Meta key with "^[".

Exapmle:

bind generic ^[v move-page-up

In actuality, when press a key with a Meta(or Option key on Mac) key, terminal apps send a key sequence whose first key code is KEY_ESC. This commit add a trap to receive KEY_ESC and then get the main key code again.

Iwasaki Yudai Add +ESC key binding
Exapmle:
bind generic ^[v move-page-up
5d877f0
Iwasaki Yudai
yudai commented

Hi Jonas! Thank you very much for giving me such a great tool.

I think key bindings with a Meta (or Option, Alt) are very useful for many users.
Since LESS command also allows users to page up with ^[v, I'd like to work with tig in the same way.

I'm not sure that adding 128 to the key code is the best way to represent pressing a Meta key. Some documents say Emacs uses the first bit of a 8bit key code in this way, so I choose this way.

Iwasaki Yudai yudai closed this
Jonas Fonseca
Owner
jonas commented

Hello, any reason why you are closing this pull request?

Iwasaki Yudai
yudai commented

Hi jonas! Thank you for the comment.
I thought this pull request would not be merged because I had gotten no response for a couple of weeks.
So I closed this PR just to clean up my PR list.

Jonas Fonseca
Owner
jonas commented

Sorry on my part, I am not always quick to merge.
I will look into getting it in today.

Iwasaki Yudai
yudai commented

No problem jonas, your application really helps me everyday :+1:

This change might introduce a problem to users who assign single ESC to any function, so please examine it carefully.

Jonas Fonseca
Owner
jonas commented

OK, pushed. Thanks again for your patience. ;)

Iwasaki Yudai
yudai commented

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 01, 2013
Iwasaki Yudai Add +ESC key binding
Exapmle:
bind generic ^[v move-page-up
5d877f0
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 5 additions and 0 deletions. Show diff stats Hide diff stats

  1. 5  tig.c
5  tig.c
@@ -1047,6 +1047,8 @@ get_key_value(const char *name)
1047 1047
 		if (!strcasecmp(key_table[i].name, name))
1048 1048
 			return key_table[i].value;
1049 1049
 
  1050
+	if (strlen(name) == 3 && name[0] == '^' && name[1] == '[' && isprint(*name))
  1051
+		return (int)name[2] + 0x80;
1050 1052
 	if (strlen(name) == 2 && name[0] == '^' && isprint(*name))
1051 1053
 		return (int)name[1] & 0x1f;
1052 1054
 	if (strlen(name) == 1 && isprint(*name))
@@ -8517,6 +8519,9 @@ main(int argc, const char *argv[])
8517 8519
 	while (view_driver(display[current_view], request)) {
8518 8520
 		int key = get_input(0);
8519 8521
 
  8522
+		if (key == KEY_ESC)
  8523
+			key  = get_input(0) + 0x80;
  8524
+
8520 8525
 		view = display[current_view];
8521 8526
 		request = get_keybinding(&view->ops->keymap, key);
8522 8527
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.