| 1 | package # hide from PAUSE | ||
| 2 | App::DBBrowser::Options::Menus; | ||
| 3 | |||
| 4 | use warnings; | ||
| 5 | use strict; | ||
| 6 | use 5.016; | ||
| 7 | |||
| 8 | use File::Basename qw( fileparse ); | ||
| 9 | use File::Spec::Functions qw( catfile ); | ||
| 10 | |||
| 11 | use Term::Choose qw(); | ||
| 12 | use Term::Choose::Util qw( insert_sep ); | ||
| 13 | use Term::Form qw(); | ||
| 14 | |||
| 15 | |||
| 16 | sub new { | ||
| 17 | my ( $class, $info, $options ) = @_; | ||
| 18 | bless { | ||
| 19 | i => $info, | ||
| 20 | o => $options, | ||
| 21 | }, $class; | ||
| 22 | } | ||
| 23 | |||
| 24 | |||
| 25 | sub groups { | ||
| 26 | my ( $sf, $plugin, $select_plugins ) = @_; | ||
| 27 | my $groups; | ||
| 28 | if ( $select_plugins ) { | ||
| 29 | $groups = [ | ||
| 30 | { name => 'group_select_plugins', text => "- Plugins" }, | ||
| 31 | ]; | ||
| 32 | } | ||
| 33 | elsif ( $plugin ) { | ||
| 34 | $groups = [ | ||
| 35 | { name => 'group_connect', text => "- Connect data" }, ## | ||
| 36 | { name => 'group_extensions', text => "- Extensions" }, | ||
| 37 | { name => 'group_sql_settings', text => "- SQL settings" }, | ||
| 38 | { name => 'group_create_table', text => "- Create table" }, | ||
| 39 | { name => 'group_output', text => "- Output" }, | ||
| 40 | { name => 'group_import', text => "- Import" }, | ||
| 41 | { name => 'group_export', text => "- Export" }, | ||
| 42 | { name => 'group_misc', text => "- Misc" }, | ||
| 43 | ]; | ||
| 44 | } | ||
| 45 | else { | ||
| 46 | $groups = [ | ||
| 47 | { name => 'group_global', text => "- Global settings" }, | ||
| 48 | ]; | ||
| 49 | } | ||
| 50 | return $groups; | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 54 | sub sub_groups { | ||
| 55 | my ( $sf, $group, $driver ) = @_; | ||
| 56 | if ( $group eq 'group_connect' ) { | ||
| 57 | if ( $driver =~ /^(?:SQLite|DuckDB)\z/ ) { | ||
| 58 | return [ | ||
| 59 | { name => '_read_attributes', text => "- Read attributes", section => 'connect_attr' }, | ||
| 60 | { name => '_set_attributes', text => "- Set attributes", section => 'connect_attr' }, | ||
| 61 | ]; | ||
| 62 | } | ||
| 63 | else { | ||
| 64 | return [ | ||
| 65 | { name => '_required_fields', text => "- Required fields", section => 'connect_data' }, | ||
| 66 | { name => '_login_data', text => "- Login data", section => 'connect_data' }, | ||
| 67 | { name => '_env_variables', text => "- ENV variables", section => 'connect_data' }, | ||
| 68 | { name => '_read_attributes', text => "- Read attributes", section => 'connect_attr' }, | ||
| 69 | { name => '_set_attributes', text => "- Set attributes", section => 'connect_attr' }, | ||
| 70 | ]; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | my $groups = { | ||
| 74 | group_extensions => [ | ||
| 75 | { name => '_e_table', text => "- Tables menu", section => 'enable' }, | ||
| 76 | { name => '_e_join', text => "- Join menu", section => 'enable' }, | ||
| 77 | { name => '_e_union', text => "- Union menu", section => 'enable' }, | ||
| 78 | { name => '_e_expressions', text => "- Columns and Values", section => 'enable' }, | ||
| 79 | { name => '_e_write_access', text => "- Write access", section => 'enable' }, | ||
| 80 | ], | ||
| 81 | group_sql_settings => [ | ||
| 82 | { name => '_meta', text => "- System data", section => 'G' }, | ||
| 83 | { name => 'operators', text => "- Operators", section => 'G' }, | ||
| 84 | { name => '_add_aliases', text => "- Add aliases", section => 'alias' }, | ||
| 85 | { name => '_aliases_in_clauses', text => "- Alias in clauses", section => 'alias' }, | ||
| 86 | { name => '_sql_identifiers', text => "- Identifiers", section => 'G' }, | ||
| 87 | { name => '_view_name_prefix', text => "- View prefix", section => 'create' }, ## | ||
| 88 | { name => '_other_sql_settings', text => "- Other", section => 'G' }, | ||
| 89 | ], | ||
| 90 | group_create_table => [ | ||
| 91 | { name => '_enable_ct_opt', text => "- Enable options", section => 'create' }, | ||
| 92 | { name => '_add_ct_fields', text => "- Add form fields", section => 'create' }, | ||
| 93 | { name => '_default_ai_column_name', text => "- Default auto increment column name", section => 'create' }, ## | ||
| 94 | ], | ||
| 95 | group_output => [ | ||
| 96 | { name => '_binary_filter', text => "- Binary filter", section => 'table' }, | ||
| 97 | { name => '_squash_spaces', text => "- Squash spaces", section => 'table' }, | ||
| 98 | { name => '_set_string', text => "- Undef string", section => 'table' }, | ||
| 99 | { name => '_color', text => "- Color", section => 'table' }, | ||
| 100 | { name => 'trunc_fract_first', text => "- Trunc fract first", section => 'table' }, | ||
| 101 | { name => '_base_indent', text => "- Indentation SQL", section => 'G' }, | ||
| 102 | { name => '_pad_row_edges', text => "- Pad row edges", section => 'table' }, | ||
| 103 | { name => 'tab_width', text => "- Tab width", section => 'table' }, | ||
| 104 | { name => '_expand_rows', text => "- Expand table rows", section => 'table' }, | ||
| 105 | { name => '_expanded_line_spacing', text => "- Expanded rows line spacing", section => 'table' }, | ||
| 106 | { name => 'expanded_max_width', text => "- Expanded rows max width", section => 'table' }, | ||
| 107 | { name => 'col_trim_threshold', text => "- Column trim threshold", section => 'table' }, | ||
| 108 | ], | ||
| 109 | group_import => [ | ||
| 110 | { name => '_parse_file', text => "- Parse tool", section => 'insert' }, | ||
| 111 | { name => '_csv_in_char', text => "- CSV options a", section => 'csv_in' }, | ||
| 112 | { name => '_csv_in_options', text => "- CSV options b", section => 'csv_in' }, | ||
| 113 | { name => '_split_config', text => "- Settings 'split'", section => 'split' }, | ||
| 114 | { name => '_input_filter', text => "- Input filter", section => 'insert' }, | ||
| 115 | { name => '_empty_to_null', text => "- Empty to null", section => 'insert' }, | ||
| 116 | { name => '_file_encoding_in', text => "- File encoding", section => 'insert' }, | ||
| 117 | { name => '_file_filter', text => "- File filter", section => 'insert' }, | ||
| 118 | { name => '_show_hidden_files', text => "- Hidden files", section => 'insert' }, | ||
| 119 | { name => 'history_dirs', text => "- Directory history", section => 'insert' }, | ||
| 120 | { name => '_data_source_type', text => "- Source type", section => 'insert' }, | ||
| 121 | { name => 'max_cols_plain', text => "- Max cols plain", section => 'insert' }, | ||
| 122 | ], | ||
| 123 | group_export => [ | ||
| 124 | { name => 'export_dir', text => "- Destination folder", section => 'export' }, | ||
| 125 | { name => '_exported_files', text => "- File name", section => 'export' }, | ||
| 126 | { name => '_csv_out_char', text => "- CSV options a out", section => 'csv_out' }, | ||
| 127 | { name => '_csv_out_options', text => "- CSV options b out", section => 'csv_out' }, | ||
| 128 | { name => '_file_encoding_out', text => "- File encoding out", section => 'export' }, | ||
| 129 | ], | ||
| 130 | group_misc => [ | ||
| 131 | { name => '_search', text => "- Search", section => 'table' }, | ||
| 132 | { name => '_warnings', text => "- Warnings", section => 'G' }, | ||
| 133 | { name => 'progress_bar', text => "- Progress bar", section => 'table' }, | ||
| 134 | ], | ||
| 135 | group_global => [ | ||
| 136 | { name => '_menu_memory', text => "- Menu memory", section => 'G' }, | ||
| 137 | { name => '_mouse', text => "- Mouse mode", section => 'table' }, | ||
| 138 | ], | ||
| 139 | group_select_plugins => [ | ||
| 140 | { name => 'plugins', text => "- Select plugins", section => 'G' }, | ||
| 141 | ], | ||
| 142 | }; | ||
| 143 | if ( $driver eq 'DB2' ) { | ||
| 144 | push @{$groups->{group_output}}, { name => '_db2_encoding', text => "- DB2 encoding", section => 'G' }; | ||
| 145 | } | ||
| 146 | if ( $driver eq 'DuckDB' ) { | ||
| 147 | push @{$groups->{group_output}}, { name => '_duckdb_utf8_decode', text => "- Decode output", section => 'G' }; | ||
| 148 | } | ||
| 149 | return $groups->{$group}; | ||
| 150 | } | ||
| 151 | |||
| 152 | |||
| 153 | my ( $no, $yes ) = ( 'NO', 'YES' ); | ||
| 154 | |||
| 155 | |||
| 156 | sub group_connect { | ||
| 157 | my ( $sf, $info, $lo, $section, $sub_group, $driver ) = @_; | ||
| 158 | my $sub_menu_required_fields = [ | ||
| 159 | [ 'host_required', "- Host required", [ $no, $yes ] ], | ||
| 160 | [ 'port_required', "- Port required", [ $no, $yes ] ], | ||
| 161 | [ 'user_required', "- User required", [ $no, $yes ] ], | ||
| 162 | [ 'pass_required', "- Password required", [ $no, $yes ] ], | ||
| 163 | ]; | ||
| 164 | my $items_login_data = [ | ||
| 165 | { name => 'host', prompt => "- Host" }, | ||
| 166 | { name => 'port', prompt => "- Port" }, | ||
| 167 | { name => 'user', prompt => "- User" }, | ||
| 168 | ]; | ||
| 169 | my $sub_menu_env_variables = [ | ||
| 170 | [ 'use_dbi_host', "- Use DBI_HOST", [ $no, $yes ] ], | ||
| 171 | [ 'use_dbi_port', "- Use DBI_PORT", [ $no, $yes ] ], | ||
| 172 | [ 'use_dbi_user', "- Use DBI_USER", [ $no, $yes ] ], | ||
| 173 | [ 'use_dbi_pass', "- Use DBI_PASS", [ $no, $yes ] ], | ||
| 174 | ]; | ||
| 175 | my $items_read_attributes = [ | ||
| 176 | { name => 'LongReadLen', text => "- LongReadLen" }, | ||
| 177 | ]; | ||
| 178 | my $sub_menu_set_attributes = [ | ||
| 179 | [ 'ChopBlanks', "- ChopBlanks", [ $no, $yes ] ], | ||
| 180 | [ 'LongTruncOk', "- LongTruncOk", [ $no, $yes ] ], | ||
| 181 | ]; | ||
| 182 | |||
| 183 | if ( $driver eq 'SQLite' ) { | ||
| 184 | $sub_menu_required_fields = []; | ||
| 185 | $items_login_data = []; | ||
| 186 | $sub_menu_env_variables = []; | ||
| 187 | push @$items_read_attributes, | ||
| 188 | { name => 'sqlite_busy_timeout', text => "- sqlite_busy_timeout" }; | ||
| 189 | #my $sqlite_string_mode_values = [ | ||
| 190 | # '0 DBD_SQLITE_STRING_MODE_PV', # 0 | ||
| 191 | # '1 DBD_SQLITE_STRING_MODE_BYTES', # 1 | ||
| 192 | # undef, | ||
| 193 | # undef, | ||
| 194 | # '4 DBD_SQLITE_STRING_MODE_UNICODE_NAIVE', # 4 | ||
| 195 | # '5 DBD_SQLITE_STRING_MODE_UNICODE_FALLBACK', # 5 | ||
| 196 | # '6 DBD_SQLITE_STRING_MODE_UNICODE_STRICT', # 6 | ||
| 197 | #]; | ||
| 198 | push @$sub_menu_set_attributes, | ||
| 199 | #[ 'sqlite_string_mode', "- sqlite_string_mode", $sqlite_string_mode_values ], | ||
| 200 | [ 'sqlite_string_mode', "- sqlite_string_mode", [ 0, 1, undef, undef, 4, 5, 6 ] ], # undef not seen by the user | ||
| 201 | [ 'sqlite_see_if_its_a_number', "- sqlite_see_if_its_a_number", [ $no, $yes ] ]; | ||
| 202 | } | ||
| 203 | elsif ( $driver eq 'mysql' ) { | ||
| 204 | push @$sub_menu_set_attributes, | ||
| 205 | [ 'mysql_enable_utf8', "- mysql_enable_utf8", [ $no, $yes ] ], | ||
| 206 | [ 'mysql_enable_utf8mb4', "- mysql_enable_utf8mb4", [ $no, $yes ] ], | ||
| 207 | [ 'mysql_bind_type_guessing', "- mysql_bind_type_guessing", [ $no, $yes ] ]; | ||
| 208 | } | ||
| 209 | elsif ( $driver eq 'MariaDB' ) { | ||
| 210 | push @$sub_menu_set_attributes, | ||
| 211 | [ 'mariadb_bind_type_guessing', "- mariadb_bind_type_guessing", [ $no, $yes ] ]; | ||
| 212 | } | ||
| 213 | elsif ( $driver eq 'Pg' ) { | ||
| 214 | push @$sub_menu_set_attributes, | ||
| 215 | [ 'pg_enable_utf8', "- pg_enable_utf8", [ $no, $yes ] ]; | ||
| 216 | } | ||
| 217 | elsif ( $driver eq 'Firebird' ) { | ||
| 218 | push @$items_read_attributes, | ||
| 219 | { name => 'ib_dialect', text => "- ib_dialect" }, | ||
| 220 | { name => 'ib_role', text => "- ib_role" }, | ||
| 221 | { name => 'ib_charset', text => "- ib_charset" }; | ||
| 222 | push @$sub_menu_set_attributes, | ||
| 223 | [ 'ib_enable_utf8', "- ib_enable_utf8", [ $no, $yes ] ]; | ||
| 224 | } | ||
| 225 | elsif ( $driver eq 'DB2' ) { | ||
| 226 | splice( @$sub_menu_required_fields, 0, 2 ); | ||
| 227 | splice( @$items_login_data, 0, 2 ); | ||
| 228 | splice( @$sub_menu_env_variables, 0, 2 ); | ||
| 229 | } | ||
| 230 | elsif ( $driver eq 'Informix' ) { | ||
| 231 | splice( @$sub_menu_required_fields, 0, 2 ); | ||
| 232 | splice( @$items_login_data, 0, 2 ); | ||
| 233 | splice( @$sub_menu_env_variables, 0, 2 ); | ||
| 234 | push @$sub_menu_set_attributes, | ||
| 235 | [ 'ix_EnableUTF8', "- ix_EnableUTF8", [ $no, $yes ] ]; | ||
| 236 | } | ||
| 237 | elsif ( $driver eq 'Oracle' ) { | ||
| 238 | push @$items_read_attributes, | ||
| 239 | { name => 'ora_charset', text => "- ora_charset" }; | ||
| 240 | push @$sub_menu_set_attributes, | ||
| 241 | [ 'AskIfSID', "- AskIfSID", [ $no, $yes ] ]; | ||
| 242 | } | ||
| 243 | elsif ( $driver eq 'ODBC' ) { | ||
| 244 | splice( @$sub_menu_required_fields, 0, 2 ); | ||
| 245 | splice( @$items_login_data, 0, 2 ); | ||
| 246 | splice( @$sub_menu_env_variables, 0, 2 ); | ||
| 247 | push @$items_read_attributes, | ||
| 248 | { name => 'odbc_batch_size', text => "- odbc_batch_size" }; | ||
| 249 | push @$sub_menu_set_attributes, | ||
| 250 | [ 'odbc_utf8_on', "- odbc_utf8_on", [ $no, $yes ] ], | ||
| 251 | [ 'odbc_ignore_named_placeholders', "- odbc_ignore_named_placeholders", [ $no, $yes ] ], | ||
| 252 | #[ 'odbc_array_operations', "- odbc_array_operations", [ $no, $yes ] ]; | ||
| 253 | } | ||
| 254 | elsif ( $driver eq 'DuckDB' ) { | ||
| 255 | $sub_menu_required_fields = []; | ||
| 256 | $items_login_data = []; | ||
| 257 | $sub_menu_env_variables = []; | ||
| 258 | } | ||
| 259 | if ( $sub_group eq '_required_fields' ) { | ||
| 260 | my $prompt = 'Required Fields:'; | ||
| 261 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu_required_fields, $prompt ); | ||
| 262 | } | ||
| 263 | elsif ( $sub_group eq '_login_data' ) { | ||
| 264 | my $prompt = 'Login Data:'; | ||
| 265 | $sf->__group_readline( $info, $lo, $section, $items_login_data, $prompt ); | ||
| 266 | } | ||
| 267 | elsif ( $sub_group eq '_env_variables' ) { | ||
| 268 | my $prompt = 'Environment Variables:'; | ||
| 269 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu_env_variables, $prompt ); | ||
| 270 | } | ||
| 271 | elsif ( $sub_group eq '_read_attributes' ) { | ||
| 272 | my $prompt = 'Read Attributes:'; | ||
| 273 | $sf->__group_readline( $info, $lo, $section, $items_read_attributes, $prompt ); | ||
| 274 | } | ||
| 275 | elsif ( $sub_group eq '_set_attributes' ) { | ||
| 276 | my $prompt = 'Set Attributes:'; | ||
| 277 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu_set_attributes, $prompt ); | ||
| 278 | } | ||
| 279 | else { | ||
| 280 | die "connect: unknown sub_group $sub_group"; | ||
| 281 | } | ||
| 282 | return; | ||
| 283 | } | ||
| 284 | |||
| 285 | |||
| 286 | sub group_extensions { | ||
| 287 | my ( $sf, $info, $lo, $section, $sub_group ) = @_; | ||
| 288 | if ( $sub_group eq '_e_table' ) { | ||
| 289 | my $prompt = 'Extend tables menu:'; | ||
| 290 | my $sub_menu = [ | ||
| 291 | [ 'm_derived', "- Add subquery", [ $no, $yes ] ], | ||
| 292 | [ 'm_cte', "- Add cte", [ $no, $yes ] ], | ||
| 293 | [ 'join', "- Add join", [ $no, $yes ] ], | ||
| 294 | [ 'union', "- Add union", [ $no, $yes ] ], | ||
| 295 | ]; | ||
| 296 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 297 | } | ||
| 298 | elsif ( $sub_group eq '_e_join' ) { | ||
| 299 | my $prompt = 'Extend join menu:'; | ||
| 300 | my $sub_menu = [ | ||
| 301 | [ 'j_derived', "- Add subquery", [ $no, $yes ] ], | ||
| 302 | [ 'j_cte', "- Add cte", [ $no, $yes ] ], | ||
| 303 | ]; | ||
| 304 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 305 | } | ||
| 306 | elsif ( $sub_group eq '_e_union' ) { | ||
| 307 | my $prompt = 'Extend union menu:'; | ||
| 308 | my $sub_menu = [ | ||
| 309 | [ 'u_derived', "- Add subquery", [ $no, $yes ] ], | ||
| 310 | [ 'u_cte', "- Add cte", [ $no, $yes ] ], | ||
| 311 | [ 'u_edit_stmt', "- Edit statement", [ $no, $yes ] ], | ||
| 312 | [ 'u_parentheses', "- Parentheses", [ $no, $yes ] ], | ||
| 313 | ]; | ||
| 314 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 315 | } | ||
| 316 | elsif ( $sub_group eq '_e_expressions' ) { | ||
| 317 | my $prompt = 'Extended expressions:'; | ||
| 318 | my $sub_menu = [ | ||
| 319 | [ 'extended_cols', "- Exdented columns", [ $no, $yes ] ], | ||
| 320 | [ 'extended_values', "- Exdented values", [ $no, $yes ] ], | ||
| 321 | [ 'extended_args', "- Exdented arguments", [ $no, $yes ] ], | ||
| 322 | ]; | ||
| 323 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 324 | } | ||
| 325 | elsif ( $sub_group eq '_e_write_access' ) { | ||
| 326 | my $prompt = 'Write access: '; | ||
| 327 | my $sub_menu = [ | ||
| 328 | [ 'insert_into', "- Insert records", [ $no, $yes ] ], | ||
| 329 | [ 'update', "- Update records", [ $no, $yes ] ], | ||
| 330 | [ 'delete', "- Delete records", [ $no, $yes ] ], | ||
| 331 | [ 'create_table', "- Create table", [ $no, $yes ] ], | ||
| 332 | [ 'drop_table', "- Drop table", [ $no, $yes ] ], | ||
| 333 | [ 'create_view', "- Create view", [ $no, $yes ] ], | ||
| 334 | [ 'drop_view', "- Drop view", [ $no, $yes ] ], | ||
| 335 | ]; | ||
| 336 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 337 | } | ||
| 338 | else { | ||
| 339 | die "extensions: unknown sub_group $sub_group"; | ||
| 340 | } | ||
| 341 | return; | ||
| 342 | } | ||
| 343 | |||
| 344 | |||
| 345 | sub group_sql_settings { | ||
| 346 | my ( $sf, $info, $lo, $section, $sub_group, $driver ) = @_; | ||
| 347 | if ( $sub_group eq '_meta' ) { | ||
| 348 | my $prompt = 'System data '; | ||
| 349 | my $sub_menu = [ | ||
| 350 | [ 'metadata', "- Show system DB/schemas/tables", [ $no, $yes ] ] | ||
| 351 | ]; | ||
| 352 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 353 | } | ||
| 354 | elsif ( $sub_group eq 'operators' ) { | ||
| 355 | my $prompt = 'Choose operators'; | ||
| 356 | my $avail_operators = [ | ||
| 357 | " = ", " != ", " <> ", " < ", " > ", " >= ", " <= ", | ||
| 358 | "REGEXP", "REGEXP_i", "NOT REGEXP", "NOT REGEXP_i", "LIKE", "NOT LIKE", | ||
| 359 | "IS NULL", "IS NOT NULL", "IN", "NOT IN", "BETWEEN", "NOT BETWEEN", | ||
| 360 | "ANY", "ALL", | ||
| 361 | ]; | ||
| 362 | $sf->__choose_a_subset_wrap( $info, $lo, $section, $sub_group, $avail_operators, $prompt ); | ||
| 363 | } | ||
| 364 | elsif ( $sub_group eq '_add_aliases' ) { | ||
| 365 | my $prompt = 'Add alias:'; | ||
| 366 | my $sub_menu = [ | ||
| 367 | [ 'complex_cols_select', "- Functions/Subqueries in select", [ 'NO', undef, 'ASK', undef ] ], | ||
| 368 | [ 'tables_in_join', "- Tables in join", [ undef, 'AUTO', undef, 'ASK/AUTO' ] ], | ||
| 369 | [ 'join_columns', "- Non-unique columns in join", [ 'NO', 'AUTO', 'ASK', 'ASK/AUTO' ] ], | ||
| 370 | [ 'derived_table', "- Derived table", [ 'NO', 'AUTO', 'ASK', 'ASK/AUTO' ] ], | ||
| 371 | [ 'ordinary_table', "- Ordinary table", [ 'NO', 'AUTO', 'ASK', 'ASK/AUTO' ] ], | ||
| 372 | ]; | ||
| 373 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 374 | } | ||
| 375 | elsif ( $sub_group eq '_aliases_in_clauses' ) { | ||
| 376 | my $prompt = 'Use aliases in: '; | ||
| 377 | my $sub_menu = [ | ||
| 378 | [ 'use_in_group_by', "- Group by", [ $no, $yes ] ], | ||
| 379 | [ 'use_in_having', "- Having", [ $no, $yes ] ], | ||
| 380 | [ 'use_in_order_by', "- Order by", [ $no, $yes ] ], | ||
| 381 | ]; | ||
| 382 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 383 | } | ||
| 384 | elsif ( $sub_group eq '_sql_identifiers' ) { | ||
| 385 | my $prompt = 'Your choice: '; | ||
| 386 | my $sub_menu = [ | ||
| 387 | [ 'qualified_table_name', "- Qualified table names", [ $no, $yes ] ], | ||
| 388 | [ 'quote_tables', "- Quote table names", [ $no, $yes ] ], | ||
| 389 | [ 'quote_columns', "- Quote column names", [ $no, $yes ] ], | ||
| 390 | ]; | ||
| 391 | if ( $driver eq 'Firebird' ) { | ||
| 392 | shift @$sub_menu; | ||
| 393 | } | ||
| 394 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 395 | } | ||
| 396 | elsif ( $sub_group eq '_view_name_prefix' ) { | ||
| 397 | my $items = [ | ||
| 398 | { name => 'view_name_prefix', prompt => "View name prefix" }, | ||
| 399 | ]; | ||
| 400 | my $prompt = 'Set a view name prefix'; | ||
| 401 | $sf->__group_readline( $info, $lo, $section, $items, $prompt ); | ||
| 402 | } | ||
| 403 | elsif ( $sub_group eq '_other_sql_settings' ) { | ||
| 404 | my $prompt = 'Your choice: '; | ||
| 405 | my $sub_menu = [ | ||
| 406 | [ 'edit_sql_menu_sq', "- Subqueries created with 'SQL Menu': Allow editing.", [ $no, $yes ] ], | ||
| 407 | ]; | ||
| 408 | if ( $driver eq 'Pg' ) { | ||
| 409 | push @$sub_menu, [ 'pg_autocast', "- Pg: Convert to 'text' automatically when required.", [ $no, $yes ] ]; | ||
| 410 | } | ||
| 411 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 412 | } | ||
| 413 | else { | ||
| 414 | die "sql_settings: unknown sub_group $sub_group"; | ||
| 415 | } | ||
| 416 | return; | ||
| 417 | } | ||
| 418 | |||
| 419 | |||
| 420 | sub group_create_table { | ||
| 421 | my ( $sf, $info, $lo, $section, $sub_group ) = @_; | ||
| 422 | if ( $sub_group eq '_enable_ct_opt' ) { | ||
| 423 | my $prompt = 'Activate options'; | ||
| 424 | my $sub_menu = [ | ||
| 425 | [ 'option_ai_column_enabled', "- Offer auto increment column", [ $no, $yes ] ], | ||
| 426 | [ 'data_type_guessing', "- Data type guessing", [ $no, $yes ] ], | ||
| 427 | [ 'encode_for_data_type_guessing', "- Encode for data type guessing", [ $no, $yes ] ], | ||
| 428 | ]; | ||
| 429 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 430 | } | ||
| 431 | elsif ( $sub_group eq '_add_ct_fields' ) { | ||
| 432 | my $prompt = 'Add fields'; | ||
| 433 | my $sub_menu = [ | ||
| 434 | [ 'table_constraint_rows', "- Table constraint fields", [ 0 .. 9 ] ], | ||
| 435 | [ 'table_option_rows', "- Table option fields", [ 0 .. 9 ] ], | ||
| 436 | ]; | ||
| 437 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 438 | } | ||
| 439 | elsif ( $sub_group eq '_default_ai_column_name' ) { | ||
| 440 | my $items = [ | ||
| 441 | { name => 'default_ai_column_name', prompt => "Default primary key auto increment column name" }, | ||
| 442 | ]; | ||
| 443 | my $prompt = 'Set a default auto increment column name'; | ||
| 444 | $sf->__group_readline( $info, $lo, $section, $items, $prompt ); | ||
| 445 | } | ||
| 446 | else { | ||
| 447 | die "create_table: unknown sub_group $sub_group"; | ||
| 448 | } | ||
| 449 | return; | ||
| 450 | } | ||
| 451 | |||
| 452 | |||
| 453 | sub group_output { | ||
| 454 | my ( $sf, $info, $lo, $section, $sub_group ) = @_; | ||
| 455 | if ( $sub_group eq '_binary_filter' ) { | ||
| 456 | my $prompt = 'How to print arbitrary binray data'; | ||
| 457 | my $sub_menu = [ | ||
| 458 | [ 'binary_filter', "- Binary filter", [ $no, 'BNRY', 'Hexadecimal' ] ] | ||
| 459 | ]; | ||
| 460 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 461 | } | ||
| 462 | elsif ( $sub_group eq '_squash_spaces' ) { | ||
| 463 | my $prompt = 'Remove leading and trailing spaces and squash consecutive spaces'; | ||
| 464 | my $sub_menu = [ | ||
| 465 | [ 'squash_spaces', "- Squash spaces", [ $no, $yes ] ] | ||
| 466 | ]; | ||
| 467 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 468 | } | ||
| 469 | elsif ( $sub_group eq '_set_string' ) { | ||
| 470 | my $items = [ | ||
| 471 | { name => 'undef', prompt => "Show undefined fields as" }, | ||
| 472 | ]; | ||
| 473 | my $prompt = 'Undef string'; | ||
| 474 | $sf->__group_readline( $info, $lo, $section, $items, $prompt ); | ||
| 475 | } | ||
| 476 | elsif ( $sub_group eq '_color' ) { | ||
| 477 | my $prompt = '"ANSI color escapes"'; | ||
| 478 | my $sub_menu = [ | ||
| 479 | [ 'color', "- ANSI color escapes", [ $no, $yes ] ] | ||
| 480 | ]; | ||
| 481 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 482 | } | ||
| 483 | elsif ( $sub_group eq 'trunc_fract_first' ) { | ||
| 484 | my $prompt = 'If the terminal is not wide enough:'; | ||
| 485 | my $sub_menu = [ | ||
| 486 | [ 'trunc_fract_first', "- First step: truncate fraction of numbers", [ $no, $yes ] ] | ||
| 487 | ]; | ||
| 488 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 489 | } | ||
| 490 | elsif ( $sub_group eq '_base_indent' ) { | ||
| 491 | my $prompt = 'Set the indentation width for SQL substatements'; | ||
| 492 | my $sub_menu = [ | ||
| 493 | [ 'base_indent', "- Indentation", [ 0, 1, 2, 3, 4 ] ] | ||
| 494 | ]; | ||
| 495 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 496 | } | ||
| 497 | elsif ( $sub_group eq 'tab_width' ) { | ||
| 498 | my $digits = 3; | ||
| 499 | my $prompt = 'Set the tab width '; | ||
| 500 | $sf->__choose_a_number_wrap( $info, $lo, $section, $sub_group, $prompt, $digits, 0 ); | ||
| 501 | } | ||
| 502 | elsif ( $sub_group eq '_pad_row_edges' ) { | ||
| 503 | my $prompt = '"Pad row edges"'; | ||
| 504 | my $sub_menu = [ | ||
| 505 | [ 'pad_row_edges', "- Pad row edges with a space.", [ $no, $yes ] ] | ||
| 506 | ]; | ||
| 507 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 508 | } | ||
| 509 | elsif ( $sub_group eq '_expand_rows' ) { | ||
| 510 | my $prompt = 'Your choice: '; | ||
| 511 | my $sub_menu = [ | ||
| 512 | [ 'table_expand', "- Expand table rows", [ $no, $yes ] ], | ||
| 513 | ]; | ||
| 514 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 515 | } | ||
| 516 | elsif ( $sub_group eq '_expanded_line_spacing' ) { | ||
| 517 | my $prompt = 'Your choice: '; | ||
| 518 | my $sub_menu = [ | ||
| 519 | [ 'expanded_line_spacing', "- Blank line between columns when a row is expanded.", [ $no, $yes ] ], | ||
| 520 | ]; | ||
| 521 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 522 | } | ||
| 523 | elsif ( $sub_group eq 'expanded_max_width' ) { | ||
| 524 | my $digits = 3; | ||
| 525 | my $prompt = 'Maximum width of expanded table rows'; | ||
| 526 | $sf->__choose_a_number_wrap( $info, $lo, $section, $sub_group, $prompt, $digits, 0 ); | ||
| 527 | } | ||
| 528 | elsif ( $sub_group eq 'col_trim_threshold' ) { | ||
| 529 | my $digits = 3; | ||
| 530 | my $prompt = 'Column trim threshold '; | ||
| 531 | $sf->__choose_a_number_wrap( $info, $lo, $section, $sub_group, $prompt, $digits, 0 ); | ||
| 532 | } | ||
| 533 | elsif ( $sub_group eq '_db2_encoding' ) { | ||
| 534 | my $items = [ | ||
| 535 | { name => 'db2_encoding', prompt => "DB2 application code set" }, | ||
| 536 | ]; | ||
| 537 | my $prompt = 'Set the DB2 application code set'; | ||
| 538 | $sf->__group_readline( $info, $lo, $section, $items, $prompt ); | ||
| 539 | } | ||
| 540 | elsif ( $sub_group eq '_duckdb_utf8_decode' ) { | ||
| 541 | my $prompt = 'Your choice: '; | ||
| 542 | my $sub_menu = [ | ||
| 543 | [ 'duckdb_utf8_decode', "- Decode the output of VARCHAR columns as UTF-8.", [ $no, $yes ] ], | ||
| 544 | ]; | ||
| 545 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 546 | } | ||
| 547 | else { | ||
| 548 | die "output: unknown sub_group $sub_group"; | ||
| 549 | } | ||
| 550 | return; | ||
| 551 | } | ||
| 552 | |||
| 553 | |||
| 554 | sub group_import { | ||
| 555 | my ( $sf, $info, $lo, $section, $sub_group ) = @_; | ||
| 556 | if ( $sub_group eq '_data_source_type' ) { | ||
| 557 | my $prompt = 'Data source options'; | ||
| 558 | my $sub_menu = [ | ||
| 559 | [ 'data_source_create_table', "- Data source \"Create table\"", [ 'plain', 'file', 'menu' ], ], | ||
| 560 | [ 'data_source_insert', "- Data source \"Insert into\"", [ 'plain', 'file', 'menu' ], ], | ||
| 561 | ]; | ||
| 562 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 563 | } | ||
| 564 | elsif ( $sub_group eq 'max_cols_plain' ) { | ||
| 565 | my $digits = 2; | ||
| 566 | my $prompt = 'Create table, source plain.' . "\n" . 'Maximum columns:'; | ||
| 567 | $sf->__choose_a_number_wrap( $info, $lo, $section, $sub_group, $prompt, $digits, 1 ); | ||
| 568 | } | ||
| 569 | elsif ( $sub_group eq '_parse_file' ) { | ||
| 570 | my $prompt = 'How to parse input files'; | ||
| 571 | my $sub_menu = [ | ||
| 572 | [ 'parse_mode_input_file', "- Use", [ 'Text::CSV', 'split', 'Template', 'Spreadsheet::Read' ] ], | ||
| 573 | ]; | ||
| 574 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 575 | } | ||
| 576 | elsif ( $sub_group eq '_csv_in_char' ) { | ||
| 577 | my $items = [ | ||
| 578 | { name => 'sep_char', prompt => "sep_char " }, | ||
| 579 | { name => 'quote_char', prompt => "quote_char " }, | ||
| 580 | { name => 'escape_char', prompt => "escape_char" }, | ||
| 581 | { name => 'eol', prompt => "eol " }, | ||
| 582 | { name => 'comment_str', prompt => "comment_str" }, | ||
| 583 | ]; | ||
| 584 | my $prompt = 'Text::CSV_XS options a'; | ||
| 585 | $sf->__group_readline( $info, $lo, $section, $items, $prompt ); | ||
| 586 | } | ||
| 587 | elsif ( $sub_group eq '_csv_in_options' ) { | ||
| 588 | my $prompt = 'Text::CSV_XS options b'; | ||
| 589 | my $sub_menu = [ | ||
| 590 | [ 'allow_loose_escapes', "- allow_loose_escapes", [ $no, $yes ] ], | ||
| 591 | [ 'allow_loose_quotes', "- allow_loose_quotes", [ $no, $yes ] ], | ||
| 592 | [ 'allow_whitespace', "- allow_whitespace", [ $no, $yes ] ], | ||
| 593 | [ 'blank_is_undef', "- blank_is_undef", [ $no, $yes ] ], | ||
| 594 | [ 'binary', "- binary", [ $no, $yes ] ], | ||
| 595 | [ 'decode_utf8', "- decode_utf8", [ $no, $yes ] ], | ||
| 596 | [ 'empty_is_undef', "- empty_is_undef", [ $no, $yes ] ], | ||
| 597 | [ 'skip_empty_rows', "- skip_empty_rows", [ $no, $yes ] ], | ||
| 598 | ]; | ||
| 599 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 600 | } | ||
| 601 | elsif ( $sub_group eq '_split_config' ) { | ||
| 602 | my $items = [ | ||
| 603 | { name => 'field_sep', prompt => "Field separator " }, | ||
| 604 | { name => 'field_l_trim', prompt => "Trim field left " }, | ||
| 605 | { name => 'field_r_trim', prompt => "Trim field right " }, | ||
| 606 | { name => 'record_sep', prompt => "Record separator " }, | ||
| 607 | { name => 'record_l_trim', prompt => "Trim record left " }, | ||
| 608 | { name => 'record_r_trim', prompt => "Trim record right" }, | ||
| 609 | ]; | ||
| 610 | my $prompt = 'Config \'split\' mode'; | ||
| 611 | $sf->__group_readline( $info, $lo, $section, $items, $prompt ); | ||
| 612 | } | ||
| 613 | elsif ( $sub_group eq '_input_filter' ) { | ||
| 614 | my $prompt = 'Enable input filter'; | ||
| 615 | my $sub_menu = [ | ||
| 616 | [ 'enable_input_filter', "- Enable input filter", [ $no, $yes ] ] | ||
| 617 | ]; | ||
| 618 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 619 | } | ||
| 620 | elsif ( $sub_group eq '_empty_to_null' ) { | ||
| 621 | my $prompt = 'Enable "Empty to NULL":'; | ||
| 622 | my $sub_menu = [ | ||
| 623 | [ 'empty_to_null_plain', "- Source type 'plain'", [ $no, $yes ] ], | ||
| 624 | [ 'empty_to_null_file', "- Source type 'file'", [ $no, $yes ] ], | ||
| 625 | ]; | ||
| 626 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 627 | } | ||
| 628 | elsif ( $sub_group eq '_file_encoding_in' ) { | ||
| 629 | my $items = [ | ||
| 630 | { name => 'file_encoding', prompt => "Input file encoding" }, | ||
| 631 | ]; | ||
| 632 | my $prompt = 'Encoding of input data text files'; | ||
| 633 | $sf->__group_readline( $info, $lo, $section, $items, $prompt ); | ||
| 634 | } | ||
| 635 | elsif ( $sub_group eq 'history_dirs' ) { | ||
| 636 | my $digits = 2; | ||
| 637 | my $prompt = 'Number of saved dirs: '; | ||
| 638 | $sf->__choose_a_number_wrap( $info, $lo, $section, $sub_group, $prompt, $digits, 1 ); | ||
| 639 | } | ||
| 640 | elsif ( $sub_group eq '_file_filter' ) { | ||
| 641 | my $items = [ | ||
| 642 | { name => 'file_filter', prompt => "File filter glob pattern" }, | ||
| 643 | ]; | ||
| 644 | my $prompt = 'Set the glob pattern for the file filter'; | ||
| 645 | $sf->__group_readline( $info, $lo, $section, $items, $prompt ); | ||
| 646 | } | ||
| 647 | elsif ( $sub_group eq '_show_hidden_files' ) { | ||
| 648 | my $prompt = 'Show hidden files'; | ||
| 649 | my $sub_menu = [ | ||
| 650 | [ 'show_hidden_files', "- Show hidden files", [ $no, $yes ] ] | ||
| 651 | ]; | ||
| 652 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 653 | } | ||
| 654 | else { | ||
| 655 | die "import: unknown sub_group $sub_group"; | ||
| 656 | } | ||
| 657 | return; | ||
| 658 | } | ||
| 659 | |||
| 660 | |||
| 661 | sub group_export { | ||
| 662 | my ( $sf, $info, $lo, $section, $sub_group ) = @_; | ||
| 663 | if ( $sub_group eq 'export_dir' ) { | ||
| 664 | my $prompt = 'Select the destination folder for data exported as CSV files.'; | ||
| 665 | $sf->__choose_a_directory_wrap( $info, $lo, $section, $sub_group, $prompt ); | ||
| 666 | } | ||
| 667 | elsif ( $sub_group eq '_exported_files' ) { | ||
| 668 | my $prompt = 'Data export to CSV files'; | ||
| 669 | my $sub_menu = [ | ||
| 670 | [ 'add_extension', "- Add automatically '.csv'-extension", [ $no, $yes ] ], | ||
| 671 | [ 'default_filename', "- Table name is default file name", [ $no, $yes ] ] | ||
| 672 | ]; | ||
| 673 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 674 | } | ||
| 675 | elsif ( $sub_group eq '_file_encoding_out' ) { | ||
| 676 | my $items = [ | ||
| 677 | { name => 'file_encoding', prompt => "Encoding CSV file" }, | ||
| 678 | ]; | ||
| 679 | my $prompt = 'Data to CSV-files'; | ||
| 680 | $sf->__group_readline( $info, $lo, $section, $items, $prompt ); | ||
| 681 | } | ||
| 682 | elsif ( $sub_group eq '_csv_out_char' ) { | ||
| 683 | my $items = [ | ||
| 684 | { name => 'sep_char', prompt => "sep_char " }, | ||
| 685 | { name => 'quote_char', prompt => "quote_char " }, | ||
| 686 | { name => 'escape_char', prompt => "escape_char" }, | ||
| 687 | { name => 'eol', prompt => "eol " }, | ||
| 688 | { name => 'undef_str', prompt => "undef_str" }, | ||
| 689 | ]; | ||
| 690 | my $prompt = 'Text::CSV_XS write options a'; | ||
| 691 | $sf->__group_readline( $info, $lo, $section, $items, $prompt ); | ||
| 692 | } | ||
| 693 | elsif ( $sub_group eq '_csv_out_options' ) { | ||
| 694 | my $prompt = 'Text::CSV_XS write options b'; | ||
| 695 | my $sub_menu = [ | ||
| 696 | [ 'always_quote', "- always_quote", [ $no, $yes ] ], | ||
| 697 | [ 'binary', "- binary", [ $no, $yes ] ], | ||
| 698 | [ 'escape_null', "- escape_null", [ $no, $yes ] ], | ||
| 699 | [ 'quote_binary', "- quote_binary", [ $no, $yes ] ], | ||
| 700 | [ 'quote_empty', "- quote_empty", [ $no, $yes ] ], | ||
| 701 | [ 'quote_space', "- quote_space", [ $no, $yes ] ], | ||
| 702 | ]; | ||
| 703 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 704 | } | ||
| 705 | else { | ||
| 706 | die "export: unknown sub_group $sub_group"; | ||
| 707 | } | ||
| 708 | return; | ||
| 709 | } | ||
| 710 | |||
| 711 | |||
| 712 | sub group_misc { | ||
| 713 | my ( $sf, $info, $lo, $section, $sub_group, $driver ) = @_; | ||
| 714 | if ( $sub_group eq '_search' ) { | ||
| 715 | my $prompt = 'Your choice: '; | ||
| 716 | my $sub_menu = [ | ||
| 717 | [ 'search', "- Row filter", [ 'disabled', 'case insensitive', 'case sensitive' ] ] | ||
| 718 | ]; | ||
| 719 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 720 | } | ||
| 721 | elsif ( $sub_group eq '_warnings' ) { | ||
| 722 | my $prompt = '"Disable/Enable warnings"'; | ||
| 723 | my $sub_menu = [ | ||
| 724 | [ 'warnings_table_print', "- Warnings table-print", [ $no, $yes ] ], | ||
| 725 | ]; | ||
| 726 | if ( $driver eq 'SQLite' ) { | ||
| 727 | push @$sub_menu, [ 'file_find_warnings', "- Warnings \"File::Find\" search", [ $no, $yes ] ]; | ||
| 728 | } | ||
| 729 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 730 | } | ||
| 731 | elsif ( $sub_group eq 'progress_bar' ) { | ||
| 732 | my $digits = 7; | ||
| 733 | my $prompt = 'Set the threshold for the progress bar '; | ||
| 734 | $sf->__choose_a_number_wrap( $info, $lo, $section, $sub_group, $prompt, $digits, 0 ); | ||
| 735 | } | ||
| 736 | else { | ||
| 737 | die "misc: unknown sub_group: $sub_group"; | ||
| 738 | } | ||
| 739 | return; | ||
| 740 | } | ||
| 741 | |||
| 742 | |||
| 743 | sub group_global { | ||
| 744 | my ( $sf, $info, $lo, $section, $sub_group ) = @_; | ||
| 745 | if ( $sub_group eq '_menu_memory' ) { | ||
| 746 | my $prompt = 'Your choice: '; | ||
| 747 | my $sub_menu = [ | ||
| 748 | [ 'menu_memory', "- Menu memory", [ $no, $yes ] ], | ||
| 749 | ]; | ||
| 750 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 751 | } | ||
| 752 | elsif ( $sub_group eq '_mouse' ) { | ||
| 753 | my $prompt = 'Your choice: '; | ||
| 754 | my $sub_menu = [ | ||
| 755 | [ 'mouse', "- Mouse mode", [ $no, $yes ] ] | ||
| 756 | ]; | ||
| 757 | $sf->__settings_menu_wrap( $info, $lo, $section, $sub_menu, $prompt ); | ||
| 758 | } | ||
| 759 | else { | ||
| 760 | die "global: unknown sub_group: $sub_group"; | ||
| 761 | } | ||
| 762 | return; | ||
| 763 | } | ||
| 764 | |||
| 765 | |||
| 766 | sub group_select_plugins { | ||
| 767 | my ( $sf, $info, $lo, $section, $sub_group ) = @_; | ||
| 768 | if ( $sub_group eq 'plugins' ) { | ||
| 769 | my %installed_plugins; | ||
| 770 | |||
| 771 | for my $dir ( @INC ) { | ||
| 772 | my $glob_pattern = catfile $dir, 'App', 'DBBrowser', 'DB', '*.pm'; | ||
| 773 | map { $installed_plugins{( fileparse $_, '.pm' )[0]}++ } glob $glob_pattern; | ||
| 774 | } | ||
| 775 | my $avail_plugins = [ sort keys %installed_plugins ]; | ||
| 776 | my $prompt = 'Select plugins'; | ||
| 777 | # $info = undef; | ||
| 778 | $sf->__choose_a_subset_wrap( $info, $lo, $section, $sub_group, $avail_plugins, $prompt ); | ||
| 779 | } | ||
| 780 | else { | ||
| 781 | die "global: unknown sub_group: $sub_group"; | ||
| 782 | } | ||
| 783 | return; | ||
| 784 | } | ||
| 785 | |||
| 786 | |||
| 787 | sub __settings_menu_wrap { | ||
| 788 | # sets the options to the index of the chosen values, not to the values itself | ||
| 789 | my ( $sf, $info, $lo, $section, $sub_menu, $prompt ) = @_; | ||
| 790 | my $tu = Term::Choose::Util->new( $sf->{i}{tcu_default} ); | ||
| 791 | my $changed = $tu->settings_menu( | ||
| 792 | $sub_menu, $lo->{$section}, | ||
| 793 | { info => $info, prompt => $prompt, back => $sf->{i}{_back}, confirm => $sf->{i}{_confirm} } | ||
| 794 | ); | ||
| 795 | } | ||
| 796 | |||
| 797 | |||
| 798 | sub __choose_a_subset_wrap { | ||
| 799 | my ( $sf, $info, $lo, $section, $opt, $available, $prompt ) = @_; | ||
| 800 | my $tu = Term::Choose::Util->new( $sf->{i}{tcu_default} ); | ||
| 801 | my $current = $lo->{$section}{$opt}; | ||
| 802 | $info .= "\n" if length $info; | ||
| 803 | $info .= 'Cur: '; | ||
| 804 | $info .= join( ', ', @$current ) if defined $current; | ||
| 805 | my $name = 'New: '; | ||
| 806 | # Choose_a_list | ||
| 807 | my $list = $tu->choose_a_subset( | ||
| 808 | $available, | ||
| 809 | { info => $info, prompt => $prompt, cs_label => $name, prefix => '- ', keep_chosen => 0, | ||
| 810 | index => 0, confirm => $sf->{i}{_confirm}, back => $sf->{i}{_back}, layout => 2, | ||
| 811 | clear_screen => 1 } | ||
| 812 | ); | ||
| 813 | return if ! defined $list; | ||
| 814 | return if ! @$list; | ||
| 815 | $lo->{$section}{$opt} = $list; | ||
| 816 | return; | ||
| 817 | } | ||
| 818 | |||
| 819 | |||
| 820 | sub __choose_a_number_wrap { | ||
| 821 | my ( $sf, $info, $lo, $section, $opt, $prompt, $digits, $small_first ) = @_; | ||
| 822 | my $tu = Term::Choose::Util->new( $sf->{i}{tcu_default} ); | ||
| 823 | my $current = $lo->{$section}{$opt}; | ||
| 824 | my $w = $digits + int( ( $digits - 1 ) / 3 ) * length $sf->{i}{info_thsd_sep}; | ||
| 825 | $info .= "\n" . 'Cur: '; | ||
| 826 | $info .= sprintf( "%*s", $w, insert_sep( $current, $sf->{i}{info_thsd_sep} ) ) if defined $current; | ||
| 827 | my $name = 'New: '; | ||
| 828 | # Choose_a_number | ||
| 829 | my $choice = $tu->choose_a_number( $digits, | ||
| 830 | { info => $info, prompt => $prompt, cs_label => $name, small_first => $small_first, | ||
| 831 | clear_screen => 1, confirm => $sf->{i}{confirm}, back => $sf->{i}{back} } | ||
| 832 | ); | ||
| 833 | return if ! defined $choice; | ||
| 834 | $lo->{$section}{$opt} = $choice; | ||
| 835 | return; | ||
| 836 | } | ||
| 837 | |||
| 838 | |||
| 839 | sub __choose_a_directory_wrap { | ||
| 840 | my ( $sf, $info, $lo, $section, $opt, $prompt ) = @_; | ||
| 841 | my $tu = Term::Choose::Util->new( $sf->{i}{tcu_default} ); | ||
| 842 | my $current = $lo->{$section}{$opt}; | ||
| 843 | # Choose_a_directory | ||
| 844 | my $choice = $tu->choose_a_directory( | ||
| 845 | { show_hidden => 1, info => $info, prompt => $prompt, clear_screen => 1, decoded => 1, | ||
| 846 | confirm => $sf->{i}{confirm}, back => $sf->{i}{back}, init_dir => $current } | ||
| 847 | ); | ||
| 848 | return if ! defined $choice; | ||
| 849 | $lo->{$section}{$opt} = $choice; | ||
| 850 | return; | ||
| 851 | } | ||
| 852 | |||
| 853 | |||
| 854 | sub __group_readline { | ||
| 855 | my ( $sf, $info, $lo, $section, $items, $prompt ) = @_; | ||
| 856 | my $list = [ map { | ||
| 857 | [ exists $_->{prompt} ? $_->{prompt} : $_->{name}, $lo->{$section}{$_->{name}} ] | ||
| 858 | } @{$items} ]; | ||
| 859 | my $tf = Term::Form->new( $sf->{i}{tf_default} ); | ||
| 860 | # Fill_Form | ||
| 861 | my $new_list = $tf->fill_form( | ||
| 862 | $list, | ||
| 863 | { info => $info, prompt => $prompt, confirm => $sf->{i}{confirm}, back => $sf->{i}{back} } | ||
| 864 | ); | ||
| 865 | if ( $new_list ) { | ||
| 866 | for my $i ( 0 .. $#$items ) { | ||
| 867 | $lo->{$section}{$items->[$i]{name}} = $new_list->[$i][1]; | ||
| 868 | } | ||
| 869 | } | ||
| 870 | } | ||
| 871 | |||
| 872 | |||
| 873 | |||
| 874 | 1; | ||
| 875 | |||
| 876 | |||
| 877 | __END__ |