Coverage Report

Created: 2026-10-17 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tmux/style.c
Line
Count
Source
1
/* $OpenBSD: style.c,v 1.48 2026/10/16 07:59:06 nicm Exp $ */
2
3
/*
4
 * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
5
 * Copyright (c) 2014 Tiago Cunha <tcunha@users.sourceforge.net>
6
 *
7
 * Permission to use, copy, modify, and distribute this software for any
8
 * purpose with or without fee is hereby granted, provided that the above
9
 * copyright notice and this permission notice appear in all copies.
10
 *
11
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15
 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
16
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
17
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
 */
19
20
#include <sys/types.h>
21
22
#include <ctype.h>
23
#include <stdlib.h>
24
#include <string.h>
25
26
#include "tmux.h"
27
28
/* Mask for bits not included in style. */
29
#define STYLE_ATTR_MASK (~0)
30
31
/* Default style. */
32
static struct style style_default = {
33
  { { { ' ' }, 0, 1, 1 }, 0, 0, 8, 8, 0, 0 },
34
  0,
35
  0,
36
37
  8,
38
  STYLE_ALIGN_DEFAULT,
39
  STYLE_LIST_OFF,
40
41
  STYLE_RANGE_NONE, 0, "",
42
43
  STYLE_WIDTH_DEFAULT, 0, STYLE_PAD_DEFAULT,
44
  0,
45
  0,
46
47
  STYLE_DEFAULT_BASE
48
};
49
50
/*
51
 * Global hyperlink set holding the URIs for #[link=...] styles, so a style
52
 * only needs to store a small ID rather than the URI itself.
53
 */
54
static struct hyperlinks  *style_hyperlinks;
55
56
/* Set range string. */
57
static void
58
style_set_range_string(struct style *sy, const char *s)
59
8.35k
{
60
8.35k
  strlcpy(sy->range_string, s, sizeof sy->range_string);
61
8.35k
}
62
63
/*
64
 * Parse an embedded style of the form "fg=colour,bg=colour,bright,...".  Note
65
 * that this adds onto the given style, so it must have been initialized
66
 * already.
67
 */
