Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/**
4
 * Hoa
5
 *
6
 *
7
 * @license
8
 *
9
 * New BSD License
10
 *
11
 * Copyright © 2007-2017, Hoa community. All rights reserved.
12
 *
13
 * Redistribution and use in source and binary forms, with or without
14
 * modification, are permitted provided that the following conditions are met:
15
 *     * Redistributions of source code must retain the above copyright
16
 *       notice, this list of conditions and the following disclaimer.
17
 *     * Redistributions in binary form must reproduce the above copyright
18
 *       notice, this list of conditions and the following disclaimer in the
19
 *       documentation and/or other materials provided with the distribution.
20
 *     * Neither the name of the Hoa nor the names of its contributors may be
21
 *       used to endorse or promote products derived from this software without
22
 *       specific prior written permission.
23
 *
24
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
 * POSSIBILITY OF SUCH DAMAGE.
35
 */
36
 
37
namespace Psy\Readline\Hoa;
38
 
39
/**
40
 * Class \Hoa\Console\Tput.
41
 *
42
 * Query terminfo database.
43
 * Resources:
44
 *     • http://man.cx/terminfo(5),
45
 *     • http://pubs.opengroup.org/onlinepubs/7908799/xcurses/terminfo.html,
46
 */
47
class ConsoleTput
48
{
49
    /**
50
     * Booleans.
51
     */
52
    protected static $_booleans = [
53
        'auto_left_margin',
54
        'auto_right_margin',
55
        'no_esc_ctlc',
56
        'ceol_standout_glitch',
57
        'eat_newline_glitch',
58
        'erase_overstrike',
59
        'generic_type',
60
        'hard_copy',
61
        'meta_key', // originally has_meta_key
62
        'status_line', // originally has_status_line
63
        'insert_null_glitch',
64
        'memory_above',
65
        'memory_below',
66
        'move_insert_mode',
67
        'move_standout_mode',
68
        'over_strike',
69
        'status_line_esc_ok',
70
        'dest_tabs_magic_smso',
71
        'tilde_glitch',
72
        'transparent_underline',
73
        'xon_xoff',
74
        'needs_xon_xoff',
75
        'prtr_silent',
76
        'hard_cursor',
77
        'non_rev_rmcup',
78
        'no_pad_char',
79
        'non_dest_scroll_region',
80
        'can_change',
81
        'back_color_erase',
82
        'hue_lightness_saturation',
83
        'col_addr_glitch',
84
        'cr_cancels_micro_mode',
85
        'print_wheel', // originally has_print_wheel
86
        'row_addr_glitch',
87
        'semi_auto_right_margin',
88
        'cpi_changes_res',
89
        'lpi_changes_res',
90
        // #ifdef __INTERNAL_CAPS_VISIBLE
91
        'backspaces_with_bs',
92
        'crt_no_scrolling',
93
        'no_correctly_working_cr',
94
        'gnu_meta_key', // originally gnu_has_meta_key
95
        'linefeed_is_newline',
96
        'hardware_tabs', // originally has_hardware_tabs
97
        'return_does_clr_eol',
98
    ];
99
 
100
    /**
101
     * Numbers.
102
     */
103
    protected static $_numbers = [
104
        'columns',
105
        'init_tabs',
106
        'lines',
107
        'lines_of_memory',
108
        'magic_cookie_glitch',
109
        'padding_baud_rate',
110
        'virtual_terminal',
111
        'width_status_line',
112
        'num_labels',
113
        'label_height',
114
        'label_width',
115
        'max_attributes',
116
        'maximum_windows',
117
        'max_colors',
118
        'max_pairs',
119
        'no_color_video',
120
        'buffer_capacity',
121
        'dot_vert_spacing',
122
        'dot_horz_spacing',
123
        'max_micro_address',
124
        'max_micro_jump',
125
        'micro_col_size',
126
        'micro_line_size',
127
        'number_of_pins',
128
        'output_res_char',
129
        'output_res_line',
130
        'output_res_horz_inch',
131
        'output_res_vert_inch',
132
        'print_rate',
133
        'wide_char_size',
134
        'buttons',
135
        'bit_image_entwining',
136
        'bit_image_type',
137
        // #ifdef __INTERNAL_CAPS_VISIBLE
138
        'magic_cookie_glitch_ul',
139
        'carriage_return_delay',
140
        'new_line_delay',
141
        'backspace_delay',
142
        'horizontal_tab_delay',
143
        'number_of_function_keys',
144
    ];
145
 
146
    /**
147
     * Strings.
148
     */
149
    protected static $_strings = [
150
        'back_tab',
151
        'bell',
152
        'carriage_return',
153
        'change_scroll_region',
154
        'clear_all_tabs',
155
        'clear_screen',
156
        'clr_eol',
157
        'clr_eos',
158
        'column_address',
159
        'command_character',
160
        'cursor_address',
161
        'cursor_down',
162
        'cursor_home',
163
        'cursor_invisible',
164
        'cursor_left',
165
        'cursor_mem_address',
166
        'cursor_normal',
167
        'cursor_right',
168
        'cursor_to_ll',
169
        'cursor_up',
170
        'cursor_visible',
171
        'delete_character',
172
        'delete_line',
173
        'dis_status_line',
174
        'down_half_line',
175
        'enter_alt_charset_mode',
176
        'enter_blink_mode',
177
        'enter_bold_mode',
178
        'enter_ca_mode',
179
        'enter_delete_mode',
180
        'enter_dim_mode',
181
        'enter_insert_mode',
182
        'enter_secure_mode',
183
        'enter_protected_mode',
184
        'enter_reverse_mode',
185
        'enter_standout_mode',
186
        'enter_underline_mode',
187
        'erase_chars',
188
        'exit_alt_charset_mode',
189
        'exit_attribute_mode',
190
        'exit_ca_mode',
191
        'exit_delete_mode',
192
        'exit_insert_mode',
193
        'exit_standout_mode',
194
        'exit_underline_mode',
195
        'flash_screen',
196
        'form_feed',
197
        'from_status_line',
198
        'init_1string',
199
        'init_2string',
200
        'init_3string',
201
        'init_file',
202
        'insert_character',
203
        'insert_line',
204
        'insert_padding',
205
        'key_backspace',
206
        'key_catab',
207
        'key_clear',
208
        'key_ctab',
209
        'key_dc',
210
        'key_dl',
211
        'key_down',
212
        'key_eic',
213
        'key_eol',
214
        'key_eos',
215
        'key_f0',
216
        'key_f1',
217
        'key_f10',
218
        'key_f2',
219
        'key_f3',
220
        'key_f4',
221
        'key_f5',
222
        'key_f6',
223
        'key_f7',
224
        'key_f8',
225
        'key_f9',
226
        'key_home',
227
        'key_ic',
228
        'key_il',
229
        'key_left',
230
        'key_ll',
231
        'key_npage',
232
        'key_ppage',
233
        'key_right',
234
        'key_sf',
235
        'key_sr',
236
        'key_stab',
237
        'key_up',
238
        'keypad_local',
239
        'keypad_xmit',
240
        'lab_f0',
241
        'lab_f1',
242
        'lab_f10',
243
        'lab_f2',
244
        'lab_f3',
245
        'lab_f4',
246
        'lab_f5',
247
        'lab_f6',
248
        'lab_f7',
249
        'lab_f8',
250
        'lab_f9',
251
        'meta_off',
252
        'meta_on',
253
        'newline',
254
        'pad_char',
255
        'parm_dch',
256
        'parm_delete_line',
257
        'parm_down_cursor',
258
        'parm_ich',
259
        'parm_index',
260
        'parm_insert_line',
261
        'parm_left_cursor',
262
        'parm_right_cursor',
263
        'parm_rindex',
264
        'parm_up_cursor',
265
        'pkey_key',
266
        'pkey_local',
267
        'pkey_xmit',
268
        'print_screen',
269
        'prtr_off',
270
        'prtr_on',
271
        'repeat_char',
272
        'reset_1string',
273
        'reset_2string',
274
        'reset_3string',
275
        'reset_file',
276
        'restore_cursor',
277
        'row_address',
278
        'save_cursor',
279
        'scroll_forward',
280
        'scroll_reverse',
281
        'set_attributes',
282
        'set_tab',
283
        'set_window',
284
        'tab',
285
        'to_status_line',
286
        'underline_char',
287
        'up_half_line',
288
        'init_prog',
289
        'key_a1',
290
        'key_a3',
291
        'key_b2',
292
        'key_c1',
293
        'key_c3',
294
        'prtr_non',
295
        'char_padding',
296
        'acs_chars',
297
        'plab_norm',
298
        'key_btab',
299
        'enter_xon_mode',
300
        'exit_xon_mode',
301
        'enter_am_mode',
302
        'exit_am_mode',
303
        'xon_character',
304
        'xoff_character',
305
        'ena_acs',
306
        'label_on',
307
        'label_off',
308
        'key_beg',
309
        'key_cancel',
310
        'key_close',
311
        'key_command',
312
        'key_copy',
313
        'key_create',
314
        'key_end',
315
        'key_enter',
316
        'key_exit',
317
        'key_find',
318
        'key_help',
319
        'key_mark',
320
        'key_message',
321
        'key_move',
322
        'key_next',
323
        'key_open',
324
        'key_options',
325
        'key_previous',
326
        'key_print',
327
        'key_redo',
328
        'key_reference',
329
        'key_refresh',
330
        'key_replace',
331
        'key_restart',
332
        'key_resume',
333
        'key_save',
334
        'key_suspend',
335
        'key_undo',
336
        'key_sbeg',
337
        'key_scancel',
338
        'key_scommand',
339
        'key_scopy',
340
        'key_screate',
341
        'key_sdc',
342
        'key_sdl',
343
        'key_select',
344
        'key_send',
345
        'key_seol',
346
        'key_sexit',
347
        'key_sfind',
348
        'key_shelp',
349
        'key_shome',
350
        'key_sic',
351
        'key_sleft',
352
        'key_smessage',
353
        'key_smove',
354
        'key_snext',
355
        'key_soptions',
356
        'key_sprevious',
357
        'key_sprint',
358
        'key_sredo',
359
        'key_sreplace',
360
        'key_sright',
361
        'key_srsume',
362
        'key_ssave',
363
        'key_ssuspend',
364
        'key_sundo',
365
        'req_for_input',
366
        'key_f11',
367
        'key_f12',
368
        'key_f13',
369
        'key_f14',
370
        'key_f15',
371
        'key_f16',
372
        'key_f17',
373
        'key_f18',
374
        'key_f19',
375
        'key_f20',
376
        'key_f21',
377
        'key_f22',
378
        'key_f23',
379
        'key_f24',
380
        'key_f25',
381
        'key_f26',
382
        'key_f27',
383
        'key_f28',
384
        'key_f29',
385
        'key_f30',
386
        'key_f31',
387
        'key_f32',
388
        'key_f33',
389
        'key_f34',
390
        'key_f35',
391
        'key_f36',
392
        'key_f37',
393
        'key_f38',
394
        'key_f39',
395
        'key_f40',
396
        'key_f41',
397
        'key_f42',
398
        'key_f43',
399
        'key_f44',
400
        'key_f45',
401
        'key_f46',
402
        'key_f47',
403
        'key_f48',
404
        'key_f49',
405
        'key_f50',
406
        'key_f51',
407
        'key_f52',
408
        'key_f53',
409
        'key_f54',
410
        'key_f55',
411
        'key_f56',
412
        'key_f57',
413
        'key_f58',
414
        'key_f59',
415
        'key_f60',
416
        'key_f61',
417
        'key_f62',
418
        'key_f63',
419
        'clr_bol',
420
        'clear_margins',
421
        'set_left_margin',
422
        'set_right_margin',
423
        'label_format',
424
        'set_clock',
425
        'display_clock',
426
        'remove_clock',
427
        'create_window',
428
        'goto_window',
429
        'hangup',
430
        'dial_phone',
431
        'quick_dial',
432
        'tone',
433
        'pulse',
434
        'flash_hook',
435
        'fixed_pause',
436
        'wait_tone',
437
        'user0',
438
        'user1',
439
        'user2',
440
        'user3',
441
        'user4',
442
        'user5',
443
        'user6',
444
        'user7',
445
        'user8',
446
        'user9',
447
        'orig_pair',
448
        'orig_colors',
449
        'initialize_color',
450
        'initialize_pair',
451
        'set_color_pair',
452
        'set_foreground',
453
        'set_background',
454
        'change_char_pitch',
455
        'change_line_pitch',
456
        'change_res_horz',
457
        'change_res_vert',
458
        'define_char',
459
        'enter_doublewide_mode',
460
        'enter_draft_quality',
461
        'enter_italics_mode',
462
        'enter_leftward_mode',
463
        'enter_micro_mode',
464
        'enter_near_letter_quality',
465
        'enter_normal_quality',
466
        'enter_shadow_mode',
467
        'enter_subscript_mode',
468
        'enter_superscript_mode',
469
        'enter_upward_mode',
470
        'exit_doublewide_mode',
471
        'exit_italics_mode',
472
        'exit_leftward_mode',
473
        'exit_micro_mode',
474
        'exit_shadow_mode',
475
        'exit_subscript_mode',
476
        'exit_superscript_mode',
477
        'exit_upward_mode',
478
        'micro_column_address',
479
        'micro_down',
480
        'micro_left',
481
        'micro_right',
482
        'micro_row_address',
483
        'micro_up',
484
        'order_of_pins',
485
        'parm_down_micro',
486
        'parm_left_micro',
487
        'parm_right_micro',
488
        'parm_up_micro',
489
        'select_char_set',
490
        'set_bottom_margin',
491
        'set_bottom_margin_parm',
492
        'set_left_margin_parm',
493
        'set_right_margin_parm',
494
        'set_top_margin',
495
        'set_top_margin_parm',
496
        'start_bit_image',
497
        'start_char_set_def',
498
        'stop_bit_image',
499
        'stop_char_set_def',
500
        'subscript_characters',
501
        'superscript_characters',
502
        'these_cause_cr',
503
        'zero_motion',
504
        'char_set_names',
505
        'key_mouse',
506
        'mouse_info',
507
        'req_mouse_pos',
508
        'get_mouse',
509
        'set_a_foreground',
510
        'set_a_background',
511
        'pkey_plab',
512
        'device_type',
513
        'code_set_init',
514
        'set0_des_seq',
515
        'set1_des_seq',
516
        'set2_des_seq',
517
        'set3_des_seq',
518
        'set_lr_margin',
519
        'set_tb_margin',
520
        'bit_image_repeat',
521
        'bit_image_newline',
522
        'bit_image_carriage_return',
523
        'color_names',
524
        'define_bit_image_region',
525
        'end_bit_image_region',
526
        'set_color_band',
527
        'set_page_length',
528
        'display_pc_char',
529
        'enter_pc_charset_mode',
530
        'exit_pc_charset_mode',
531
        'enter_scancode_mode',
532
        'exit_scancode_mode',
533
        'pc_term_options',
534
        'scancode_escape',
535
        'alt_scancode_esc',
536
        'enter_horizontal_hl_mode',
537
        'enter_left_hl_mode',
538
        'enter_low_hl_mode',
539
        'enter_right_hl_mode',
540
        'enter_top_hl_mode',
541
        'enter_vertical_hl_mode',
542
        'set_a_attributes',
543
        'set_pglen_inch',
544
        // #ifdef __INTERNAL_CAPS_VISIBLE
545
        'termcap_init2',
546
        'termcap_reset',
547
        'linefeed_if_not_lf',
548
        'backspace_if_not_bs',
549
        'other_non_function_keys',
550
        'arrow_key_map',
551
        'acs_ulcorner',
552
        'acs_llcorner',
553
        'acs_urcorner',
554
        'acs_lrcorner',
555
        'acs_ltee',
556
        'acs_rtee',
557
        'acs_btee',
558
        'acs_ttee',
559
        'acs_hline',
560
        'acs_vline',
561
        'acs_plus',
562
        'memory_lock',
563
        'memory_unlock',
564
        'box_chars_1',
565
    ];
566
 
567
    /**
568
     * Computed informations.
569
     */
570
    protected $_informations = [];
571
 
572
    /**
573
     * Set stream and parse.
574
     */
575
    public function __construct($terminfo = null)
576
    {
577
        if (null === $terminfo) {
578
            $terminfo = static::getTerminfo();
579
        }
580
 
581
        $this->parse($terminfo);
582
 
583
        return;
584
    }
585
 
586
    /**
587
     * Parse.
588
     */
589
    protected function parse(string $terminfo): array
590
    {
591
        if (!\file_exists($terminfo)) {
592
            throw new ConsoleException('Terminfo file %s does not exist.', 0, $terminfo);
593
        }
594
 
595
        $data = \file_get_contents($terminfo);
596
        $length = \strlen($data);
597
        $out = ['file' => $terminfo];
598
 
599
        $headers = [
600
            'data_size'         => $length,
601
            'header_size'       => 12,
602
            'magic_number'      => (\ord($data[1]) << 8) | \ord($data[0]),
603
            'names_size'        => (\ord($data[3]) << 8) | \ord($data[2]),
604
            'bool_count'        => (\ord($data[5]) << 8) | \ord($data[4]),
605
            'number_count'      => (\ord($data[7]) << 8) | \ord($data[6]),
606
            'string_count'      => (\ord($data[9]) << 8) | \ord($data[8]),
607
            'string_table_size' => (\ord($data[11]) << 8) | \ord($data[10]),
608
        ];
609
        $out['headers'] = $headers;
610
 
611
        // Names.
612
        $i = $headers['header_size'];
613
        $nameAndDescription = \explode('|', \substr($data, $i, $headers['names_size'] - 1));
614
        $out['name'] = $nameAndDescription[0];
615
        $out['description'] = $nameAndDescription[1];
616
 
617
        // Booleans.
618
        $i += $headers['names_size'];
619
        $booleans = [];
620
        $booleanNames = &static::$_booleans;
621
 
622
        for (
623
            $e = 0, $max = $i + $headers['bool_count'];
624
            $i < $max;
625
            ++$e, ++$i
626
        ) {
627
            $booleans[$booleanNames[$e]] = 1 === \ord($data[$i]);
628
        }
629
 
630
        $out['booleans'] = $booleans;
631
 
632
        // Numbers.
633
        if (1 === ($i % 2)) {
634
            ++$i;
635
        }
636
 
637
        $numbers = [];
638
        $numberNames = &static::$_numbers;
639
 
640
        for (
641
            $e = 0, $max = $i + $headers['number_count'] * 2;
642
            $i < $max;
643
            ++$e, $i += 2
644
        ) {
645
            $name = $numberNames[$e];
646
            $data_i0 = \ord($data[$i]);
647
            $data_i1 = \ord($data[$i + 1]);
648
 
649
            if ($data_i1 === 255 && $data_i0 === 255) {
650
                $numbers[$name] = -1;
651
            } else {
652
                $numbers[$name] = ($data_i1 << 8) | $data_i0;
653
            }
654
        }
655
 
656
        $out['numbers'] = $numbers;
657
 
658
        // Strings.
659
        $strings = [];
660
        $stringNames = &static::$_strings;
661
        $ii = $i + $headers['string_count'] * 2;
662
 
663
        for (
664
            $e = 0, $max = $ii;
665
            $i < $max;
666
            ++$e, $i += 2
667
        ) {
668
            $name = $stringNames[$e];
669
            $data_i0 = \ord($data[$i]);
670
            $data_i1 = \ord($data[$i + 1]);
671
 
672
            if ($data_i1 === 255 && $data_i0 === 255) {
673
                continue;
674
            }
675
 
676
            $a = ($data_i1 << 8) | $data_i0;
677
            $strings[$name] = $a;
678
 
679
            if (65534 === $a) {
680
                continue;
681
            }
682
 
683
            $b = $ii + $a;
684
            $c = $b;
685
 
686
            while ($c < $length && \ord($data[$c])) {
687
                $c++;
688
            }
689
 
690
            $value = \substr($data, $b, $c - $b);
691
            $strings[$name] = false !== $value ? $value : null;
692
        }
693
 
694
        $out['strings'] = $strings;
695
 
696
        return $this->_informations = $out;
697
    }
698
 
699
    /**
700
     * Get all informations.
701
     */
702
    public function getInformations(): array
703
    {
704
        return $this->_informations;
705
    }
706
 
707
    /**
708
     * Get a boolean value.
709
     */
710
    public function has(string $boolean): bool
711
    {
712
        if (!isset($this->_informations['booleans'][$boolean])) {
713
            return false;
714
        }
715
 
716
        return $this->_informations['booleans'][$boolean];
717
    }
718
 
719
    /**
720
     * Get a number value.
721
     */
722
    public function count(string $number): int
723
    {
724
        if (!isset($this->_informations['numbers'][$number])) {
725
            return 0;
726
        }
727
 
728
        return $this->_informations['numbers'][$number];
729
    }
730
 
731
    /**
732
     * Get a string value.
733
     */
734
    public function get(string $string)
735
    {
736
        if (!isset($this->_informations['strings'][$string])) {
737
            return null;
738
        }
739
 
740
        return $this->_informations['strings'][$string];
741
    }
742
 
743
    /**
744
     * Get current term profile.
745
     */
746
    public static function getTerm(): string
747
    {
748
        return
749
            isset($_SERVER['TERM']) && !empty($_SERVER['TERM'])
750
                ? $_SERVER['TERM']
751
                : (\defined('PHP_WINDOWS_VERSION_PLATFORM') ? 'windows-ansi' : 'xterm');
752
    }
753
 
754
    /**
755
     * Get pathname to the current terminfo.
756
     */
757
    public static function getTerminfo($term = null): string
758
    {
759
        $paths = [];
760
 
761
        if (isset($_SERVER['TERMINFO'])) {
762
            $paths[] = $_SERVER['TERMINFO'];
763
        }
764
 
765
        if (isset($_SERVER['HOME'])) {
766
            $paths[] = $_SERVER['HOME'].\DIRECTORY_SEPARATOR.'.terminfo';
767
        }
768
 
769
        if (isset($_SERVER['TERMINFO_DIRS'])) {
770
            foreach (\explode(':', $_SERVER['TERMINFO_DIRS']) as $path) {
771
                $paths[] = $path;
772
            }
773
        }
774
 
775
        $paths[] = '/usr/share/terminfo';
776
        $paths[] = '/usr/share/lib/terminfo';
777
        $paths[] = '/lib/terminfo';
778
        $paths[] = '/usr/lib/terminfo';
779
        $paths[] = '/usr/local/share/terminfo';
780
        $paths[] = '/usr/local/share/lib/terminfo';
781
        $paths[] = '/usr/local/lib/terminfo';
782
        $paths[] = '/usr/local/ncurses/lib/terminfo';
783
        $paths[] = 'hoa://Library/Terminfo';
784
 
785
        $term = $term ?: static::getTerm();
786
        $fileHexa = \dechex(\ord($term[0])).\DIRECTORY_SEPARATOR.$term;
787
        $fileAlpha = $term[0].\DIRECTORY_SEPARATOR.$term;
788
        $pathname = null;
789
 
790
        foreach ($paths as $path) {
791
            if (\file_exists($_ = $path.\DIRECTORY_SEPARATOR.$fileHexa) ||
792
                \file_exists($_ = $path.\DIRECTORY_SEPARATOR.$fileAlpha)) {
793
                $pathname = $_;
794
 
795
                break;
796
            }
797
        }
798
 
799
        if (null === $pathname && 'xterm' !== $term) {
800
            return static::getTerminfo('xterm');
801
        }
802
 
803
        return $pathname ?? '';
804
    }
805
 
806
    /**
807
     * Check whether all required terminfo capabilities are defined.
808
     */
809
    public static function isSupported(): bool
810
    {
811
        if (static::getTerminfo() === '') {
812
            return false;
813
        }
814
 
815
        $requiredVars = [
816
            'clear_screen',
817
            'clr_bol',
818
            'clr_eol',
819
            'clr_eos',
820
            'initialize_color',
821
            'parm_down_cursor',
822
            'parm_index',
823
            'parm_left_cursor',
824
            'parm_right_cursor',
825
            'parm_rindex',
826
            'parm_up_cursor',
827
            'user6',
828
            'user7',
829
        ];
830
 
831
        $tput = new self();
832
 
833
        foreach ($requiredVars as $var) {
834
            if ($tput->get($var) === null) {
835
                return false;
836
            }
837
        }
838
 
839
        return true;
840
    }
841
}