aboutsummaryrefslogtreecommitdiff
path: root/miscutils/less.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-05-17 16:44:54 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-05-17 16:44:54 +0200
commit020f40693a08b836abdea74f3823a0bce0378ec5 (patch)
tree4ae11c9b2156cccc1af8904c11c195b25b2886b0 /miscutils/less.c
parent071ede1e5de784820f39c2546000c08d74b12f6d (diff)
downloadbusybox-w32-020f40693a08b836abdea74f3823a0bce0378ec5.tar.gz
busybox-w32-020f40693a08b836abdea74f3823a0bce0378ec5.tar.bz2
busybox-w32-020f40693a08b836abdea74f3823a0bce0378ec5.zip
line editing: add an option to emit ESC [ 6 n and use results
This makes line editing able to recognize case when cursor was not at the beginning of the line. It may also be adapted later to find out display size (serial line users would love it). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils/less.c')
-rw-r--r--miscutils/less.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/miscutils/less.c b/miscutils/less.c
index 702c4a891..bd855066f 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -96,7 +96,6 @@ struct globals {
96 smallint pattern_valid; 96 smallint pattern_valid;
97#endif 97#endif
98 smallint terminated; 98 smallint terminated;
99 smalluint kbd_input_size;
100 struct termios term_orig, term_less; 99 struct termios term_orig, term_less;
101 char kbd_input[KEYCODE_BUFFER_SIZE]; 100 char kbd_input[KEYCODE_BUFFER_SIZE];
102}; 101};
@@ -135,7 +134,6 @@ struct globals {
135#define terminated (G.terminated ) 134#define terminated (G.terminated )
136#define term_orig (G.term_orig ) 135#define term_orig (G.term_orig )
137#define term_less (G.term_less ) 136#define term_less (G.term_less )
138#define kbd_input_size (G.kbd_input_size )
139#define kbd_input (G.kbd_input ) 137#define kbd_input (G.kbd_input )
140#define INIT_G() do { \ 138#define INIT_G() do { \
141 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 139 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
@@ -806,7 +804,7 @@ static void reinitialize(void)
806 buffer_fill_and_print(); 804 buffer_fill_and_print();
807} 805}
808 806
809static ssize_t getch_nowait(void) 807static int getch_nowait(void)
810{ 808{
811 int rd; 809 int rd;
812 struct pollfd pfd[2]; 810 struct pollfd pfd[2];
@@ -839,7 +837,7 @@ static ssize_t getch_nowait(void)
839 move_cursor(max_displayed_line + 2, less_gets_pos + 1); 837 move_cursor(max_displayed_line + 2, less_gets_pos + 1);
840 fflush(stdout); 838 fflush(stdout);
841 839
842 if (kbd_input_size == 0) { 840 if (kbd_input[0] == 0) { /* if nothing is buffered */
843#if ENABLE_FEATURE_LESS_WINCH 841#if ENABLE_FEATURE_LESS_WINCH
844 while (1) { 842 while (1) {
845 int r; 843 int r;
@@ -856,7 +854,7 @@ static ssize_t getch_nowait(void)
856 854
857 /* We have kbd_fd in O_NONBLOCK mode, read inside read_key() 855 /* We have kbd_fd in O_NONBLOCK mode, read inside read_key()
858 * would not block even if there is no input available */ 856 * would not block even if there is no input available */
859 rd = read_key(kbd_fd, &kbd_input_size, kbd_input); 857 rd = read_key(kbd_fd, kbd_input);
860 if (rd == -1) { 858 if (rd == -1) {
861 if (errno == EAGAIN) { 859 if (errno == EAGAIN) {
862 /* No keyboard input available. Since poll() did return, 860 /* No keyboard input available. Since poll() did return,
@@ -872,9 +870,9 @@ static ssize_t getch_nowait(void)
872 return rd; 870 return rd;
873} 871}
874 872
875/* Grab a character from input without requiring the return key. If the 873/* Grab a character from input without requiring the return key.
876 * character is ASCII \033, get more characters and assign certain sequences 874 * May return KEYCODE_xxx values.
877 * special return codes. Note that this function works best with raw input. */ 875 * Note that this function works best with raw input. */
878static int less_getch(int pos) 876static int less_getch(int pos)
879{ 877{
880 int i; 878 int i;