68
int
69
style_parse(struct style *sy, const struct grid_cell *base, const char *in)
70
1.32M
{
71
1.32M
  struct style  saved;
72
1.32M
  const char  delimiters[] = " ,\n", *errstr;
73
1.32M
  char    tmp[256], *found;
74
1.32M
  int   value;
75
1.32M
  size_t    end;
76
1.32M
  u_int   n;
77
78
1.32M
  if (*in == '\0')
79
9.82k
    return (0);
80
1.31M
  style_copy(&saved, sy);
81
82
1.31M
  log_debug("%s: %s", __func__, in);
83
1.62M
  do {
84
1.86M
    while (*in != '\0' && strchr(delimiters, *in) != NULL)
85
239k
      in++;
86
1.62M
    if (*in == '\0')
87
740
      break;
88
89
1.62M
    end = strcspn(in, delimiters);
90
1.62M
    if (end > (sizeof tmp) - 1)
91
1.13k
      goto error;
92
1.62M
    memcpy(tmp, in, end);
93
1.62M
    tmp[end] = '\0';
94
95
1.62M
    log_debug("%s: %s", __func__, tmp);
96
1.62M
    if (strcasecmp(tmp, "default") == 0) {
97
19.7k
      sy->gc.fg = base->fg;
98
19.7k
      sy->gc.bg = base->bg;
99
19.7k
      sy->gc.us = base->us;
100
19.7k
      sy->gc.attr = base->attr;
101
19.7k
      sy->gc.flags = base->flags;
102
19.7k
      sy->link = 0;
103
1.60M
    } else if (strcasecmp(tmp, "ignore") == 0)
104
548
      sy->ignore = 1;
105
1.60M
    else if (strcasecmp(tmp, "noignore") == 0)
106
564
      sy->ignore = 0;
107
1.60M
    else if (strcasecmp(tmp, "push-default") == 0)
108
15.5k
      sy->default_type = STYLE_DEFAULT_PUSH;
109
1.58M
    else if (strcasecmp(tmp, "pop-default") == 0)
110
15.5k
      sy->default_type = STYLE_DEFAULT_POP;
111
1.57M
    else if (strcasecmp(tmp, "set-default") == 0)
112
17.7k
      sy->default_type = STYLE_DEFAULT_SET;
113
1.55M
    else if (strcasecmp(tmp, "nl") == 0)
114
7
      sy->nl = 1;
115
1.55M
    else if (strcasecmp(tmp, "nolist") == 0)
116
2.14k
      sy->list = STYLE_LIST_OFF;
117
1.55M
    else if (strncasecmp(tmp, "list=", 5) == 0) {
118
84.7k
      if (strcasecmp(tmp + 5, "on") == 0)
119
21.3k
        sy->list = STYLE_LIST_ON;
120
63.4k
      else if (strcasecmp(tmp + 5, "focus") == 0)
121
472
        sy->list = STYLE_LIST_FOCUS;
122
62.9k
      else if (strcasecmp(tmp + 5, "left-marker") == 0)
123
5.84k
        sy->list = STYLE_LIST_LEFT_MARKER;
124
57.1k
      else if (strcasecmp(tmp + 5, "right-marker") == 0)
125
5.84k
        sy->list = STYLE_LIST_RIGHT_MARKER;
126
51.2k
      else
127
51.2k
        goto error;
128
1.46M
    } else if (strcasecmp(tmp, "norange") == 0) {
129
20.2k
      sy->range_type = style_default.range_type;
130
20.2k
      sy->range_argument = style_default.range_type;
131
20.2k
      strlcpy(sy->range_string, style_default.range_string,
132
20.2k
          sizeof sy->range_string);
133
1.44M
    } else if (end > 6 && strncasecmp(tmp, "range=", 6) == 0) {
134
50.6k
      found = strchr(tmp + 6, '|');
135
50.6k
      if (found != NULL) {
136
39.2k
        *found++ = '\0';
137
39.2k
        if (*found == '\0')
138
514
          goto error;
139
39.2k
      }
140
50.1k
      if (strcasecmp(tmp + 6, "left") == 0) {
141
2.52k
        if (found != NULL)
142
515
          goto error;
143
2.01k
        sy->range_type = STYLE_RANGE_LEFT;
144
2.01k
        sy->range_argument = 0;
145
2.01k
        style_set_range_string(sy, "");
146
47.6k
      } else if (strcasecmp(tmp + 6, "right") == 0) {
147
2.49k
        if (found != NULL)
148
496
          goto error;
149
1.99k
        sy->range_type = STYLE_RANGE_RIGHT;
150
1.99k
        sy->range_argument = 0;
151
1.99k
        style_set_range_string(sy, "");
152
45.1k
      } else if (strcasecmp(tmp + 6, "control") == 0) {
153
2.28k
        if (found == NULL)
154
525
          goto error;
155
1.76k
        n = strtonum(found, 0, 9, &errstr);
156
1.76k
        if (errstr != NULL)
157
413
          goto error;
158
1.34k
        sy->range_type = STYLE_RANGE_CONTROL;
159
1.34k
        sy->range_argument = n;
160
1.34k
        style_set_range_string(sy, "");
161
42.8k
      } else if (strcasecmp(tmp + 6, "pane") == 0) {
162
5.94k
        if (found == NULL)
163
397
          goto error;
164
5.54k
        if (*found != '%' || found[1] == '\0')
165
4.27k
          goto error;
166
1.26k
        n = strtonum(found + 1, 0, UINT_MAX, &errstr);
167
1.26k
        if (errstr != NULL)
168
558
          goto error;
169
710
        sy->range_type = STYLE_RANGE_PANE;
170
710
        sy->range_argument = n;
171
710
        style_set_range_string(sy, "");
172
36.8k
      } else if (strcasecmp(tmp + 6, "window") == 0) {
173
5.31k
        if (found == NULL)
174
497
          goto error;
175
4.81k
        n = strtonum(found, 0, UINT_MAX, &errstr);
176
4.81k
        if (errstr != NULL)
177
4.08k
          goto error;
178
726
        sy->range_type = STYLE_RANGE_WINDOW;
179
726
        sy->range_argument = n;
180
726
        style_set_range_string(sy, "");
181
31.5k
      } else if (strcasecmp(tmp + 6, "session") == 0) {
182
5.79k
        if (found == NULL)
183
496
          goto error;
184
5.29k
        if (*found != '$' || found[1] == '\0')
185
4.33k
          goto error;
186
966
        n = strtonum(found + 1, 0, UINT_MAX, &errstr);
187
966
        if (errstr != NULL)
188
406
          goto error;
189
560
        sy->range_type = STYLE_RANGE_SESSION;
190
560
        sy->range_argument = n;
191
560
        style_set_range_string(sy, "");
192
25.7k
      } else if (strcasecmp(tmp + 6, "user") == 0) {
193
1.55k
        if (found == NULL)
194
554
          goto error;
195
997
        sy->range_type = STYLE_RANGE_USER;
196
997
        sy->range_argument = 0;
197
997
        style_set_range_string(sy, found);
198
997
      }
199
1.39M
    } else if (strcasecmp(tmp, "noalign") == 0)
200
659
      sy->align = style_default.align;
201
1.39M
    else if (end > 6 && strncasecmp(tmp, "align=", 6) == 0) {
202
28.1k
      if (strcasecmp(tmp + 6, "left") == 0)
203
5.90k
        sy->align = STYLE_ALIGN_LEFT;
204
22.2k
      else if (strcasecmp(tmp + 6, "centre") == 0)
205
1.47k
        sy->align = STYLE_ALIGN_CENTRE;
206
20.8k
      else if (strcasecmp(tmp + 6, "right") == 0)
207
2.87k
        sy->align = STYLE_ALIGN_RIGHT;
208
17.9k
      else if (strcasecmp(tmp + 6, "absolute-centre") == 0)
209
2.40k
        sy->align = STYLE_ALIGN_ABSOLUTE_CENTRE;
210
15.5k
      else
211
15.5k
        goto error;
212
1.36M
    } else if (end > 5 && strncasecmp(tmp, "fill=", 5) == 0) {
213
17.4k
      if ((value = colour_fromstring(tmp + 5)) == -1)
214
16.6k
        goto error;
215
741
      sy->fill = value;
216
1.35M
    } else if (end > 4 && strncasecmp(tmp, "dim=", 4) == 0) {
217
2.49k
      if (tmp[end - 1] == '%')
218
755
        tmp[end - 1] = '\0';
219
2.49k
      n = strtonum(tmp + 4, 0, 100, &errstr);
220
2.49k
      if (errstr != NULL)
221
1.96k
        goto error;
222
534
      sy->dim = n;
223
1.34M
    } else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) {
224
132k
      if ((value = colour_fromstring(tmp + 3)) == -1)
225
5.69k
        goto error;
226
127k
      if (*in == 'f' || *in == 'F') {
227
59.2k
        if (value != 8)
228
58.6k
          sy->gc.fg = value;
229
606
        else
230
606
          sy->gc.fg = base->fg;
231
67.7k
      } else if (*in == 'b' || *in == 'B') {
232
66.9k
        if (value != 8)
233
66.1k
          sy->gc.bg = value;
234
705
        else
235
705
          sy->gc.bg = base->bg;
236
66.9k
      } else
237
835
        goto error;
238
1.21M
    } else if (end > 3 && strncasecmp(tmp, "us=", 3) == 0) {
239
10.6k
      if ((value = colour_fromstring(tmp + 3)) == -1)
240
992
        goto error;
241
9.66k
      if (value != 8)
242
8.90k
        sy->gc.us = value;
243
762
      else
244
762
        sy->gc.us = base->us;
245
1.20M
    } else if (strcasecmp(tmp, "none") == 0)
246
4.05k
      sy->gc.attr = 0;
247
1.20M
    else if (end > 2 && strncasecmp(tmp, "no", 2) == 0) {
248
61.2k
      if (strcmp(tmp + 2, "link") == 0)
249
543
        sy->link = 0;
250
60.7k
      else if (strcmp(tmp + 2, "attr") == 0)
251
471
        sy->gc.attr |= GRID_ATTR_NOATTR;
252
60.2k
      else {
253
60.2k
        value = attributes_fromstring(tmp + 2);
254
60.2k
        if (value == -1)
255
59.0k
          goto error;
256
1.24k
        sy->gc.attr &= ~value;
257
1.24k
      }
258
1.13M
    } else if (end > 6 && strncasecmp(tmp, "width=", 6) == 0) {
259
129k
      if (end > 7 && tmp[end - 1] == '%') {
260
3.68k
        tmp[end - 1] = '\0';
261
3.68k
        n = strtonum(tmp + 6, 0, 100, &errstr);
262
3.68k
        if (errstr != NULL)
263
2.00k
          goto error;
264
1.68k
        sy->width = (int)n;
265
1.68k
        sy->width_percentage = 1;
266
126k
      } else {
267
126k
        n = strtonum(tmp + 6, 0, UINT_MAX, &errstr);
268
126k
        if (errstr != NULL)
269
70.2k
          goto error;
270
55.8k
        sy->width = (int)n;
271
55.8k
        sy->width_percentage = 0;
272
55.8k
      }
273
1.00M
    } else if (end > 4 && strncasecmp(tmp, "pad=", 4) == 0) {
274
56.2k
      n = strtonum(tmp + 4, 0, UINT_MAX, &errstr);
275
56.2k
      if (errstr != NULL)
276
885
        goto error;
277
55.3k
      sy->pad = (int)n;
278
953k
    } else if (strncasecmp(tmp, "link=", 5) == 0) {
279
614k
      if (tmp[5] == '\0')
280
2.18k
        sy->link = 0;
281
611k
      else {
282
611k
        if (style_hyperlinks == NULL)
283
3
          style_hyperlinks = hyperlinks_init();
284
611k
        sy->link = hyperlinks_put(style_hyperlinks,
285
611k
            tmp + 5, tmp + 5);
286
611k
      }
287
614k
    } else {
288
339k
      if ((value = attributes_fromstring(tmp)) == -1)
289
337k
        goto error;
290
2.17k
      sy->gc.attr |= value;
291
2.17k
    }
292
293
1.04M
    in += end + strspn(in + end, delimiters);
294
1.04M
  } while (*in != '\0');
