aboutsummaryrefslogtreecommitdiff
path: root/miscutils/less.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2017-09-27 10:08:12 +0100
committerRon Yorston <rmy@pobox.com>2017-09-27 10:11:19 +0100
commitd9383e984da8de72e61e5094a3cf6404c5707ddc (patch)
treedd42825854fc42aea40d4f7a95548d53721d1733 /miscutils/less.c
parent166b3e4e82799f87d3b002c7177891111eff079e (diff)
parent0c4dbd481aedb5d22c1048e7f7eb547a3b5e50a5 (diff)
downloadbusybox-w32-d9383e984da8de72e61e5094a3cf6404c5707ddc.tar.gz
busybox-w32-d9383e984da8de72e61e5094a3cf6404c5707ddc.tar.bz2
busybox-w32-d9383e984da8de72e61e5094a3cf6404c5707ddc.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'miscutils/less.c')
-rw-r--r--miscutils/less.c28
1 files changed, 10 insertions, 18 deletions
diff --git a/miscutils/less.c b/miscutils/less.c
index 8a5b9ff0b..4ab0e17da 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -6,7 +6,6 @@
6 * 6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */ 8 */
9
10/* 9/*
11 * TODO: 10 * TODO:
12 * - Add more regular expression support - search modifiers, certain matches, etc. 11 * - Add more regular expression support - search modifiers, certain matches, etc.
@@ -20,7 +19,6 @@
20 * - the inp file pointer is used so that keyboard input works after 19 * - the inp file pointer is used so that keyboard input works after
21 * redirected input has been read from stdin 20 * redirected input has been read from stdin
22 */ 21 */
23
24//config:config LESS 22//config:config LESS
25//config: bool "less (15 kb)" 23//config: bool "less (15 kb)"
26//config: default y 24//config: default y
@@ -141,9 +139,9 @@
141#define ESC "\033" 139#define ESC "\033"
142/* The escape codes for highlighted and normal text */ 140/* The escape codes for highlighted and normal text */
143#define HIGHLIGHT ESC"[7m" 141#define HIGHLIGHT ESC"[7m"
144#define NORMAL ESC"[0m" 142#define NORMAL ESC"[m"
145/* The escape code to home and clear to the end of screen */ 143/* The escape code to home and clear to the end of screen */
146#define CLEAR ESC"[H\033[J" 144#define CLEAR ESC"[H"ESC"[J"
147/* The escape code to clear to the end of line */ 145/* The escape code to clear to the end of line */
148#define CLEAR_2_EOL ESC"[K" 146#define CLEAR_2_EOL ESC"[K"
149 147
@@ -285,9 +283,9 @@ static void set_tty_cooked(void)
285 283
286/* Move the cursor to a position (x,y), where (0,0) is the 284/* Move the cursor to a position (x,y), where (0,0) is the
287 top-left corner of the console */ 285 top-left corner of the console */
288static void move_cursor(int line, int row) 286static void move_cursor(int line, int col)
289{ 287{
290 printf(ESC"[%u;%uH", line, row); 288 printf(ESC"[%u;%uH", line, col);
291} 289}
292 290
293static void clear_line(void) 291static void clear_line(void)
@@ -1070,7 +1068,7 @@ static void reinitialize(void)
1070 open_file_and_read_lines(); 1068 open_file_and_read_lines();
1071#if ENABLE_FEATURE_LESS_ASK_TERMINAL 1069#if ENABLE_FEATURE_LESS_ASK_TERMINAL
1072 if (G.winsize_err) 1070 if (G.winsize_err)
1073 printf("\033[999;999H" "\033[6n"); 1071 printf(ESC"[999;999H" ESC"[6n");
1074#endif 1072#endif
1075#if ENABLE_PLATFORM_MINGW32 1073#if ENABLE_PLATFORM_MINGW32
1076 reset_screen(); 1074 reset_screen();
@@ -1135,7 +1133,7 @@ static int64_t getch_nowait(void)
1135 goto again; 1133 goto again;
1136 } 1134 }
1137 /* EOF/error (ssh session got killed etc) */ 1135 /* EOF/error (ssh session got killed etc) */
1138 less_exit(0); 1136 less_exit(EXIT_SUCCESS);
1139 } 1137 }
1140 set_tty_cooked(); 1138 set_tty_cooked();
1141 return key64; 1139 return key64;
@@ -1839,8 +1837,8 @@ int less_main(int argc, char **argv)
1839{ 1837{
1840#if !ENABLE_PLATFORM_MINGW32 1838#if !ENABLE_PLATFORM_MINGW32
1841 char *tty_name; 1839 char *tty_name;
1842 int tty_fd;
1843#endif 1840#endif
1841 int tty_fd;
1844 1842
1845 INIT_G(); 1843 INIT_G();
1846 1844
@@ -1901,18 +1899,12 @@ int less_main(int argc, char **argv)
1901 G.kbd_fd_orig_flags = ndelay_on(tty_fd); 1899 G.kbd_fd_orig_flags = ndelay_on(tty_fd);
1902 kbd_fd = tty_fd; /* save in a global */ 1900 kbd_fd = tty_fd; /* save in a global */
1903#else 1901#else
1904 kbd_fd = 0; 1902 kbd_fd = tty_fd = 0;
1905#endif 1903#endif
1906 1904
1907 tcgetattr(kbd_fd, &term_orig); 1905 get_termios_and_make_raw(tty_fd, &term_less, &term_orig, TERMIOS_RAW_CRNL);
1908 term_less = term_orig;
1909 term_less.c_lflag &= ~(ICANON | ECHO);
1910 term_less.c_iflag &= ~(IXON | ICRNL);
1911 /*term_less.c_oflag &= ~ONLCR;*/
1912 term_less.c_cc[VMIN] = 1;
1913 term_less.c_cc[VTIME] = 0;
1914 1906
1915 IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(kbd_fd, &width, &max_displayed_line); 1907 IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(tty_fd, &width, &max_displayed_line);
1916 /* 20: two tabstops + 4 */ 1908 /* 20: two tabstops + 4 */
1917 if (width < 20 || max_displayed_line < 3) 1909 if (width < 20 || max_displayed_line < 3)
1918 return bb_cat(argv); 1910 return bb_cat(argv);