robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3b00ddb601
master
1#include <stdio.h> 2 3#include "nvim/vterm/pen.h" 4#include "nvim/vterm/vterm.h" 5#include "nvim/vterm/vterm_internal_defs.h" 6 7#include "vterm/pen.c.generated.h" 8 9// Structure used to store RGB triples without the additional metadata stored in VTermColor. 10typedef struct { 11uint8_t red ,green ,blue ; 12}VTermRGB ; 13 14static const VTermRGB ansi_colors []= { 15// R G B 16 {0 ,0 ,0 },// black 17 {224 ,0 ,0 },// red 18 {0 ,224 ,0 },// green 19 {224 ,224 ,0 },// yellow 20 {0 ,0 ,224 },// blue 21 {224 ,0 ,224 },// magenta 22 {0 ,224 ,224 },// cyan 23 {224 ,224 ,224 },// white == light grey 24 25// high intensity 26 {128 ,128 ,128 },// black 27 {255 ,64 ,64 },// red 28 {64 ,255 ,64 },// green 29 {255 ,255 ,64 },// yellow 30 {64 ,64 ,255 },// blue 31 {255 ,64 ,255 },// magenta 32 {64 ,255 ,255 },// cyan 33 {255 ,255 ,255 },// white for real 34}; 35 36static uint8_t ramp6 []= { 370x00 ,0x33 ,0x66 ,0x99 ,0xCC ,0xFF , 38}; 39 40static uint8_t ramp24 []= { 410x00 ,0x0B ,0x16 ,0x21 ,0x2C ,0x37 ,0x42 ,0x4D ,0x58 ,0x63 ,0x6E ,0x79 , 420x85 ,0x90 ,0x9B ,0xA6 ,0xB1 ,0xBC ,0xC7 ,0xD2 ,0xDD ,0xE8 ,0xF3 ,0xFF , 43}; 44 45static void lookup_default_colour_ansi (long idx ,VTermColor * col ) 46{ 47if (idx >=0 && idx < 16 ) { 48vterm_color_rgb (col , 49ansi_colors [idx ].red ,ansi_colors [idx ].green ,ansi_colors [idx ].blue ); 50 } 51} 52 53static bool lookup_colour_ansi (const VTermState * state ,long index ,VTermColor * col ) 54{ 55if (index >=0 && index < 16 ) { 56* col = state -> colors [index ]; 57return true; 58 } 59 60return false; 61} 62 63static bool lookup_colour_palette (const VTermState * state ,long index ,VTermColor * col ) 64{ 65if (index >=0 && index < 16 ) { 66// Normal 8 colours or high intensity - parse as palette 0 67return lookup_colour_ansi (state ,index ,col ); 68 }else if (index >=16 && index < 232 ) { 69// 216-colour cube 70index -= 16 ; 71 72vterm_color_rgb (col ,ramp6 [index /6 /6 %6 ], 73ramp6 [index /6 %6 ], 74ramp6 [index %6 ]); 75 76return true; 77 }else if (index >=232 && index < 256 ) { 78// 24 greyscales 79index -= 232 ; 80 81vterm_color_rgb (col ,ramp24 [index ],ramp24 [index ],ramp24 [index ]); 82 83return true; 84 } 85 86return false; 87} 88 89static int lookup_colour (const VTermState * state ,int palette ,const long args [],int argcount , 90VTermColor * col ) 91{ 92switch (palette ) { 93case 2 : {// RGB mode - 3 args contain colour values directly 94// ITU-T T.416 places a colour space id before R:G:B, as in "38:2::R:G:B". 95// Skip it when this colon-separated group holds more than three arguments. 96int grouplen = 0 ; 97while (grouplen < argcount && CSI_ARG_HAS_MORE (args [grouplen ])) { 98grouplen ++ ; 99 } 100grouplen = grouplen < argcount ?grouplen + 1 :argcount ; 101const int skip = grouplen > 3 ?1 :0 ; 102 103if (argcount - skip < 3 ) { 104return argcount ; 105 } 106 107vterm_color_rgb (col , (uint8_t )CSI_ARG (args [skip ]), (uint8_t )CSI_ARG (args [skip + 1 ]), 108 (uint8_t )CSI_ARG (args [skip + 2 ])); 109 110return skip + 3 ; 111 } 112 113case 5 :// XTerm 256-colour mode 114if (!argcount || CSI_ARG_IS_MISSING (args [0 ])) { 115return argcount ?1 :0 ; 116 } 117 118vterm_color_indexed (col , (uint8_t )args [0 ]); 119 120return argcount ?1 :0 ; 121 122default : 123DEBUG_LOG ("Unrecognised colour palette %d\n" ,palette ); 124return 0 ; 125 } 126} 127 128// Some conveniences 129 130static void setpenattr (VTermState * state ,VTermAttr attr ,VTermValueType type ,VTermValue * val ) 131{ 132#ifdef DEBUG 133if (type != vterm_get_attr_type (attr )) { 134DEBUG_LOG ("Cannot set attr %d as it has type %d, not type %d\n" , 135attr ,vterm_get_attr_type (attr ),type ); 136return ; 137 } 138#endif 139if (state -> callbacks && state -> callbacks -> setpenattr ) { 140 (* state -> callbacks -> setpenattr )(attr ,val ,state -> cbdata ); 141 } 142} 143 144static void setpenattr_bool (VTermState * state ,VTermAttr attr ,int boolean ) 145{ 146VTermValue val = { .boolean = boolean }; 147setpenattr (state ,attr ,VTERM_VALUETYPE_BOOL ,& val ); 148} 149 150static void setpenattr_int (VTermState * state ,VTermAttr attr ,int number ) 151{ 152VTermValue val = { .number = number }; 153setpenattr (state ,attr ,VTERM_VALUETYPE_INT ,& val ); 154} 155 156static void setpenattr_col (VTermState * state ,VTermAttr attr ,VTermColor color ) 157{ 158VTermValue val = { .color = color }; 159setpenattr (state ,attr ,VTERM_VALUETYPE_COLOR ,& val ); 160} 161 162static void set_pen_col_ansi (VTermState * state ,VTermAttr attr ,long col ) 163{ 164VTermColor * colp = (attr == VTERM_ATTR_BACKGROUND ) ?& state -> pen .bg :& state -> pen .fg ; 165 166vterm_color_indexed (colp , (uint8_t )col ); 167 168setpenattr_col (state ,attr ,* colp ); 169} 170 171void vterm_state_newpen (VTermState * state ) 172{ 173// 90% grey so that pure white is brighter 174vterm_color_rgb (& state -> default_fg ,240 ,240 ,240 ); 175vterm_color_rgb (& state -> default_bg ,0 ,0 ,0 ); 176vterm_state_set_default_colors (state ,& state -> default_fg ,& state -> default_bg ); 177 178for (int col = 0 ;col < 16 ;col ++ ) { 179lookup_default_colour_ansi (col ,& state -> colors [col ]); 180 } 181} 182 183void vterm_state_resetpen (VTermState * state ) 184{ 185state -> pen .bold = 0 ;setpenattr_bool (state ,VTERM_ATTR_BOLD ,0 ); 186state -> pen .underline = 0 ;setpenattr_int (state ,VTERM_ATTR_UNDERLINE ,0 ); 187state -> pen .italic = 0 ;setpenattr_bool (state ,VTERM_ATTR_ITALIC ,0 ); 188state -> pen .blink = 0 ;setpenattr_bool (state ,VTERM_ATTR_BLINK ,0 ); 189state -> pen .reverse = 0 ;setpenattr_bool (state ,VTERM_ATTR_REVERSE ,0 ); 190state -> pen .conceal = 0 ;setpenattr_bool (state ,VTERM_ATTR_CONCEAL ,0 ); 191state -> pen .strike = 0 ;setpenattr_bool (state ,VTERM_ATTR_STRIKE ,0 ); 192state -> pen .font = 0 ;setpenattr_int (state ,VTERM_ATTR_FONT ,0 ); 193state -> pen .small = 0 ;setpenattr_bool (state ,VTERM_ATTR_SMALL ,0 ); 194state -> pen .baseline = 0 ;setpenattr_int (state ,VTERM_ATTR_BASELINE ,0 ); 195state -> pen .dim = 0 ;setpenattr_bool (state ,VTERM_ATTR_DIM ,0 ); 196state -> pen .overline = 0 ;setpenattr_bool (state ,VTERM_ATTR_OVERLINE ,0 ); 197 198state -> pen .fg = state -> default_fg ; 199setpenattr_col (state ,VTERM_ATTR_FOREGROUND ,state -> default_fg ); 200state -> pen .bg = state -> default_bg ; 201setpenattr_col (state ,VTERM_ATTR_BACKGROUND ,state -> default_bg ); 202 203state -> pen .uri = 0 ;setpenattr_int (state ,VTERM_ATTR_URI ,0 ); 204} 205 206void vterm_state_savepen (VTermState * state ,int save ) 207{ 208if (save ) { 209state -> saved .pen = state -> pen ; 210 }else { 211state -> pen = state -> saved .pen ; 212 213setpenattr_bool (state ,VTERM_ATTR_BOLD ,state -> pen .bold ); 214setpenattr_int (state ,VTERM_ATTR_UNDERLINE ,state -> pen .underline ); 215setpenattr_bool (state ,VTERM_ATTR_ITALIC ,state -> pen .italic ); 216setpenattr_bool (state ,VTERM_ATTR_BLINK ,state -> pen .blink ); 217setpenattr_bool (state ,VTERM_ATTR_REVERSE ,state -> pen .reverse ); 218setpenattr_bool (state ,VTERM_ATTR_CONCEAL ,state -> pen .conceal ); 219setpenattr_bool (state ,VTERM_ATTR_STRIKE ,state -> pen .strike ); 220setpenattr_int (state ,VTERM_ATTR_FONT ,state -> pen .font ); 221setpenattr_bool (state ,VTERM_ATTR_SMALL ,state -> pen .small ); 222setpenattr_int (state ,VTERM_ATTR_BASELINE ,state -> pen .baseline ); 223setpenattr_bool (state ,VTERM_ATTR_DIM ,state -> pen .dim ); 224setpenattr_bool (state ,VTERM_ATTR_OVERLINE ,state -> pen .overline ); 225 226setpenattr_col (state ,VTERM_ATTR_FOREGROUND ,state -> pen .fg ); 227setpenattr_col (state ,VTERM_ATTR_BACKGROUND ,state -> pen .bg ); 228 229setpenattr_int (state ,VTERM_ATTR_URI ,state -> pen .uri ); 230 } 231} 232 233void vterm_state_set_default_colors (VTermState * state ,const VTermColor * default_fg , 234const VTermColor * default_bg ) 235{ 236if (default_fg ) { 237state -> default_fg = * default_fg ; 238state -> default_fg .type = (state -> default_fg .type & ~VTERM_COLOR_DEFAULT_MASK ) 239 |VTERM_COLOR_DEFAULT_FG ; 240 } 241 242if (default_bg ) { 243state -> default_bg = * default_bg ; 244state -> default_bg .type = (state -> default_bg .type & ~VTERM_COLOR_DEFAULT_MASK ) 245 |VTERM_COLOR_DEFAULT_BG ; 246 } 247} 248 249void vterm_state_set_palette_color (VTermState * state ,int index ,const VTermColor * col ) 250{ 251if (index >=0 && index < 16 ) { 252state -> colors [index ]= * col ; 253 } 254} 255 256/// Makes sure that the given color `col` is indeed an RGB colour. After this 257/// function returns, VTERM_COLOR_IS_RGB(col) will return true, while all other 258/// flags stored in `col->type` will have been reset. 259/// 260/// @param state is the VTermState instance from which the colour palette should 261/// be extracted. 262/// @param col is a pointer at the VTermColor instance that should be converted 263/// to an RGB colour. 264void vterm_state_convert_color_to_rgb (const VTermState * state ,VTermColor * col ) 265{ 266if (VTERM_COLOR_IS_INDEXED (col )) {// Convert indexed colors to RGB 267lookup_colour_palette (state ,col -> indexed .idx ,col ); 268 } 269col -> type &=VTERM_COLOR_TYPE_MASK ;// Reset any metadata but the type 270} 271 272void vterm_state_setpen (VTermState * state ,const long args [],int argcount ) 273{ 274// SGR - ECMA-48 8.3.117 275 276int argi = 0 ; 277int value ; 278 279while (argi < argcount ) { 280// This logic is easier to do 'done' backwards; set it true, and make it 281// false again in the 'default' case 282int done = 1 ; 283 284long arg ; 285switch (arg = CSI_ARG (args [argi ])) { 286case CSI_ARG_MISSING : 287case 0 :// Reset 288vterm_state_resetpen (state ); 289break ; 290 291case 1 : {// Bold on 292const VTermColor * fg = & state -> pen .fg ; 293state -> pen .bold = 1 ; 294setpenattr_bool (state ,VTERM_ATTR_BOLD ,1 ); 295if (!VTERM_COLOR_IS_DEFAULT_FG (fg )&& VTERM_COLOR_IS_INDEXED (fg )&& fg -> indexed .idx < 8 296&& state -> bold_is_highbright ) { 297set_pen_col_ansi (state ,VTERM_ATTR_FOREGROUND ,fg -> indexed .idx + (state -> pen .bold ?8 :0 )); 298 } 299break ; 300 } 301 302case 2 :// Dim/faint on 303state -> pen .dim = 1 ; 304setpenattr_bool (state ,VTERM_ATTR_DIM ,1 ); 305break ; 306 307case 3 :// Italic on 308state -> pen .italic = 1 ; 309setpenattr_bool (state ,VTERM_ATTR_ITALIC ,1 ); 310break ; 311 312case 4 :// Underline 313state -> pen .underline = VTERM_UNDERLINE_SINGLE ; 314if (CSI_ARG_HAS_MORE (args [argi ])) { 315argi ++ ; 316switch (CSI_ARG (args [argi ])) { 317case 0 : 318state -> pen .underline = 0 ; 319break ; 320case 1 : 321state -> pen .underline = VTERM_UNDERLINE_SINGLE ; 322break ; 323case 2 : 324state -> pen .underline = VTERM_UNDERLINE_DOUBLE ; 325break ; 326case 3 : 327state -> pen .underline = VTERM_UNDERLINE_CURLY ; 328break ; 329 } 330 } 331setpenattr_int (state ,VTERM_ATTR_UNDERLINE ,state -> pen .underline ); 332break ; 333 334case 5 :// Blink 335state -> pen .blink = 1 ; 336setpenattr_bool (state ,VTERM_ATTR_BLINK ,1 ); 337break ; 338 339case 7 :// Reverse on 340state -> pen .reverse = 1 ; 341setpenattr_bool (state ,VTERM_ATTR_REVERSE ,1 ); 342break ; 343 344case 8 :// Conceal on 345state -> pen .conceal = 1 ; 346setpenattr_bool (state ,VTERM_ATTR_CONCEAL ,1 ); 347break ; 348 349case 9 :// Strikethrough on 350state -> pen .strike = 1 ; 351setpenattr_bool (state ,VTERM_ATTR_STRIKE ,1 ); 352break ; 353 354case 10 : 355case 11 : 356case 12 : 357case 13 : 358case 14 : 359case 15 : 360case 16 : 361case 17 : 362case 18 : 363case 19 :// Select font 364state -> pen .font = CSI_ARG (args [argi ])- 10 ; 365setpenattr_int (state ,VTERM_ATTR_FONT ,state -> pen .font ); 366break ; 367 368case 21 :// Underline double 369state -> pen .underline = VTERM_UNDERLINE_DOUBLE ; 370setpenattr_int (state ,VTERM_ATTR_UNDERLINE ,state -> pen .underline ); 371break ; 372 373case 22 :// Normal intensity (bold and dim off) 374state -> pen .bold = 0 ; 375setpenattr_bool (state ,VTERM_ATTR_BOLD ,0 ); 376state -> pen .dim = 0 ; 377setpenattr_bool (state ,VTERM_ATTR_DIM ,0 ); 378break ; 379 380case 23 :// Italic and Gothic (currently unsupported) off 381state -> pen .italic = 0 ; 382setpenattr_bool (state ,VTERM_ATTR_ITALIC ,0 ); 383break ; 384 385case 24 :// Underline off 386state -> pen .underline = 0 ; 387setpenattr_int (state ,VTERM_ATTR_UNDERLINE ,0 ); 388break ; 389 390case 25 :// Blink off 391state -> pen .blink = 0 ; 392setpenattr_bool (state ,VTERM_ATTR_BLINK ,0 ); 393break ; 394 395case 27 :// Reverse off 396state -> pen .reverse = 0 ; 397setpenattr_bool (state ,VTERM_ATTR_REVERSE ,0 ); 398break ; 399 400case 28 :// Conceal off (Reveal) 401state -> pen .conceal = 0 ; 402setpenattr_bool (state ,VTERM_ATTR_CONCEAL ,0 ); 403break ; 404 405case 29 :// Strikethrough off 406state -> pen .strike = 0 ; 407setpenattr_bool (state ,VTERM_ATTR_STRIKE ,0 ); 408break ; 409 410case 30 : 411case 31 : 412case 32 : 413case 33 : 414case 34 : 415case 35 : 416case 36 : 417case 37 :// Foreground colour palette 418value = CSI_ARG (args [argi ])- 30 ; 419if (state -> pen .bold && state -> bold_is_highbright ) { 420value += 8 ; 421 } 422set_pen_col_ansi (state ,VTERM_ATTR_FOREGROUND ,value ); 423break ; 424 425case 38 :// Foreground colour alternative palette 426if (argcount - argi < 1 ) { 427return ; 428 } 429argi += 1 + lookup_colour (state ,CSI_ARG (args [argi + 1 ]),args + argi + 2 , 430argcount - argi - 2 ,& state -> pen .fg ); 431setpenattr_col (state ,VTERM_ATTR_FOREGROUND ,state -> pen .fg ); 432break ; 433 434case 39 :// Foreground colour default 435state -> pen .fg = state -> default_fg ; 436setpenattr_col (state ,VTERM_ATTR_FOREGROUND ,state -> pen .fg ); 437break ; 438 439case 40 : 440case 41 : 441case 42 : 442case 43 : 443case 44 : 444case 45 : 445case 46 : 446case 47 :// Background colour palette 447value = CSI_ARG (args [argi ])- 40 ; 448set_pen_col_ansi (state ,VTERM_ATTR_BACKGROUND ,value ); 449break ; 450 451case 48 :// Background colour alternative palette 452if (argcount - argi < 1 ) { 453return ; 454 } 455argi += 1 + lookup_colour (state ,CSI_ARG (args [argi + 1 ]),args + argi + 2 , 456argcount - argi - 2 ,& state -> pen .bg ); 457setpenattr_col (state ,VTERM_ATTR_BACKGROUND ,state -> pen .bg ); 458break ; 459 460case 49 :// Default background 461state -> pen .bg = state -> default_bg ; 462setpenattr_col (state ,VTERM_ATTR_BACKGROUND ,state -> pen .bg ); 463break ; 464 465case 53 :// Overline on 466state -> pen .overline = 1 ; 467setpenattr_bool (state ,VTERM_ATTR_OVERLINE ,1 ); 468break ; 469 470case 55 :// Overline off 471state -> pen .overline = 0 ; 472setpenattr_bool (state ,VTERM_ATTR_OVERLINE ,0 ); 473break ; 474 475case 73 :// Superscript 476case 74 :// Subscript 477case 75 :// Superscript/subscript off 478state -> pen .small = (arg != 75 ); 479state -> pen .baseline = 480 (arg == 73 ) ?VTERM_BASELINE_RAISE 481 : (arg == 74 ) ?VTERM_BASELINE_LOWER 482 :VTERM_BASELINE_NORMAL ; 483setpenattr_bool (state ,VTERM_ATTR_SMALL ,state -> pen .small ); 484setpenattr_int (state ,VTERM_ATTR_BASELINE ,state -> pen .baseline ); 485break ; 486 487case 90 : 488case 91 : 489case 92 : 490case 93 : 491case 94 : 492case 95 : 493case 96 : 494case 97 :// Foreground colour high-intensity palette 495value = CSI_ARG (args [argi ])- 90 + 8 ; 496set_pen_col_ansi (state ,VTERM_ATTR_FOREGROUND ,value ); 497break ; 498 499case 100 : 500case 101 : 501case 102 : 502case 103 : 503case 104 : 504case 105 : 505case 106 : 506case 107 :// Background colour high-intensity palette 507value = CSI_ARG (args [argi ])- 100 + 8 ; 508set_pen_col_ansi (state ,VTERM_ATTR_BACKGROUND ,value ); 509break ; 510 511default : 512done = 0 ; 513break ; 514 } 515 516if (!done ) { 517DEBUG_LOG ("libvterm: Unhandled CSI SGR %ld\n" ,arg ); 518 } 519 520while (CSI_ARG_HAS_MORE (args [argi ++ ])) {} 521 } 522} 523 524static int vterm_state_getpen_color (const VTermColor * col ,int argi ,long args [],int fg ) 525{ 526// Do nothing if the given color is the default color 527if ((fg && VTERM_COLOR_IS_DEFAULT_FG (col )) 528|| (!fg && VTERM_COLOR_IS_DEFAULT_BG (col ))) { 529return argi ; 530 } 531 532// Decide whether to send an indexed color or an RGB color 533if (VTERM_COLOR_IS_INDEXED (col )) { 534const uint8_t idx = col -> indexed .idx ; 535if (idx < 8 ) { 536args [argi ++ ]= (idx + (fg ?30 :40 )); 537 }else if (idx < 16 ) { 538args [argi ++ ]= (idx - 8 + (fg ?90 :100 )); 539 }else { 540args [argi ++ ]= CSI_ARG_FLAG_MORE | (fg ?38 :48 ); 541args [argi ++ ]= CSI_ARG_FLAG_MORE |5 ; 542args [argi ++ ]= idx ; 543 } 544 }else if (VTERM_COLOR_IS_RGB (col )) { 545args [argi ++ ]= CSI_ARG_FLAG_MORE | (fg ?38 :48 ); 546args [argi ++ ]= CSI_ARG_FLAG_MORE |2 ; 547args [argi ++ ]= CSI_ARG_FLAG_MORE |col -> rgb .red ; 548args [argi ++ ]= CSI_ARG_FLAG_MORE |col -> rgb .green ; 549args [argi ++ ]= col -> rgb .blue ; 550 } 551return argi ; 552} 553 554int vterm_state_getpen (VTermState * state ,long args [],int argcount ) 555{ 556int argi = 0 ; 557 558if (state -> pen .bold ) { 559args [argi ++ ]= 1 ; 560 } 561 562if (state -> pen .dim ) { 563args [argi ++ ]= 2 ; 564 } 565 566if (state -> pen .italic ) { 567args [argi ++ ]= 3 ; 568 } 569 570if (state -> pen .underline == VTERM_UNDERLINE_SINGLE ) { 571args [argi ++ ]= 4 ; 572 } 573if (state -> pen .underline == VTERM_UNDERLINE_CURLY ) { 574args [argi ++ ]= 4 |CSI_ARG_FLAG_MORE ,args [argi ++ ]= 3 ; 575 } 576 577if (state -> pen .blink ) { 578args [argi ++ ]= 5 ; 579 } 580 581if (state -> pen .reverse ) { 582args [argi ++ ]= 7 ; 583 } 584 585if (state -> pen .conceal ) { 586args [argi ++ ]= 8 ; 587 } 588 589if (state -> pen .strike ) { 590args [argi ++ ]= 9 ; 591 } 592 593if (state -> pen .font ) { 594args [argi ++ ]= 10 + state -> pen .font ; 595 } 596 597if (state -> pen .underline == VTERM_UNDERLINE_DOUBLE ) { 598args [argi ++ ]= 21 ; 599 } 600 601argi = vterm_state_getpen_color (& state -> pen .fg ,argi ,args , true); 602 603argi = vterm_state_getpen_color (& state -> pen .bg ,argi ,args , false); 604 605if (state -> pen .overline ) { 606args [argi ++ ]= 53 ; 607 } 608 609if (state -> pen .small ) { 610if (state -> pen .baseline == VTERM_BASELINE_RAISE ) { 611args [argi ++ ]= 73 ; 612 }else if (state -> pen .baseline == VTERM_BASELINE_LOWER ) { 613args [argi ++ ]= 74 ; 614 } 615 } 616 617return argi ; 618} 619 620int vterm_state_set_penattr (VTermState * state ,VTermAttr attr ,VTermValueType type ,VTermValue * val ) 621{ 622if (!val ) { 623return 0 ; 624 } 625 626if (type != vterm_get_attr_type (attr )) { 627DEBUG_LOG ("Cannot set attr %d as it has type %d, not type %d\n" , 628attr ,vterm_get_attr_type (attr ),type ); 629return 0 ; 630 } 631 632switch (attr ) { 633case VTERM_ATTR_BOLD : 634state -> pen .bold = (unsigned )val -> boolean ; 635break ; 636case VTERM_ATTR_UNDERLINE : 637state -> pen .underline = (unsigned )val -> number ; 638break ; 639case VTERM_ATTR_ITALIC : 640state -> pen .italic = (unsigned )val -> boolean ; 641break ; 642case VTERM_ATTR_BLINK : 643state -> pen .blink = (unsigned )val -> boolean ; 644break ; 645case VTERM_ATTR_REVERSE : 646state -> pen .reverse = (unsigned )val -> boolean ; 647break ; 648case VTERM_ATTR_CONCEAL : 649state -> pen .conceal = (unsigned )val -> boolean ; 650break ; 651case VTERM_ATTR_STRIKE : 652state -> pen .strike = (unsigned )val -> boolean ; 653break ; 654case VTERM_ATTR_FONT : 655state -> pen .font = (unsigned )val -> number ; 656break ; 657case VTERM_ATTR_FOREGROUND : 658state -> pen .fg = val -> color ; 659break ; 660case VTERM_ATTR_BACKGROUND : 661state -> pen .bg = val -> color ; 662break ; 663case VTERM_ATTR_SMALL : 664state -> pen .small = (unsigned )val -> boolean ; 665break ; 666case VTERM_ATTR_BASELINE : 667state -> pen .baseline = (unsigned )val -> number ; 668break ; 669case VTERM_ATTR_URI : 670state -> pen .uri = val -> number ; 671break ; 672case VTERM_ATTR_DIM : 673state -> pen .dim = (unsigned )val -> boolean ; 674break ; 675case VTERM_ATTR_OVERLINE : 676state -> pen .overline = (unsigned )val -> boolean ; 677break ; 678default : 679return 0 ; 680 } 681 682if (state -> callbacks && state -> callbacks -> setpenattr ) { 683 (* state -> callbacks -> setpenattr )(attr ,val ,state -> cbdata ); 684 } 685 686return 1 ; 687}