295
296
733k
  return (0);
297
298
581k
error:
299
581k
  style_copy(sy, &saved);
300
581k
  return (-1);
301
1.31M
}
302
303
/* Convert style to a string. */
304
const char *
305
style_tostring(struct style *sy)
306
0
{
307
0
  struct grid_cell  *gc = &sy->gc;
308
0
  int      off = 0;
309
0
  const char    *comma = "", *tmp = "", *uri;
310
0
  static char    s[2048];
311
0
  char       b[21];
312
313
0
  *s = '\0';
314
315
0
  if (sy->list != STYLE_LIST_OFF) {
316
0
    if (sy->list == STYLE_LIST_ON)
317
0
      tmp = "on";
318
0
    else if (sy->list == STYLE_LIST_FOCUS)
319
0
      tmp = "focus";
320
0
    else if (sy->list == STYLE_LIST_LEFT_MARKER)
321
0
      tmp = "left-marker";
322
0
    else if (sy->list == STYLE_LIST_RIGHT_MARKER)
323
0
      tmp = "right-marker";
324
0
    off += xsnprintf(s + off, sizeof s - off, "%slist=%s", comma,
325
0
        tmp);
326
0
    comma = ",";
327
0
  }
328
0
  if (sy->range_type != STYLE_RANGE_NONE) {
329
0
    if (sy->range_type == STYLE_RANGE_LEFT)
330
0
      tmp = "left";
331
0
    else if (sy->range_type == STYLE_RANGE_RIGHT)
332
0
      tmp = "right";
333
0
    else if (sy->range_type == STYLE_RANGE_PANE) {
334
0
      snprintf(b, sizeof b, "pane|%%%u", sy->range_argument);
335
0
      tmp = b;
336
0
    } else if (sy->range_type == STYLE_RANGE_WINDOW) {
337
0
      snprintf(b, sizeof b, "window|%u", sy->range_argument);
338
0
      tmp = b;
339
0
    } else if (sy->range_type == STYLE_RANGE_SESSION) {
340
0
      snprintf(b, sizeof b, "session|$%u",
341
0
          sy->range_argument);
342
0
      tmp = b;
343
0
    } else if (sy->range_type == STYLE_RANGE_USER) {
344
0
      snprintf(b, sizeof b, "user|%s", sy->range_string);
345
0
      tmp = b;
346
0
    }
347
0
    off += xsnprintf(s + off, sizeof s - off, "%srange=%s", comma,
348
0
        tmp);
349
0
    comma = ",";
350
0
  }
351
0
  if (sy->align != STYLE_ALIGN_DEFAULT) {
352
0
    if (sy->align == STYLE_ALIGN_LEFT)
353
0
      tmp = "left";
354
0
    else if (sy->align == STYLE_ALIGN_CENTRE)
355
0
      tmp = "centre";
356
0
    else if (sy->align == STYLE_ALIGN_RIGHT)
357
0
      tmp = "right";
358
0
    else if (sy->align == STYLE_ALIGN_ABSOLUTE_CENTRE)
359
0
      tmp = "absolute-centre";
360
0
    off += xsnprintf(s + off, sizeof s - off, "%salign=%s", comma,
361
0
        tmp);
362
0
    comma = ",";
363
0
  }
364
0
  if (sy->default_type != STYLE_DEFAULT_BASE) {
365
0
    if (sy->default_type == STYLE_DEFAULT_PUSH)
366
0
      tmp = "push-default";
367
0
    else if (sy->default_type == STYLE_DEFAULT_POP)
368
0
      tmp = "pop-default";
369
0
    else if (sy->default_type == STYLE_DEFAULT_SET)
370
0
      tmp = "set-default";
371
0
    off += xsnprintf(s + off, sizeof s - off, "%s%s", comma, tmp);
372
0
    comma = ",";
373
0
  }
374
0
  if (sy->fill != 8) {
375
0
    off += xsnprintf(s + off, sizeof s - off, "%sfill=%s", comma,
376
0
        colour_tostring(sy->fill));
377
0
    comma = ",";
378
0
  }
379
0
  if (sy->dim != 0) {
380
0
    off += xsnprintf(s + off, sizeof s - off, "%sdim=%d%%", comma,
381
0
        sy->dim);
382
0
    comma = ",";
383
0
  }
384
0
  if (gc->fg != 8) {
385
0
    off += xsnprintf(s + off, sizeof s - off, "%sfg=%s", comma,
386
0
        colour_tostring(gc->fg));
387
0
    comma = ",";
388
0
  }
389
0
  if (gc->bg != 8) {
390
0
    off += xsnprintf(s + off, sizeof s - off, "%sbg=%s", comma,
391
0
        colour_tostring(gc->bg));
392
0
    comma = ",";
393
0
  }
394
0
  if (gc->us != 8) {
395
0
    off += xsnprintf(s + off, sizeof s - off, "%sus=%s", comma,
396
0
        colour_tostring(gc->us));
397
0
    comma = ",";
398
0
  }
399
0
  if (gc->attr != 0) {
400
0
    off += xsnprintf(s + off, sizeof s - off, "%s%s", comma,
401
0
        attributes_tostring(gc->attr));
402
0
    comma = ",";
403
0
  }
404
0
  if (sy->width >= 0) {
405
0
    if (sy->width_percentage)
406
0
      off += xsnprintf(s + off, sizeof s - off,
407
0
          "%swidth=%u%%", comma, sy->width);
408
0
    else
409
0
      off += xsnprintf(s + off, sizeof s - off,
410
0
          "%swidth=%u", comma, sy->width);
411
0
    comma = ",";
412
0
  }
413
0
  if (sy->pad >= 0) {
414
0
    off += xsnprintf(s + off, sizeof s - off, "%spad=%u", comma,
415
0
        sy->pad);
416
0
    comma = ",";
417
0
  }
418
0
  uri = style_link(sy);
419
0
  if (uri != NULL) {
420
0
    xsnprintf(s + off, sizeof s - off, "%slink=%s", comma, uri);
421
0
    comma = ",";
422
0
  }
423
0
  if (*s == '\0')
424
0
    return ("default");
425
0
  return (s);
426
0
}
427
428
/* Get the hyperlink URI for a style, or NULL if it has none. */
429
const char *
430
style_link(struct style *sy)
431
0
{
432
0
  const char  *uri;
433
434
0
  if (sy->link == 0 || style_hyperlinks == NULL)
435
0
    return (NULL);
436
0
  if (!hyperlinks_get(style_hyperlinks, sy->link, &uri, NULL, NULL))
437
0
    return (NULL);
438
0
  return (uri);
439
0
}
440
441
/* Apply a style on top of the given style. */
442
struct style *
443
style_add(struct grid_cell *gc, struct options *oo, const char *name,
444
    struct format_tree *ft)
