output.c (a5f0fb151d90effe79714de0fa059954725fe57f) | output.c (c9346414d95d69f958210e825deb3b086dac3529) |
---|---|
1/* 2 * Copyright (C) 1984-2000 Mark Nudelman 3 * 4 * You may distribute under the terms of either the GNU General Public 5 * License or the Less License, as specified in the README file. 6 * 7 * For more information about less, or for information on how to 8 * contact the author, see the README file. --- 111 unchanged lines hidden (view full) --- 120 register int fd; 121 122 n = ob - obuf; 123 if (n == 0) 124 return; 125#if MSDOS_COMPILER==WIN32C 126 if (is_tty && any_display) 127 { | 1/* 2 * Copyright (C) 1984-2000 Mark Nudelman 3 * 4 * You may distribute under the terms of either the GNU General Public 5 * License or the Less License, as specified in the README file. 6 * 7 * For more information about less, or for information on how to 8 * contact the author, see the README file. --- 111 unchanged lines hidden (view full) --- 120 register int fd; 121 122 n = ob - obuf; 123 if (n == 0) 124 return; 125#if MSDOS_COMPILER==WIN32C 126 if (is_tty && any_display) 127 { |
128 char *p; | |
129 char *op; 130 DWORD nwritten = 0; 131 CONSOLE_SCREEN_BUFFER_INFO scr; | 128 char *op; 129 DWORD nwritten = 0; 130 CONSOLE_SCREEN_BUFFER_INFO scr; |
132 DWORD nchars; 133 COORD cpos; 134 WORD nm_attr; | 131 int row; 132 int col; |
135 int olen; 136 extern HANDLE con_out; | 133 int olen; 134 extern HANDLE con_out; |
137 extern int nm_fg_color; 138 extern int nm_bg_color; 139#define MAKEATTR(fg,bg) ((WORD)((fg)|((bg)<<4))) | |
140 | 135 |
141 *ob = '\0'; | |
142 olen = ob - obuf; 143 /* | 136 olen = ob - obuf; 137 /* |
144 * To avoid color problems, if we're scrolling the screen, 145 * we write only up to the char that causes the scroll, 146 * (a newline or a char in the last column), then fill 147 * the bottom line with the "normal" attribute, then 148 * write the rest. 149 * When Windows scrolls, it takes the attributes for the 150 * new line from the first char of the (previously) 151 * bottom line. 152 * 153 * {{ This still doesn't work correctly in all cases! }} | 138 * There is a bug in Win32 WriteConsole() if we're 139 * writing in the last cell with a different color. 140 * To avoid color problems in the bottom line, 141 * we scroll the screen manually, before writing. |
154 */ | 142 */ |
155 nm_attr = MAKEATTR(nm_fg_color, nm_bg_color); 156 for (op = obuf; *op != '\0'; ) | 143 GetConsoleScreenBufferInfo(con_out, &scr); 144 col = scr.dwCursorPosition.X; 145 row = scr.dwCursorPosition.Y; 146 for (op = obuf; op < obuf + olen; op++) |
157 { | 147 { |
158 GetConsoleScreenBufferInfo(con_out, &scr); 159 /* Find the next newline. */ 160 p = strchr(op, '\n'); 161 if (p == NULL && 162 scr.dwCursorPosition.X + olen >= sc_width) | 148 if (*op == '\n') |
163 { | 149 { |
164 /* 165 * No newline, but writing in the 166 * last column causes scrolling. 167 */ 168 p = op + sc_width - scr.dwCursorPosition.X - 1; 169 } 170 if (scr.dwCursorPosition.Y != scr.srWindow.Bottom || 171 p == NULL) 172 { 173 /* Write the entire buffer. */ 174 WriteConsole(con_out, op, olen, 175 &nwritten, NULL); 176 op += olen; | 150 col = 0; 151 row++; |
177 } else 178 { | 152 } else 153 { |
179 /* Write only up to the scrolling char. */ 180 WriteConsole(con_out, op, p - op + 1, 181 &nwritten, NULL); 182 cpos.X = 0; 183 cpos.Y = scr.dwCursorPosition.Y; 184 FillConsoleOutputAttribute(con_out, nm_attr, 185 sc_width, cpos, &nchars); 186 olen -= p - op + 1; 187 op = p + 1; | 154 col++; 155 if (col >= sc_width) 156 { 157 col = 0; 158 row++; 159 } |
188 } 189 } | 160 } 161 } |
162 if (row > scr.srWindow.Bottom) 163 win32_scroll_up(row - scr.srWindow.Bottom); 164 WriteConsole(con_out, obuf, olen, &nwritten, NULL); |
|
190 ob = obuf; 191 return; 192 } 193#else 194#if MSDOS_COMPILER==MSOFTC 195 if (is_tty && any_display) 196 { 197 *ob = '\0'; --- 71 unchanged lines hidden (view full) --- 269 static int 270iprintnum(num, radix) 271 int num; 272 int radix; 273{ 274 register char *s; 275 int r; 276 int neg; | 165 ob = obuf; 166 return; 167 } 168#else 169#if MSDOS_COMPILER==MSOFTC 170 if (is_tty && any_display) 171 { 172 *ob = '\0'; --- 71 unchanged lines hidden (view full) --- 244 static int 245iprintnum(num, radix) 246 int num; 247 int radix; 248{ 249 register char *s; 250 int r; 251 int neg; |
277 char buf[10]; | 252 char buf[INT_STRLEN_BOUND(num)]; |
278 279 neg = (num < 0); 280 if (neg) 281 num = -num; 282 283 s = buf; 284 do 285 { --- 176 unchanged lines hidden --- | 253 254 neg = (num < 0); 255 if (neg) 256 num = -num; 257 258 s = buf; 259 do 260 { --- 176 unchanged lines hidden --- |