Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /* $OpenBSD$ */  | 
2  |  |  | 
3  |  | /*  | 
4  |  |  * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>  | 
5  |  |  *  | 
6  |  |  * Permission to use, copy, modify, and distribute this software for any  | 
7  |  |  * purpose with or without fee is hereby granted, provided that the above  | 
8  |  |  * copyright notice and this permission notice appear in all copies.  | 
9  |  |  *  | 
10  |  |  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES  | 
11  |  |  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF  | 
12  |  |  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  | 
13  |  |  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES  | 
14  |  |  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER  | 
15  |  |  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING  | 
16  |  |  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.  | 
17  |  |  */  | 
18  |  |  | 
19  |  | #include <sys/types.h>  | 
20  |  |  | 
21  |  | #include <string.h>  | 
22  |  |  | 
23  |  | #include "tmux.h"  | 
24  |  |  | 
25  |  | /*  | 
26  |  |  * Grid view functions. These work using coordinates relative to the visible  | 
27  |  |  * screen area.  | 
28  |  |  */  | 
29  |  |  | 
30  | 2.37M  | #define grid_view_x(gd, x) (x)  | 
31  | 2.46M  | #define grid_view_y(gd, y) ((gd)->hsize + (y))  | 
32  |  |  | 
33  |  | /* Get cell. */  | 
34  |  | void  | 
35  |  | grid_view_get_cell(struct grid *gd, u_int px, u_int py, struct grid_cell *gc)  | 
36  | 14.0k  | { | 
37  | 14.0k  |   grid_get_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py), gc);  | 
38  | 14.0k  | }  | 
39  |  |  | 
40  |  | /* Set cell. */  | 
41  |  | void  | 
42  |  | grid_view_set_cell(struct grid *gd, u_int px, u_int py,  | 
43  |  |     const struct grid_cell *gc)  | 
44  | 2.33M  | { | 
45  | 2.33M  |   grid_set_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py), gc);  | 
46  | 2.33M  | }  | 
47  |  |  | 
48  |  | /* Set padding. */  | 
49  |  | void  | 
50  |  | grid_view_set_padding(struct grid *gd, u_int px, u_int py)  | 
51  | 0  | { | 
52  | 0  |   grid_set_padding(gd, grid_view_x(gd, px), grid_view_y(gd, py));  | 
53  | 0  | }  | 
54  |  |  | 
55  |  | /* Set cells. */  | 
56  |  | void  | 
57  |  | grid_view_set_cells(struct grid *gd, u_int px, u_int py,  | 
58  |  |     const struct grid_cell *gc, const char *s, size_t slen)  | 
59  | 7.85k  | { | 
60  | 7.85k  |   grid_set_cells(gd, grid_view_x(gd, px), grid_view_y(gd, py), gc, s,  | 
61  | 7.85k  |       slen);  | 
62  | 7.85k  | }  | 
63  |  |  | 
64  |  | /* Clear into history. */  | 
65  |  | void  | 
66  |  | grid_view_clear_history(struct grid *gd, u_int bg)  | 
67  | 0  | { | 
68  | 0  |   struct grid_line  *gl;  | 
69  | 0  |   u_int      yy, last;  | 
70  |  |  | 
71  |  |   /* Find the last used line. */  | 
72  | 0  |   last = 0;  | 
73  | 0  |   for (yy = 0; yy < gd->sy; yy++) { | 
74  | 0  |     gl = grid_get_line(gd, grid_view_y(gd, yy));  | 
75  | 0  |     if (gl->cellused != 0)  | 
76  | 0  |       last = yy + 1;  | 
77  | 0  |   }  | 
78  | 0  |   if (last == 0) { | 
79  | 0  |     grid_view_clear(gd, 0, 0, gd->sx, gd->sy, bg);  | 
80  | 0  |     return;  | 
81  | 0  |   }  | 
82  |  |  | 
83  |  |   /* Scroll the lines into the history. */  | 
84  | 0  |   for (yy = 0; yy < last; yy++) { | 
85  | 0  |     grid_collect_history(gd);  | 
86  | 0  |     grid_scroll_history(gd, bg);  | 
87  | 0  |   }  | 
88  | 0  |   if (last < gd->sy)  | 
89  | 0  |     grid_view_clear(gd, 0, 0, gd->sx, gd->sy - last, bg);  | 
90  | 0  |   gd->hscrolled = 0;  | 
91  | 0  | }  | 
92  |  |  | 
93  |  | /* Clear area. */  | 
94  |  | void  | 
95  |  | grid_view_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny,  | 
96  |  |     u_int bg)  | 
97  | 8.90k  | { | 
98  | 8.90k  |   px = grid_view_x(gd, px);  | 
99  | 8.90k  |   py = grid_view_y(gd, py);  | 
100  |  |  | 
101  | 8.90k  |   grid_clear(gd, px, py, nx, ny, bg);  | 
102  | 8.90k  | }  | 
103  |  |  | 
104  |  | /* Scroll region up. */  | 
105  |  | void  | 
106  |  | grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower,  | 
107  |  |     u_int bg)  | 
108  | 40.1k  | { | 
109  | 40.1k  |   if (gd->flags & GRID_HISTORY) { | 
110  | 0  |     grid_collect_history(gd);  | 
111  | 0  |     if (rupper == 0 && rlower == gd->sy - 1)  | 
112  | 0  |       grid_scroll_history(gd, bg);  | 
113  | 0  |     else { | 
114  | 0  |       rupper = grid_view_y(gd, rupper);  | 
115  | 0  |       rlower = grid_view_y(gd, rlower);  | 
116  | 0  |       grid_scroll_history_region(gd, rupper, rlower, bg);  | 
117  | 0  |     }  | 
118  | 40.1k  |   } else { | 
119  | 40.1k  |     rupper = grid_view_y(gd, rupper);  | 
120  | 40.1k  |     rlower = grid_view_y(gd, rlower);  | 
121  | 40.1k  |     grid_move_lines(gd, rupper, rupper + 1, rlower - rupper, bg);  | 
122  | 40.1k  |   }  | 
123  | 40.1k  | }  | 
124  |  |  | 
125  |  | /* Scroll region down. */  | 
126  |  | void  | 
127  |  | grid_view_scroll_region_down(struct grid *gd, u_int rupper, u_int rlower,  | 
128  |  |     u_int bg)  | 
129  | 3.85k  | { | 
130  | 3.85k  |   rupper = grid_view_y(gd, rupper);  | 
131  | 3.85k  |   rlower = grid_view_y(gd, rlower);  | 
132  |  |  | 
133  | 3.85k  |   grid_move_lines(gd, rupper + 1, rupper, rlower - rupper, bg);  | 
134  | 3.85k  | }  | 
135  |  |  | 
136  |  | /* Insert lines. */  | 
137  |  | void  | 
138  |  | grid_view_insert_lines(struct grid *gd, u_int py, u_int ny, u_int bg)  | 
139  | 496  | { | 
140  | 496  |   u_int sy;  | 
141  |  |  | 
142  | 496  |   py = grid_view_y(gd, py);  | 
143  |  |  | 
144  | 496  |   sy = grid_view_y(gd, gd->sy);  | 
145  |  |  | 
146  | 496  |   grid_move_lines(gd, py + ny, py, sy - py - ny, bg);  | 
147  | 496  | }  | 
148  |  |  | 
149  |  | /* Insert lines in region. */  | 
150  |  | void  | 
151  |  | grid_view_insert_lines_region(struct grid *gd, u_int rlower, u_int py,  | 
152  |  |     u_int ny, u_int bg)  | 
153  | 994  | { | 
154  | 994  |   u_int ny2;  | 
155  |  |  | 
156  | 994  |   rlower = grid_view_y(gd, rlower);  | 
157  |  |  | 
158  | 994  |   py = grid_view_y(gd, py);  | 
159  |  |  | 
160  | 994  |   ny2 = rlower + 1 - py - ny;  | 
161  | 994  |   grid_move_lines(gd, rlower + 1 - ny2, py, ny2, bg);  | 
162  | 994  |   grid_clear(gd, 0, py + ny2, gd->sx, ny - ny2, bg);  | 
163  | 994  | }  | 
164  |  |  | 
165  |  | /* Delete lines. */  | 
166  |  | void  | 
167  |  | grid_view_delete_lines(struct grid *gd, u_int py, u_int ny, u_int bg)  | 
168  | 493  | { | 
169  | 493  |   u_int sy;  | 
170  |  |  | 
171  | 493  |   py = grid_view_y(gd, py);  | 
172  |  |  | 
173  | 493  |   sy = grid_view_y(gd, gd->sy);  | 
174  |  |  | 
175  | 493  |   grid_move_lines(gd, py, py + ny, sy - py - ny, bg);  | 
176  | 493  |   grid_clear(gd, 0, sy - ny, gd->sx, py + ny - (sy - ny), bg);  | 
177  | 493  | }  | 
178  |  |  | 
179  |  | /* Delete lines inside scroll region. */  | 
180  |  | void  | 
181  |  | grid_view_delete_lines_region(struct grid *gd, u_int rlower, u_int py,  | 
182  |  |     u_int ny, u_int bg)  | 
183  | 1.25k  | { | 
184  | 1.25k  |   u_int ny2;  | 
185  |  |  | 
186  | 1.25k  |   rlower = grid_view_y(gd, rlower);  | 
187  |  |  | 
188  | 1.25k  |   py = grid_view_y(gd, py);  | 
189  |  |  | 
190  | 1.25k  |   ny2 = rlower + 1 - py - ny;  | 
191  | 1.25k  |   grid_move_lines(gd, py, py + ny, ny2, bg);  | 
192  | 1.25k  |   grid_clear(gd, 0, py + ny2, gd->sx, ny - ny2, bg);  | 
193  | 1.25k  | }  | 
194  |  |  | 
195  |  | /* Insert characters. */  | 
196  |  | void  | 
197  |  | grid_view_insert_cells(struct grid *gd, u_int px, u_int py, u_int nx, u_int bg)  | 
198  | 3.30k  | { | 
199  | 3.30k  |   u_int sx;  | 
200  |  |  | 
201  | 3.30k  |   px = grid_view_x(gd, px);  | 
202  | 3.30k  |   py = grid_view_y(gd, py);  | 
203  |  |  | 
204  | 3.30k  |   sx = grid_view_x(gd, gd->sx);  | 
205  |  |  | 
206  | 3.30k  |   if (px >= sx - 1)  | 
207  | 590  |     grid_clear(gd, px, py, 1, 1, bg);  | 
208  | 2.71k  |   else  | 
209  | 2.71k  |     grid_move_cells(gd, px + nx, px, py, sx - px - nx, bg);  | 
210  | 3.30k  | }  | 
211  |  |  | 
212  |  | /* Delete characters. */  | 
213  |  | void  | 
214  |  | grid_view_delete_cells(struct grid *gd, u_int px, u_int py, u_int nx, u_int bg)  | 
215  | 1.29k  | { | 
216  | 1.29k  |   u_int sx;  | 
217  |  |  | 
218  | 1.29k  |   px = grid_view_x(gd, px);  | 
219  | 1.29k  |   py = grid_view_y(gd, py);  | 
220  |  |  | 
221  | 1.29k  |   sx = grid_view_x(gd, gd->sx);  | 
222  |  |  | 
223  | 1.29k  |   grid_move_cells(gd, px, px + nx, py, sx - px - nx, bg);  | 
224  | 1.29k  |   grid_clear(gd, sx - nx, py, px + nx - (sx - nx), 1, bg);  | 
225  | 1.29k  | }  | 
226  |  |  | 
227  |  | /* Convert cells into a string. */  | 
228  |  | char *  | 
229  |  | grid_view_string_cells(struct grid *gd, u_int px, u_int py, u_int nx)  | 
230  | 0  | { | 
231  | 0  |   px = grid_view_x(gd, px);  | 
232  | 0  |   py = grid_view_y(gd, py);  | 
233  |  | 
  | 
234  | 0  |   return (grid_string_cells(gd, px, py, nx, NULL, 0, NULL));  | 
235  | 0  | }  |