445
35.3k
{
446
35.3k
  struct style    *sy;
447
35.3k
  struct format_tree  *ft0 = NULL;
448
449
35.3k
  if (ft == NULL)
450
27.3k
    ft = ft0 = format_create(NULL, NULL, 0, FORMAT_NOJOBS);
451
452
35.3k
  sy = options_string_to_style(oo, name, ft);
453
35.3k
  if (sy == NULL)
454
0
    sy = &style_default;
455
35.3k
  if (sy->gc.fg != 8)
456
27.3k
    gc->fg = sy->gc.fg;
457
35.3k
  if (sy->gc.bg != 8)
458
0
    gc->bg = sy->gc.bg;
459
35.3k
  if (sy->gc.us != 8)
460
0
    gc->us = sy->gc.us;
461
35.3k
  gc->attr |= sy->gc.attr;
462
463
35.3k
  if (ft0 != NULL)
464
27.3k
    format_free(ft0);
465
35.3k
  return (sy);
466
35.3k
}
467
468
/* Apply a style on top of the default style. */
469
void
470
style_apply(struct grid_cell *gc, struct options *oo, const char *name,
471
    struct format_tree *ft)
472
27.3k
{
473
27.3k
  memcpy(gc, &grid_default_cell, sizeof *gc);
474
27.3k
  style_add(gc, oo, name, ft);
475
27.3k
}
476
477
/* Parse a single colour into a style */
478
int
479
style_parse_colour(struct style *sy, const struct grid_cell *base,
480
    const char *s)
