4141using Downloads
4242
4343standard_caps = IOBuffer()
44+ user_caps = IOBuffer()
4445
4546Downloads.download("https://raw.githubusercontent.com/mirror/ncurses/v$NCURSES_VERSION/include/Caps", standard_caps)
47+ Downloads.download("https://raw.githubusercontent.com/mirror/ncurses/v$NCURSES_VERSION/include/Caps-ncurses", user_caps)
4648
47- const TERM_FLAGS = Tuple{String, String, String}[]
48- const TERM_NUMBERS = Tuple{String, String, String}[]
49- const TERM_STRINGS = Tuple{String, String, String}[]
49+ const TERM_FLAGS = NTuple{3, String}[]
50+ const TERM_NUMBERS = NTuple{3, String}[]
51+ const TERM_STRINGS = NTuple{3, String}[]
52+ const TERM_USER = NTuple{3, String}[]
5053
5154for line in eachline(seekstart(standard_caps))
5255 startswith(line, '#') && continue
@@ -66,6 +69,30 @@ for line in eachline(seekstart(standard_caps))
6669 push!(caplist, (name, shortcode, description))
6770end
6871
72+ for line in eachline(seekstart(user_caps))
73+ startswith(line, '#') && continue
74+ !startswith(line, "userdef") && continue
75+ line = line[1+ncodeunits("userdef "):end]
76+ components = split(line, '\t', keepempty=false)
77+ if length(components) ∉ 4:5
78+ @warn "Malformed line: $(sprint(show, line))"
79+ continue
80+ end
81+ code, type, _, description, _... = components
82+ if code == "xm"
83+ components[3] == "-" || continue
84+ description = "mouse response"
85+ end
86+ dtype = get(Dict("bool" => "Bool", "num" => "Int", "str" => "String"), type, nothing)
87+ if isnothing(dtype)
88+ @warn "Unrecognised data type: $type"
89+ continue
90+ end
91+ push!(TERM_USER, (dtype, code, description))
92+ end
93+
94+ push!(TERM_USER, ("Bool", "Tc", "tmux extension to indicate 24-bit truecolor support"))
95+
6996const SENTINEL = "\n## GENERATED CODE BEYOND THIS POINT ##"
7097const PREAMBLE = readuntil(__FILE__, SENTINEL, keep=true)
7198
@@ -87,6 +114,37 @@ for (ftype, list) in [("flag", TERM_FLAGS), ("number", TERM_NUMBERS), ("string",
87114 println(out, "\n]")
88115end
89116
117+ function getcustomalias(allterms::Vector{NTuple{3, String}}, type, short, description)
118+ specific_aliases = Dict{String, String}(
119+ "smxx" => ":enter_strikeout_mode",
120+ "rmxx" => ":exit_strikeout_mode",
121+ "Smol" => ":enter_overline_mode",
122+ "Rmol" => ":exit_overline_mode",
123+ "Cs" => ":set_cursor_color",
124+ "Cr" => ":reset_cursor_color",
125+ "Ss" => ":set_cursor_style",
126+ "Se" => ":reset_cursor_style",
127+ "Smulx" => ":set_underline_style",
128+ "Su" => ":can_style_underline",
129+ "csl" => ":clear_status_line",
130+ "Ms" => ":set_host_clipboard",
131+ "Tc" => ":truecolor")
132+ if startswith(short, 'k') && !occursin("keypad", description)
133+ return ":key_" * replace(lowercase(description), r"[^a-z]" => '_')
134+ end
135+ return get(specific_aliases, short, "nothing")
136+ end
137+
138+ print(out, "\n\"\"\"\nTerminfo extensions that NCurses $NCURSES_VERSION is aware of.\n\"\"\"",
139+ "\nconst TERM_USER = Dict{Tuple{DataType, Symbol}, Union{Tuple{Nothing, String}, Tuple{Symbol, String}}}(")
140+ shortpad = maximum(textwidth, getindex.(TERM_USER, 2)) + 1
141+ for (type, short, description) in TERM_USER
142+ print(out, "\n ($(rpad(type * ',', 7)) :$short)", ' '^(shortpad - textwidth(short)),
143+ "=> (", getcustomalias(TERM_USER, type, short, description), ", \"",
144+ escape_string(description), "\"),")
145+ end
146+ println(out, "\n)")
147+
90148open(io -> write(io, seekstart(out)), __FILE__, "w")
91149
92150end
@@ -610,3 +668,112 @@ const TERM_STRINGS = [
610668 TermCapability (:memory_unlock , :memu , " unlock memory" ),
611669 TermCapability (:box_chars_1 , :box1 , " box characters primary set" ),
612670]
671+
672+ """
673+ Terminfo extensions that NCurses 6.4 is aware of.
674+ """
675+ const TERM_USER = Dict {Tuple{DataType, Symbol}, Union{Tuple{Nothing, String}, Tuple{Symbol, String}}} (
676+ (Int, :CO ) => (nothing , " number of indexed colors overlaying RGB space" ),
677+ (String, :E3 ) => (nothing , " clears the terminal's scrollback buffer." ),
678+ (Bool, :NQ ) => (nothing , " terminal does not support query/response" ),
679+ (Bool, :RGB ) => (nothing , " use direct colors with 1/3 of color-pair bits per color." ),
680+ (Int, :RGB ) => (nothing , " use direct colors with given number of bits per color." ),
681+ (String, :RGB ) => (nothing , " use direct colors with given bit-layout." ),
682+ (String, :TS ) => (nothing , " like \" tsl\" , but uses no parameter." ),
683+ (Int, :U8 ) => (nothing , " terminal does/does not support VT100 SI/SO when processing UTF-8 encoding." ),
684+ (String, :XM ) => (nothing , " initialize alternate xterm mouse mode" ),
685+ (String, :grbom ) => (nothing , " disable real bold (not intensity bright) mode." ),
686+ (String, :gsbom ) => (nothing , " enable real bold (not intensity bright) mode." ),
687+ (String, :xm ) => (nothing , " mouse response" ),
688+ (String, :Rmol ) => (:exit_overline_mode , " remove overline-mode" ),
689+ (String, :Smol ) => (:enter_overline_mode , " set overline-mode" ),
690+ (String, :blink2 ) => (nothing , " turn on rapid blinking" ),
691+ (String, :norm ) => (nothing , " turn off bold and half-bright mode" ),
692+ (String, :opaq ) => (nothing , " turn off blank mode" ),
693+ (String, :setal ) => (nothing , " set underline-color" ),
694+ (String, :smul2 ) => (nothing , " begin double underline mode" ),
695+ (Bool, :AN ) => (nothing , " turn on autonuke." ),
696+ (Bool, :AX ) => (nothing , " understands ANSI set default fg/bg color (\\ E[39m / \\ E[49m)." ),
697+ (String, :C0 ) => (nothing , " use the string as a conversion table for font '0', like acsc." ),
698+ (Bool, :C8 ) => (nothing , " terminal shows bold as high-intensity colors." ),
699+ (String, :CE ) => (nothing , " switch cursor-keys back to normal mode." ),
700+ (String, :CS ) => (nothing , " switch cursor-keys to application mode." ),
701+ (String, :E0 ) => (nothing , " switch charset 'G0' back to standard charset. Default is '\\ E(B'." ),
702+ (Bool, :G0 ) => (nothing , " terminal can deal with ISO 2022 font selection sequences." ),
703+ (String, :KJ ) => (nothing , " set the encoding of the terminal." ),
704+ (Int, :OL ) => (nothing , " set the screen program's output buffer limit." ),
705+ (String, :S0 ) => (nothing , " switch charset 'G0' to the specified charset. Default is '\\ E(%.'." ),
706+ (Bool, :TF ) => (nothing , " add missing capabilities to screen's termcap/info entry. (Set by default)." ),
707+ (String, :WS ) => (nothing , " resize display. This capability has the desired width and height as arguments. SunView(tm) example: '\\ E[8;%d;%dt'." ),
708+ (String, :XC ) => (nothing , " describe a translation of characters to strings depending on the current font." ),
709+ (Bool, :XT ) => (nothing , " terminal understands special xterm sequences (OSC, mouse tracking)." ),
710+ (String, :Z0 ) => (nothing , " change width to 132 columns." ),
711+ (String, :Z1 ) => (nothing , " change width to 80 columns." ),
712+ (String, :Cr ) => (:reset_cursor_color , " restore the default cursor color." ),
713+ (String, :Cs ) => (:set_cursor_color , " set the cursor color." ),
714+ (String, :Csr ) => (nothing , " change the cursor style, overriding Ss." ),
715+ (String, :Ms ) => (:set_host_clipboard , " store the current buffer in the host terminal's selection (clipboard)." ),
716+ (String, :Se ) => (:reset_cursor_style , " reset the cursor style to the terminal initial state." ),
717+ (String, :Smulx ) => (:set_underline_style , " modify the appearance of underlines in VTE." ),
718+ (String, :Ss ) => (:set_cursor_style , " change the cursor style." ),
719+ (String, :rmxx ) => (:exit_strikeout_mode , " reset ECMA-48 strikeout/crossed-out attributes." ),
720+ (String, :smxx ) => (:enter_strikeout_mode , " set ECMA-48 strikeout/crossed-out attributes." ),
721+ (String, :csl ) => (:clear_status_line , " clear status line" ),
722+ (String, :kDC3 ) => (:key_alt_delete_character , " alt delete-character" ),
723+ (String, :kDC4 ) => (:key_shift_alt_delete_character , " shift+alt delete-character" ),
724+ (String, :kDC5 ) => (:key_control_delete_character , " control delete-character" ),
725+ (String, :kDC6 ) => (:key_shift_control_delete_character , " shift+control delete-character" ),
726+ (String, :kDC7 ) => (:key_alt_control_delete_character , " alt+control delete-character" ),
727+ (String, :kDN ) => (:key_shift_down_cursor , " shift down-cursor" ),
728+ (String, :kDN3 ) => (:key_alt_down_cursor , " alt down-cursor" ),
729+ (String, :kDN4 ) => (:key_shift_alt_down_cursor , " shift+alt down-cursor" ),
730+ (String, :kDN5 ) => (:key_control_down_cursor , " control down-cursor" ),
731+ (String, :kDN6 ) => (:key_shift_control_down_cursor , " shift+control down-cursor" ),
732+ (String, :kDN7 ) => (:key_alt_control_down_cursor , " alt+control down-cursor" ),
733+ (String, :kEND3 ) => (:key_alt_end , " alt end" ),
734+ (String, :kEND4 ) => (:key_shift_alt_end , " shift+alt end" ),
735+ (String, :kEND5 ) => (:key_control_end , " control end" ),
736+ (String, :kEND6 ) => (:key_shift_control_end , " shift+control end" ),
737+ (String, :kEND7 ) => (:key_alt_control_end , " alt+control end" ),
738+ (String, :kHOM3 ) => (:key_alt_home , " alt home" ),
739+ (String, :kHOM4 ) => (:key_shift_alt_home , " shift+alt home" ),
740+ (String, :kHOM5 ) => (:key_control_home , " control home" ),
741+ (String, :kHOM6 ) => (:key_shift_control_home , " shift+control home" ),
742+ (String, :kHOM7 ) => (:key_alt_control_home , " alt+control home" ),
743+ (String, :kIC3 ) => (:key_alt_insert_character , " alt insert-character" ),
744+ (String, :kIC4 ) => (:key_shift_alt_insert_character , " shift+alt insert-character" ),
745+ (String, :kIC5 ) => (:key_control_insert_character , " control insert-character" ),
746+ (String, :kIC6 ) => (:key_shift_control_insert_character , " shift+control insert-character" ),
747+ (String, :kIC7 ) => (:key_alt_control_insert_character , " alt+control insert-character" ),
748+ (String, :kLFT3 ) => (:key_alt_left_cursor , " alt left-cursor" ),
749+ (String, :kLFT4 ) => (:key_shift_alt_left_cursor , " shift+alt left-cursor" ),
750+ (String, :kLFT5 ) => (:key_control_left_cursor , " control left-cursor" ),
751+ (String, :kLFT6 ) => (:key_shift_control_left_cursor , " shift+control left-cursor" ),
752+ (String, :kLFT7 ) => (:key_alt_control_left_cursor , " alt+control left-cursor" ),
753+ (String, :kNXT3 ) => (:key_alt_next , " alt next" ),
754+ (String, :kNXT4 ) => (:key_shift_alt_next , " shift+alt next" ),
755+ (String, :kNXT5 ) => (:key_control_next , " control next" ),
756+ (String, :kNXT6 ) => (:key_shift_control_next , " shift+control next" ),
757+ (String, :kNXT7 ) => (:key_alt_control_next , " alt+control next" ),
758+ (String, :kPRV3 ) => (:key_alt_previous , " alt previous" ),
759+ (String, :kPRV4 ) => (:key_shift_alt_previous , " shift+alt previous" ),
760+ (String, :kPRV5 ) => (:key_control_previous , " control previous" ),
761+ (String, :kPRV6 ) => (:key_shift_control_previous , " shift+control previous" ),
762+ (String, :kPRV7 ) => (:key_alt_control_previous , " alt+control previous" ),
763+ (String, :kRIT3 ) => (:key_alt_right_cursor , " alt right-cursor" ),
764+ (String, :kRIT4 ) => (:key_shift_alt_right_cursor , " shift+alt right-cursor" ),
765+ (String, :kRIT5 ) => (:key_control_right_cursor , " control right-cursor" ),
766+ (String, :kRIT6 ) => (:key_shift_control_right_cursor , " shift+control right-cursor" ),
767+ (String, :kRIT7 ) => (:key_alt_control_right_cursor , " alt+control right-cursor" ),
768+ (String, :kUP ) => (:key_shift_up_cursor , " shift up-cursor" ),
769+ (String, :kUP3 ) => (:key_alt_up_cursor , " alt up-cursor" ),
770+ (String, :kUP4 ) => (:key_shift_alt_up_cursor , " shift+alt up-cursor" ),
771+ (String, :kUP5 ) => (:key_control_up_cursor , " control up-cursor" ),
772+ (String, :kUP6 ) => (:key_shift_control_up_cursor , " shift+control up-cursor" ),
773+ (String, :kUP7 ) => (:key_alt_control_up_cursor , " alt+control up-cursor" ),
774+ (String, :ka2 ) => (nothing , " vt220-keypad extensions" ),
775+ (String, :kb1 ) => (nothing , " vt220-keypad extensions" ),
776+ (String, :kb3 ) => (nothing , " vt220-keypad extensions" ),
777+ (String, :kc2 ) => (nothing , " vt220-keypad extensions" ),
778+ (Bool, :Tc ) => (:truecolor , " tmux extension to indicate 24-bit truecolor support" ),
779+ )
0 commit comments