481
2
{
482
2
  int c;
483
484
2
  style_set(sy, base);
485
486
2
  if (*s == '\0') {
487
2
    sy->gc.fg = -1;
488
2
    return (0);
489
2
  }
490
491
0
  if ((c = colour_fromstring(s)) == -1)
492
0
    return (-1);
493
0
  if (c == 8)
494
0
    sy->gc.fg = base->fg;
495
0
  else
496
0
    sy->gc.fg = c;
497
0
  return (0);
498
0
}
499
500
/* Initialize style from cell. */
501
void
502
style_set(struct style *sy, const struct grid_cell *gc)
503
183k
{
504
183k
  memcpy(sy, &style_default, sizeof *sy);
505
183k
  memcpy(&sy->gc, gc, sizeof sy->gc);
506
183k
}
507
508
/* Copy style. */
509
void
510
style_copy(struct style *dst, struct style *src)
511
1.89M
{
512
1.89M
  memcpy(dst, src, sizeof *dst);
513
1.89M
}
514
515
/* Set scrollbar style from an option. */
516
void
517
style_set_scrollbar_style_from_option(struct style *sb_style,
518
    struct options *oo)
519
27.3k
{
520
27.3k
  const struct options_table_entry  *oe;
521
27.3k
  struct options_entry      *o;
522
27.3k
  const char        *s;
523
27.3k
  char          *style, *expanded;
524
525
27.3k
  style_set(sb_style, &grid_default_cell);
526
27.3k
  o = options_get(oo, "pane-scrollbars-style");
527
27.3k
  if (o == NULL)
528
0
    fatalx("missing pane-scrollbars-style");
529
27.3k
  oe = options_table_entry(o);
530
27.3k
  style = format_single(NULL, oe->default_str, NULL, NULL, NULL, NULL);
531
27.3k
  if (style_parse(sb_style, &grid_default_cell, style) != 0)
532
0
    fatalx("bad pane-scrollbars-style default");
533
534
27.3k
  s = options_get_string(oo, "pane-scrollbars-style");
535
27.3k
  if (s != NULL) {
536
27.3k
    expanded = format_single(NULL, s, NULL, NULL, NULL, NULL);
537
27.3k
    if (style_parse(sb_style, &grid_default_cell, expanded) != 0)
538
0
      style_parse(sb_style, &grid_default_cell, style);
539
27.3k
    free(expanded);
540
27.3k
  }
541
27.3k
  free(style);
542
27.3k
  if (sb_style->width < 1)
543
0
    sb_style->width = PANE_SCROLLBARS_DEFAULT_WIDTH;
544
27.3k
  if (sb_style->pad < 0)
545
0
    sb_style->pad = PANE_SCROLLBARS_DEFAULT_PADDING;
546
27.3k
  utf8_set(&sb_style->gc.data, PANE_SCROLLBARS_CHARACTER);
547
27.3k
}
548
549
/* Initialize style ranges. */
550
void
551
style_ranges_init(struct style_ranges *srs)
552
27.3k
{
553
27.3k
  TAILQ_INIT(srs);
554
27.3k
}
555
556
/* Free style ranges. */
557
void
558
style_ranges_free(struct style_ranges *srs)
559
27.3k
{
560
27.3k
  struct style_range  *sr, *sr1;
561
562
27.3k
  TAILQ_FOREACH_SAFE(sr, srs, entry, sr1) {
563
0
    TAILQ_REMOVE(srs, sr, entry);
564
0
    free(sr);
565
0
  }
566
27.3k
}
567
568
/* Get range for position from style ranges. */
569
struct style_range *
570
style_ranges_get_range(struct style_ranges *srs, u_int x)
571
0
{
572
0
  struct style_range  *sr;
573
574
0
  if (srs == NULL)
575
0
    return (NULL);
576
0
  TAILQ_FOREACH(sr, srs, entry) {
577
0
    if (x >= sr->start && x < sr->end)
578
0
      return (sr);
579
0
  }
580
0
  return (NULL);
581
0
}
582
583
/* Get range for position and row from style ranges. */
584
struct style_range *
585
style_ranges_get_range_at(struct style_ranges *srs, u_int x, u_int y)
586
0
{
587
0
  struct style_range  *sr;
588
589
0
  if (srs == NULL)
590
0
    return (NULL);
591
0
  TAILQ_FOREACH(sr, srs, entry) {
592
0
    if (x >= sr->start && x < sr->end && y == sr->y)
593
0
      return (sr);
594
0
  }
595
0
  return (NULL);
596
0
}