wibrfake-brk 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.dockerignore +48 -0
- data/.gitattributes +19 -0
- data/.github/dependabot.yml +12 -0
- data/.github/workflows/ci.yml +90 -0
- data/.rubocop.yml +8 -0
- data/.ruby-version +1 -0
- data/Dockerfile +69 -0
- data/Gemfile +68 -0
- data/README.md +188 -0
- data/Rakefile +6 -0
- data/app/assets/config/manifest.js +5 -0
- data/app/assets/images/.keep +0 -0
- data/app/assets/images/2024-12-30-07:58:34-screenshot.png +0 -0
- data/app/assets/images/facebook/facebook-logo.svg +3 -0
- data/app/assets/images/google/googlelogo_color_272x92dp.png +0 -0
- data/app/assets/images/instagram/app-store.png +0 -0
- data/app/assets/images/instagram/google-play.png +0 -0
- data/app/assets/images/instagram/instagram-logo.png +0 -0
- data/app/assets/images/instagram/screenshot1.png +0 -0
- data/app/assets/images/instagram/screenshot2.png +0 -0
- data/app/assets/images/instagram/screenshot3.png +0 -0
- data/app/assets/images/instagram/screenshot4.png +0 -0
- data/app/assets/images/nauta_etecsa/CUBADEBATE.jpg +0 -0
- data/app/assets/images/nauta_etecsa/CUBAEDUCA.jpg +0 -0
- data/app/assets/images/nauta_etecsa/CUBARTE.jpg +0 -0
- data/app/assets/images/nauta_etecsa/CUBASI.jpg +0 -0
- data/app/assets/images/nauta_etecsa/ECURED.jpg +0 -0
- data/app/assets/images/nauta_etecsa/OFERTAS.jpg +0 -0
- data/app/assets/images/nauta_etecsa/PAPELETA.jpg +0 -0
- data/app/assets/images/nauta_etecsa/contenedor_bg.jpg +0 -0
- data/app/assets/images/nauta_etecsa/etecsa.jpg +0 -0
- data/app/assets/images/nauta_etecsa/nauta_wifi.jpg +0 -0
- data/app/assets/images/nauta_hogar/CUBADEBATE.jpg +0 -0
- data/app/assets/images/nauta_hogar/CUBAEDUCA.jpg +0 -0
- data/app/assets/images/nauta_hogar/CUBARTE.jpg +0 -0
- data/app/assets/images/nauta_hogar/CUBASI.jpg +0 -0
- data/app/assets/images/nauta_hogar/ECURED.jpg +0 -0
- data/app/assets/images/nauta_hogar/OFERTAS.jpg +0 -0
- data/app/assets/images/nauta_hogar/PAPELETA.jpg +0 -0
- data/app/assets/images/nauta_hogar/banner_hogar.png +0 -0
- data/app/assets/images/wibrfake/Breaker-Wallpaper1.jpg +0 -0
- data/app/assets/images/wibrfake/mac-list-parameter.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-100x100.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-32x32.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-48x48.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-apfake-on.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-apfake-set-basic.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-apfake-show.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-help.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-hostpot.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-init.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-init2.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-login-basic.jpg +0 -0
- data/app/assets/images/wibrfake/wibrfake-mac-list.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-mac-ramset-oui.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-mac-ramset.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-mac-set.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-mac-show.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-need-signin.jpg +0 -0
- data/app/assets/images/wibrfake/wibrfake-session-active.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-session-init.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-session-list.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-session-new.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-session-rename.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-session-save.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-web-server-apfake.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-web-server-on.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-web-server-show.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-wkdump-loaded.png +0 -0
- data/app/assets/images/wibrfake/wibrfake-wkdump.png +0 -0
- data/app/assets/images/wibrfake/wibrfake.png +0 -0
- data/app/assets/stylesheets/application.css +15 -0
- data/app/assets/stylesheets/basic/page_basic.css +0 -0
- data/app/assets/stylesheets/facebook/page_facebook.css +93 -0
- data/app/assets/stylesheets/google/page_google.css +137 -0
- data/app/assets/stylesheets/instagram/page_instagram.css +94 -0
- data/app/assets/stylesheets/nauta_etecsa/page_nauta.css +325 -0
- data/app/assets/stylesheets/nauta_hogar/page_nauta.css +469 -0
- data/app/assets/stylesheets/wibrfake/page_wibrfake.css +1181 -0
- data/app/assets/stylesheets/wibrfake/page_wibrfake_about.css +486 -0
- data/app/channels/application_cable/channel.rb +4 -0
- data/app/channels/application_cable/connection.rb +4 -0
- data/app/controllers/application_controller.rb +15 -0
- data/app/controllers/concerns/.keep +0 -0
- data/app/controllers/sessions_controller.rb +111 -0
- data/app/helpers/application_helper.rb +2 -0
- data/app/helpers/sessions_helper.rb +2 -0
- data/app/javascript/application.js +3 -0
- data/app/javascript/bootstrap.bundle.min.js +7 -0
- data/app/javascript/controllers/application.js +9 -0
- data/app/javascript/controllers/hello_controller.js +7 -0
- data/app/javascript/controllers/index.js +4 -0
- data/app/javascript/google/page_google.js +50 -0
- data/app/javascript/incorrect3.js +29 -0
- data/app/javascript/page_wibrfake.js +50 -0
- data/app/javascript/page_wibrfake_about.js +147 -0
- data/app/jobs/application_job.rb +7 -0
- data/app/mailers/application_mailer.rb +4 -0
- data/app/models/application_record.rb +3 -0
- data/app/models/concerns/.keep +0 -0
- data/app/models/user.rb +6 -0
- data/app/views/layouts/application.html.erb +33 -0
- data/app/views/layouts/mailer.html.erb +13 -0
- data/app/views/layouts/mailer.text.erb +1 -0
- data/app/views/pwa/manifest.json.erb +22 -0
- data/app/views/pwa/service-worker.js +26 -0
- data/app/views/sessions/basic/basic.html.erb +21 -0
- data/app/views/sessions/facebook/facebook.html.erb +132 -0
- data/app/views/sessions/google/google.html.erb +72 -0
- data/app/views/sessions/index.html.erb +11 -0
- data/app/views/sessions/instagram/instagram.html.erb +69 -0
- data/app/views/sessions/nauta_etecsa/nauta_etecsa.html.erb +97 -0
- data/app/views/sessions/nauta_hogar/nauta_hogar.html.erb +135 -0
- data/app/views/sessions/wibrfake/about/about.html.erb +164 -0
- data/app/views/sessions/wibrfake/wibrfake.html.erb +417 -0
- data/bin/.names.rb.swp +0 -0
- data/bin/brakeman +7 -0
- data/bin/bundle +114 -0
- data/bin/docker-entrypoint +13 -0
- data/bin/google.wkdump +3 -0
- data/bin/importmap +4 -0
- data/bin/rails +4 -0
- data/bin/rake +4 -0
- data/bin/rubocop +8 -0
- data/bin/setup +37 -0
- data/bin/wibrfake +20 -0
- data/config/application.rb +26 -0
- data/config/boot.rb +4 -0
- data/config/cable.yml +10 -0
- data/config/credentials.yml.enc +1 -0
- data/config/database.yml +16 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +85 -0
- data/config/environments/production.rb +105 -0
- data/config/environments/test.rb +67 -0
- data/config/icons/application-x-wkdump.xml +13 -0
- data/config/icons/hicolor/16x16/mimetypes/application-x-wkdump.png +0 -0
- data/config/icons/hicolor/32x32/mimetypes/application-x-wkdump.png +0 -0
- data/config/icons/hicolor/48x48/mimetypes/application-x-wkdump.png +0 -0
- data/config/icons/hicolor/icon-theme.cache +0 -0
- data/config/icons/hicolor/index.theme +20 -0
- data/config/icons/wkdump.desktop +5 -0
- data/config/importmap.rb +7 -0
- data/config/initializers/assets.rb +12 -0
- data/config/initializers/content_security_policy.rb +25 -0
- data/config/initializers/devise.rb +313 -0
- data/config/initializers/filter_parameter_logging.rb +8 -0
- data/config/initializers/inflections.rb +16 -0
- data/config/initializers/permissions_policy.rb +13 -0
- data/config/locales/devise.en.yml +65 -0
- data/config/locales/en.yml +31 -0
- data/config/puma.rb +35 -0
- data/config/routes.rb +12 -0
- data/config/storage.yml +34 -0
- data/config.ru +6 -0
- data/db/development.sqlite3 +0 -0
- data/db/schema.rb +14 -0
- data/ext/wibrfake/extconf.rb +3 -0
- data/ext/wibrfake/wibrfake.h +0 -0
- data/images/ouilist.png +0 -0
- data/images/wibrfakehelp.png +0 -0
- data/images/wibrfakeinit.png +0 -0
- data/lib/assets/.keep +0 -0
- data/lib/tasks/.keep +0 -0
- data/lib/wibrfake/Config/ipaddr.rb +71 -0
- data/lib/wibrfake/Config/options.rb +98 -0
- data/lib/wibrfake/Config/security_wpa.rb +43 -0
- data/lib/wibrfake/DataBase/howuis.db +0 -0
- data/lib/wibrfake/DataBase/ouis.db +0 -0
- data/lib/wibrfake/DataBase/ouis.rb +24 -0
- data/lib/wibrfake/DataBase/rename.rb +15 -0
- data/lib/wibrfake/DataBase/show.rb +18 -0
- data/lib/wibrfake/Dnsmasq/dhcp.rb +149 -0
- data/lib/wibrfake/Dnsmasq/dhcp_prueba.rb +135 -0
- data/lib/wibrfake/Dnsmasq/dns.rb +34 -0
- data/lib/wibrfake/Dnsmasq/dns_prueba.rb +36 -0
- data/lib/wibrfake/Dnsmasq/dnsmasq.rb +33 -0
- data/lib/wibrfake/Listing/apfake.rb +28 -0
- data/lib/wibrfake/Listing/clients.rb +76 -0
- data/lib/wibrfake/Listing/ouis.rb +53 -0
- data/lib/wibrfake/Listing/process.rb +14 -0
- data/lib/wibrfake/Listing/sessions.rb +47 -0
- data/lib/wibrfake/Listing/web_server.rb +17 -0
- data/lib/wibrfake/Listing/wireless.rb +30 -0
- data/lib/wibrfake/Logs/credentials.log +59 -0
- data/lib/wibrfake/NetworkInterface/ip-routing.rb +99 -0
- data/lib/wibrfake/NetworkInterface/mac.rb +114 -0
- data/lib/wibrfake/NetworkInterface/monitor.rb +44 -0
- data/lib/wibrfake/NetworkInterface/ouis.db +0 -0
- data/lib/wibrfake/Process/id.rb +11 -0
- data/lib/wibrfake/Process/pids.log +5 -0
- data/lib/wibrfake/Process/pkill.rb +124 -0
- data/lib/wibrfake/Process/processes.rb +76 -0
- data/lib/wibrfake/Rails/login.rb +20 -0
- data/lib/wibrfake/Rails/routes.rb +76 -0
- data/lib/wibrfake/Rails/service.rb +58 -0
- data/lib/wibrfake/Rails/service_usage.rb +46 -0
- data/lib/wibrfake/Sessions/session.rb +188 -0
- data/lib/wibrfake/String/string.rb +109 -0
- data/lib/wibrfake/Tmp/config.yml +1 -0
- data/lib/wibrfake/config.rb +24 -0
- data/lib/wibrfake/help.rb +107 -0
- data/lib/wibrfake/optionpr.rb +68 -0
- data/lib/wibrfake/run.rb +9 -0
- data/lib/wibrfake/ty/apld.rb +110 -0
- data/lib/wibrfake/ty/prompt/answers_collector.rb +78 -0
- data/lib/wibrfake/ty/prompt/block_paginator.rb +59 -0
- data/lib/wibrfake/ty/prompt/choice.rb +147 -0
- data/lib/wibrfake/ty/prompt/choices.rb +129 -0
- data/lib/wibrfake/ty/prompt/confirm_question.rb +158 -0
- data/lib/wibrfake/ty/prompt/const.rb +17 -0
- data/lib/wibrfake/ty/prompt/converter_dsl.rb +21 -0
- data/lib/wibrfake/ty/prompt/converter_registry.rb +69 -0
- data/lib/wibrfake/ty/prompt/converters.rb +182 -0
- data/lib/wibrfake/ty/prompt/distance.rb +49 -0
- data/lib/wibrfake/ty/prompt/enum_list.rb +433 -0
- data/lib/wibrfake/ty/prompt/errors.rb +31 -0
- data/lib/wibrfake/ty/prompt/evaluator.rb +29 -0
- data/lib/wibrfake/ty/prompt/expander.rb +321 -0
- data/lib/wibrfake/ty/prompt/keypress.rb +98 -0
- data/lib/wibrfake/ty/prompt/list.rb +589 -0
- data/lib/wibrfake/ty/prompt/mask_question.rb +96 -0
- data/lib/wibrfake/ty/prompt/multi_list.rb +224 -0
- data/lib/wibrfake/ty/prompt/multiline.rb +72 -0
- data/lib/wibrfake/ty/prompt/paginator.rb +111 -0
- data/lib/wibrfake/ty/prompt/question/checks.rb +105 -0
- data/lib/wibrfake/ty/prompt/question/modifier.rb +96 -0
- data/lib/wibrfake/ty/prompt/question/validation.rb +72 -0
- data/lib/wibrfake/ty/prompt/question.rb +391 -0
- data/lib/wibrfake/ty/prompt/result.rb +42 -0
- data/lib/wibrfake/ty/prompt/selected_choices.rb +77 -0
- data/lib/wibrfake/ty/prompt/slider.rb +286 -0
- data/lib/wibrfake/ty/prompt/statement.rb +55 -0
- data/lib/wibrfake/ty/prompt/suggestion.rb +113 -0
- data/lib/wibrfake/ty/prompt/symbols.rb +89 -0
- data/lib/wibrfake/ty/prompt/test.rb +36 -0
- data/lib/wibrfake/ty/prompt/timer.rb +75 -0
- data/lib/wibrfake/ty/prompt/utils.rb +42 -0
- data/lib/wibrfake/ty/prompt/version.rb +7 -0
- data/lib/wibrfake/ty/prompt.rb +589 -0
- data/lib/wibrfake/version.rb +5 -0
- data/lib/wibrfake/wibrfake_cli.rb +683 -0
- data/log/.keep +0 -0
- data/pruebas/daemon1.pid +1 -0
- data/pruebas/daemon2.pid +1 -0
- data/pruebas/daemons.rb +44 -0
- data/public/404.html +67 -0
- data/public/406-unsupported-browser.html +66 -0
- data/public/422.html +67 -0
- data/public/500.html +66 -0
- data/public/icon.png +0 -0
- data/public/icon.svg +3 -0
- data/public/robots.txt +1 -0
- data/storage/.keep +0 -0
- data/test/application_system_test_case.rb +5 -0
- data/test/channels/application_cable/connection_test.rb +13 -0
- data/test/controllers/.keep +0 -0
- data/test/controllers/sessions_controller_test.rb +7 -0
- data/test/fixtures/files/.keep +0 -0
- data/test/fixtures/users.yml +11 -0
- data/test/helpers/.keep +0 -0
- data/test/integration/.keep +0 -0
- data/test/mailers/.keep +0 -0
- data/test/models/.keep +0 -0
- data/test/models/user_test.rb +7 -0
- data/test/system/.keep +0 -0
- data/test/test_helper.rb +15 -0
- data/tmp/.keep +0 -0
- data/tmp/pids/.keep +0 -0
- data/tmp/storage/.keep +0 -0
- data/vendor/.keep +0 -0
- data/vendor/javascript/.keep +0 -0
- data/wibrfake.gemspec +49 -0
- metadata +743 -0
@@ -0,0 +1,589 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "forwardable"
|
4
|
+
require "pastel"
|
5
|
+
require "tty-cursor"
|
6
|
+
require "tty-reader"
|
7
|
+
require "tty-screen"
|
8
|
+
|
9
|
+
require_relative "prompt/answers_collector"
|
10
|
+
require_relative "prompt/confirm_question"
|
11
|
+
require_relative "prompt/errors"
|
12
|
+
require_relative "prompt/expander"
|
13
|
+
require_relative "prompt/enum_list"
|
14
|
+
require_relative "prompt/keypress"
|
15
|
+
require_relative "prompt/list"
|
16
|
+
require_relative "prompt/multi_list"
|
17
|
+
require_relative "prompt/multiline"
|
18
|
+
require_relative "prompt/mask_question"
|
19
|
+
require_relative "prompt/question"
|
20
|
+
require_relative "prompt/slider"
|
21
|
+
require_relative "prompt/statement"
|
22
|
+
require_relative "prompt/suggestion"
|
23
|
+
require_relative "prompt/symbols"
|
24
|
+
require_relative "prompt/utils"
|
25
|
+
require_relative "prompt/version"
|
26
|
+
|
27
|
+
module TTY
|
28
|
+
# A main entry for asking prompt questions.
|
29
|
+
class Prompt
|
30
|
+
extend Forwardable
|
31
|
+
|
32
|
+
# @api private
|
33
|
+
attr_reader :input
|
34
|
+
|
35
|
+
# @api private
|
36
|
+
attr_reader :output
|
37
|
+
|
38
|
+
attr_reader :reader
|
39
|
+
|
40
|
+
attr_reader :cursor
|
41
|
+
|
42
|
+
# Prompt prefix
|
43
|
+
#
|
44
|
+
# @example
|
45
|
+
# prompt = TTY::Prompt.new(prefix: [?])
|
46
|
+
#
|
47
|
+
# @return [String]
|
48
|
+
#
|
49
|
+
# @api private
|
50
|
+
attr_reader :prefix
|
51
|
+
|
52
|
+
# Theme colors
|
53
|
+
#
|
54
|
+
# @api private
|
55
|
+
attr_reader :active_color, :help_color, :error_color, :enabled_color
|
56
|
+
|
57
|
+
# Quiet mode
|
58
|
+
#
|
59
|
+
# @api private
|
60
|
+
attr_reader :quiet
|
61
|
+
|
62
|
+
# The collection of display symbols
|
63
|
+
#
|
64
|
+
# @example
|
65
|
+
# prompt = TTY::Prompt.new(symbols: {marker: ">"})
|
66
|
+
#
|
67
|
+
# @return [Hash]
|
68
|
+
#
|
69
|
+
# @api private
|
70
|
+
attr_reader :symbols
|
71
|
+
|
72
|
+
def_delegators :@pastel, :strip
|
73
|
+
|
74
|
+
def_delegators :@cursor, :clear_lines, :clear_line,
|
75
|
+
:show, :hide
|
76
|
+
|
77
|
+
def_delegators :@reader, :read_char, :read_keypress, :read_line,
|
78
|
+
:read_multiline, :on, :subscribe, :unsubscribe, :trigger,
|
79
|
+
:count_screen_lines
|
80
|
+
|
81
|
+
def_delegators :@output, :print, :puts, :flush
|
82
|
+
|
83
|
+
def self.messages
|
84
|
+
{
|
85
|
+
range?: "Value %{value} must be within the range %{in}",
|
86
|
+
valid?: "Your answer is invalid (must match %{valid})",
|
87
|
+
required?: "Value must be provided for cli wibrfake",
|
88
|
+
convert?: "Cannot convert `%{value}` to '%{type}' type"
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
# Initialize a Prompt
|
93
|
+
#
|
94
|
+
# @param [IO] :input
|
95
|
+
# the input stream
|
96
|
+
# @param [IO] :output
|
97
|
+
# the output stream
|
98
|
+
# @param [Hash] :env
|
99
|
+
# the environment variables
|
100
|
+
# @param [Hash] :symbols
|
101
|
+
# the symbols displayed in prompts such as :marker, :cross
|
102
|
+
# @param options [Boolean] :quiet
|
103
|
+
# enable quiet mode, don't re-echo the question
|
104
|
+
# @param [String] :prefix
|
105
|
+
# the prompt prefix, by default empty
|
106
|
+
# @param [Symbol] :interrupt
|
107
|
+
# handling of Ctrl+C key out of :signal, :exit, :noop
|
108
|
+
# @param [Boolean] :track_history
|
109
|
+
# disable line history tracking, true by default
|
110
|
+
# @param [Boolean] :enable_color
|
111
|
+
# enable color support, true by default
|
112
|
+
# @param [String,Proc] :active_color
|
113
|
+
# the color used for selected option
|
114
|
+
# @param [String,Proc] :help_color
|
115
|
+
# the color used for help text
|
116
|
+
# @param [String] :error_color
|
117
|
+
# the color used for displaying error messages
|
118
|
+
#
|
119
|
+
# @api public
|
120
|
+
def initialize(input: $stdin, output: $stdout, env: ENV, symbols: {},
|
121
|
+
prefix: "", interrupt: :error, track_history: true,
|
122
|
+
quiet: false, enable_color: nil, active_color: :green,
|
123
|
+
help_color: :bright_black, error_color: :red)
|
124
|
+
@input = input
|
125
|
+
@output = output
|
126
|
+
@env = env
|
127
|
+
@prefix = prefix
|
128
|
+
@enabled_color = enable_color
|
129
|
+
@active_color = active_color
|
130
|
+
@help_color = help_color
|
131
|
+
@error_color = error_color
|
132
|
+
@interrupt = interrupt
|
133
|
+
@track_history = track_history
|
134
|
+
@symbols = Symbols.symbols.merge(symbols)
|
135
|
+
@quiet = quiet
|
136
|
+
|
137
|
+
@cursor = TTY::Cursor
|
138
|
+
@pastel = enabled_color.nil? ? Pastel.new : Pastel.new(enabled: enabled_color)
|
139
|
+
@reader = TTY::Reader.new(
|
140
|
+
input: input,
|
141
|
+
output: output,
|
142
|
+
interrupt: interrupt,
|
143
|
+
track_history: track_history,
|
144
|
+
env: env
|
145
|
+
)
|
146
|
+
end
|
147
|
+
|
148
|
+
# Decorate a string with colors
|
149
|
+
#
|
150
|
+
# @param [String] :string
|
151
|
+
# the string to color
|
152
|
+
# @param [Array<Proc|Symbol>] :colors
|
153
|
+
# collection of color symbols or callable object
|
154
|
+
#
|
155
|
+
# @api public
|
156
|
+
def decorate(string, *colors)
|
157
|
+
if Utils.blank?(string) || @enabled_color == false || colors.empty?
|
158
|
+
return string
|
159
|
+
end
|
160
|
+
|
161
|
+
coloring = colors.first
|
162
|
+
if coloring.respond_to?(:call)
|
163
|
+
coloring.call(string)
|
164
|
+
else
|
165
|
+
@pastel.decorate(string, *colors)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Invoke a question type of prompt
|
170
|
+
#
|
171
|
+
# @example
|
172
|
+
# prompt = TTY::Prompt.new
|
173
|
+
# prompt.invoke_question(Question, "Your name? ")
|
174
|
+
#
|
175
|
+
# @return [String]
|
176
|
+
#
|
177
|
+
# @api public
|
178
|
+
def invoke_question(object, message, **options, &block)
|
179
|
+
options[:messages] = self.class.messages
|
180
|
+
question = object.new(self, **options)
|
181
|
+
question.(message, &block)
|
182
|
+
end
|
183
|
+
|
184
|
+
# Ask a question.
|
185
|
+
#
|
186
|
+
# @example
|
187
|
+
# propmt = TTY::Prompt.new
|
188
|
+
# prompt.ask("What is your name?")
|
189
|
+
#
|
190
|
+
# @param [String] message
|
191
|
+
# the question to be asked
|
192
|
+
#
|
193
|
+
# @yieldparam [TTY::Prompt::Question] question
|
194
|
+
# further configure the question
|
195
|
+
#
|
196
|
+
# @yield [question]
|
197
|
+
#
|
198
|
+
# @return [TTY::Prompt::Question]
|
199
|
+
#
|
200
|
+
# @api public
|
201
|
+
def ask(message = "", **options, &block)
|
202
|
+
invoke_question(Question, message, **options, &block)
|
203
|
+
end
|
204
|
+
|
205
|
+
# Ask a question with a keypress answer
|
206
|
+
#
|
207
|
+
# @see #ask
|
208
|
+
#
|
209
|
+
# @api public
|
210
|
+
def keypress(message = "", **options, &block)
|
211
|
+
invoke_question(Keypress, message, **options, &block)
|
212
|
+
end
|
213
|
+
|
214
|
+
# Ask a question with a multiline answer
|
215
|
+
#
|
216
|
+
# @example
|
217
|
+
# prompt.multiline("Description?")
|
218
|
+
#
|
219
|
+
# @return [Array[String]]
|
220
|
+
#
|
221
|
+
# @api public
|
222
|
+
def multiline(message = "", **options, &block)
|
223
|
+
invoke_question(Multiline, message, **options, &block)
|
224
|
+
end
|
225
|
+
|
226
|
+
# Invoke a list type of prompt
|
227
|
+
#
|
228
|
+
# @example
|
229
|
+
# prompt = TTY::Prompt.new
|
230
|
+
# editors = %w(emacs nano vim)
|
231
|
+
# prompt.invoke_select(EnumList, "Select editor: ", editors)
|
232
|
+
#
|
233
|
+
# @return [String]
|
234
|
+
#
|
235
|
+
# @api public
|
236
|
+
def invoke_select(object, question, *args, &block)
|
237
|
+
options = Utils.extract_options!(args)
|
238
|
+
choices = if args.empty? && !block
|
239
|
+
possible = options.dup
|
240
|
+
options = {}
|
241
|
+
possible
|
242
|
+
elsif args.size == 1 && args[0].is_a?(Hash)
|
243
|
+
Utils.extract_options!(args)
|
244
|
+
else
|
245
|
+
args.flatten
|
246
|
+
end
|
247
|
+
|
248
|
+
list = object.new(self, **options)
|
249
|
+
list.(question, choices, &block)
|
250
|
+
end
|
251
|
+
|
252
|
+
# Ask masked question
|
253
|
+
#
|
254
|
+
# @example
|
255
|
+
# propmt = TTY::Prompt.new
|
256
|
+
# prompt.mask("What is your secret?")
|
257
|
+
#
|
258
|
+
# @return [TTY::Prompt::MaskQuestion]
|
259
|
+
#
|
260
|
+
# @api public
|
261
|
+
def mask(message = "", **options, &block)
|
262
|
+
invoke_question(MaskQuestion, message, **options, &block)
|
263
|
+
end
|
264
|
+
|
265
|
+
# Ask a question with a list of options
|
266
|
+
#
|
267
|
+
# @example
|
268
|
+
# prompt = TTY::Prompt.new
|
269
|
+
# prompt.select("What size?", %w(large medium small))
|
270
|
+
#
|
271
|
+
# @example
|
272
|
+
# prompt = TTY::Prompt.new
|
273
|
+
# prompt.select("What size?") do |menu|
|
274
|
+
# menu.choice :large
|
275
|
+
# menu.choices %w(:medium :small)
|
276
|
+
# end
|
277
|
+
#
|
278
|
+
# @param [String] question
|
279
|
+
# the question to ask
|
280
|
+
#
|
281
|
+
# @param [Array[Object]] choices
|
282
|
+
# the choices to select from
|
283
|
+
#
|
284
|
+
# @api public
|
285
|
+
def select(question, *args, &block)
|
286
|
+
invoke_select(List, question, *args, &block)
|
287
|
+
end
|
288
|
+
|
289
|
+
# Ask a question with multiple attributes activated
|
290
|
+
#
|
291
|
+
# @example
|
292
|
+
# prompt = TTY::Prompt.new
|
293
|
+
# choices = %w(Scorpion Jax Kitana Baraka Jade)
|
294
|
+
# prompt.multi_select("Choose your destiny?", choices)
|
295
|
+
#
|
296
|
+
# @param [String] question
|
297
|
+
# the question to ask
|
298
|
+
#
|
299
|
+
# @param [Array[Object]] choices
|
300
|
+
# the choices to select from
|
301
|
+
#
|
302
|
+
# @return [String]
|
303
|
+
#
|
304
|
+
# @api public
|
305
|
+
def multi_select(question, *args, &block)
|
306
|
+
invoke_select(MultiList, question, *args, &block)
|
307
|
+
end
|
308
|
+
|
309
|
+
# Ask a question with indexed list
|
310
|
+
#
|
311
|
+
# @example
|
312
|
+
# prompt = TTY::Prompt.new
|
313
|
+
# editors = %w(emacs nano vim)
|
314
|
+
# prompt.enum_select(EnumList, "Select editor: ", editors)
|
315
|
+
#
|
316
|
+
# @param [String] question
|
317
|
+
# the question to ask
|
318
|
+
#
|
319
|
+
# @param [Array[Object]] choices
|
320
|
+
# the choices to select from
|
321
|
+
#
|
322
|
+
# @return [String]
|
323
|
+
#
|
324
|
+
# @api public
|
325
|
+
def enum_select(question, *args, &block)
|
326
|
+
invoke_select(EnumList, question, *args, &block)
|
327
|
+
end
|
328
|
+
|
329
|
+
# A shortcut method to ask the user positive question and return
|
330
|
+
# true for "yes" reply, false for "no".
|
331
|
+
#
|
332
|
+
# @example
|
333
|
+
# prompt = TTY::Prompt.new
|
334
|
+
# prompt.yes?("Are you human?")
|
335
|
+
# # => Are you human? (Y/n)
|
336
|
+
#
|
337
|
+
# @return [Boolean]
|
338
|
+
#
|
339
|
+
# @api public
|
340
|
+
def yes?(message, **options, &block)
|
341
|
+
opts = { default: true }.merge(options)
|
342
|
+
question = ConfirmQuestion.new(self, **opts)
|
343
|
+
question.call(message, &block)
|
344
|
+
end
|
345
|
+
|
346
|
+
# A shortcut method to ask the user negative question and return
|
347
|
+
# true for "no" reply.
|
348
|
+
#
|
349
|
+
# @example
|
350
|
+
# prompt = TTY::Prompt.new
|
351
|
+
# prompt.no?("Are you alien?") # => true
|
352
|
+
# # => Are you human? (y/N)
|
353
|
+
#
|
354
|
+
# @return [Boolean]
|
355
|
+
#
|
356
|
+
# @api public
|
357
|
+
def no?(message, **options, &block)
|
358
|
+
opts = { default: false }.merge(options)
|
359
|
+
question = ConfirmQuestion.new(self, **opts)
|
360
|
+
!question.call(message, &block)
|
361
|
+
end
|
362
|
+
|
363
|
+
# Expand available options
|
364
|
+
#
|
365
|
+
# @example
|
366
|
+
# prompt = TTY::Prompt.new
|
367
|
+
# choices = [{
|
368
|
+
# key: "Y",
|
369
|
+
# name: "Overwrite",
|
370
|
+
# value: :yes
|
371
|
+
# }, {
|
372
|
+
# key: "n",
|
373
|
+
# name: "Skip",
|
374
|
+
# value: :no
|
375
|
+
# }]
|
376
|
+
# prompt.expand("Overwirte Gemfile?", choices)
|
377
|
+
#
|
378
|
+
# @return [Object]
|
379
|
+
# the user specified value
|
380
|
+
#
|
381
|
+
# @api public
|
382
|
+
def expand(message, *args, &block)
|
383
|
+
invoke_select(Expander, message, *args, &block)
|
384
|
+
end
|
385
|
+
|
386
|
+
# Ask a question with a range slider
|
387
|
+
#
|
388
|
+
# @example
|
389
|
+
# prompt = TTY::Prompt.new
|
390
|
+
# prompt.slider("What size?", min: 32, max: 54, step: 2)
|
391
|
+
# prompt.slider("What size?", [ 'xs', 's', 'm', 'l', 'xl' ])
|
392
|
+
#
|
393
|
+
# @param [String] question
|
394
|
+
# the question to ask
|
395
|
+
#
|
396
|
+
# @param [Array] choices
|
397
|
+
# the choices to display
|
398
|
+
#
|
399
|
+
# @return [String]
|
400
|
+
#
|
401
|
+
# @api public
|
402
|
+
def slider(question, choices = nil, **options, &block)
|
403
|
+
slider = Slider.new(self, **options)
|
404
|
+
slider.call(question, choices, &block)
|
405
|
+
end
|
406
|
+
|
407
|
+
# Print statement out. If the supplied message ends with a space or
|
408
|
+
# tab character, a new line will not be appended.
|
409
|
+
#
|
410
|
+
# @example
|
411
|
+
# say("Simple things.", color: :red)
|
412
|
+
#
|
413
|
+
# @param [String] message
|
414
|
+
#
|
415
|
+
# @return [String]
|
416
|
+
#
|
417
|
+
# @api public
|
418
|
+
def say(message = "", **options)
|
419
|
+
message = message.to_s
|
420
|
+
return if message.empty?
|
421
|
+
|
422
|
+
statement = Statement.new(self, **options)
|
423
|
+
statement.call(message)
|
424
|
+
end
|
425
|
+
|
426
|
+
# Print statement(s) out in red green.
|
427
|
+
#
|
428
|
+
# @example
|
429
|
+
# prompt.ok "Are you sure?"
|
430
|
+
# prompt.ok "All is fine!", "This is fine too."
|
431
|
+
#
|
432
|
+
# @param [Array] messages
|
433
|
+
#
|
434
|
+
# @return [Array] messages
|
435
|
+
#
|
436
|
+
# @api public
|
437
|
+
def ok(*args, **options)
|
438
|
+
opts = { color: :green }.merge(options)
|
439
|
+
args.each { |message| say(message, **opts) }
|
440
|
+
end
|
441
|
+
|
442
|
+
# Print statement(s) out in yellow color.
|
443
|
+
#
|
444
|
+
# @example
|
445
|
+
# prompt.warn "This action can have dire consequences"
|
446
|
+
# prompt.warn "Carefull young apprentice", "This is potentially dangerous"
|
447
|
+
#
|
448
|
+
# @param [Array] messages
|
449
|
+
#
|
450
|
+
# @return [Array] messages
|
451
|
+
#
|
452
|
+
# @api public
|
453
|
+
def warn(*args, **options)
|
454
|
+
opts = { color: :yellow }.merge(options)
|
455
|
+
args.each { |message| say(message, **opts) }
|
456
|
+
end
|
457
|
+
|
458
|
+
# Print statement(s) out in red color.
|
459
|
+
#
|
460
|
+
# @example
|
461
|
+
# prompt.error "Shutting down all systems!"
|
462
|
+
# prompt.error "Nothing is fine!", "All is broken!"
|
463
|
+
#
|
464
|
+
# @param [Array] messages
|
465
|
+
#
|
466
|
+
# @return [Array] messages
|
467
|
+
#
|
468
|
+
# @api public
|
469
|
+
def error(*args, **options)
|
470
|
+
opts = { color: :red }.merge(options)
|
471
|
+
args.each { |message| say(message, **opts) }
|
472
|
+
end
|
473
|
+
|
474
|
+
# Print debug information in terminal top right corner
|
475
|
+
#
|
476
|
+
# @example
|
477
|
+
# prompt.debug "info1", "info2"
|
478
|
+
#
|
479
|
+
# @param [Array] messages
|
480
|
+
#
|
481
|
+
# @retrun [nil]
|
482
|
+
#
|
483
|
+
# @api public
|
484
|
+
def debug(*messages)
|
485
|
+
longest = messages.max_by(&:length).size
|
486
|
+
width = TTY::Screen.width - longest
|
487
|
+
print cursor.save
|
488
|
+
messages.reverse_each do |msg|
|
489
|
+
print cursor.column(width) + cursor.up + cursor.clear_line_after
|
490
|
+
print msg
|
491
|
+
end
|
492
|
+
ensure
|
493
|
+
print cursor.restore
|
494
|
+
end
|
495
|
+
|
496
|
+
# Takes the string provided by the user and compare it with other possible
|
497
|
+
# matches to suggest an unambigous string
|
498
|
+
#
|
499
|
+
# @example
|
500
|
+
# prompt.suggest("sta", ["status", "stage", "commit", "branch"])
|
501
|
+
# # => "status, stage"
|
502
|
+
#
|
503
|
+
# @param [String] message
|
504
|
+
#
|
505
|
+
# @param [Array] possibilities
|
506
|
+
#
|
507
|
+
# @param [Hash] options
|
508
|
+
# @option options [String] :indent
|
509
|
+
# The number of spaces for indentation
|
510
|
+
# @option options [String] :single_text
|
511
|
+
# The text for a single suggestion
|
512
|
+
# @option options [String] :plural_text
|
513
|
+
# The text for multiple suggestions
|
514
|
+
#
|
515
|
+
# @return [String]
|
516
|
+
#
|
517
|
+
# @api public
|
518
|
+
def suggest(message, possibilities, **options)
|
519
|
+
suggestion = Suggestion.new(**options)
|
520
|
+
say(suggestion.suggest(message, possibilities))
|
521
|
+
end
|
522
|
+
|
523
|
+
# Gathers more than one aswer
|
524
|
+
#
|
525
|
+
# @example
|
526
|
+
# prompt.collect do
|
527
|
+
# key(:name).ask("Name?")
|
528
|
+
# end
|
529
|
+
#
|
530
|
+
# @return [Hash]
|
531
|
+
# the collection of answers
|
532
|
+
#
|
533
|
+
# @api public
|
534
|
+
def collect(**options, &block)
|
535
|
+
collector = AnswersCollector.new(self, **options)
|
536
|
+
collector.call(&block)
|
537
|
+
end
|
538
|
+
|
539
|
+
# Check if outputing to terminal
|
540
|
+
#
|
541
|
+
# @return [Boolean]
|
542
|
+
#
|
543
|
+
# @api public
|
544
|
+
def tty?
|
545
|
+
stdout.tty?
|
546
|
+
end
|
547
|
+
|
548
|
+
# Return standard in
|
549
|
+
#
|
550
|
+
# @api private
|
551
|
+
def stdin
|
552
|
+
$stdin
|
553
|
+
end
|
554
|
+
|
555
|
+
# Return standard out
|
556
|
+
#
|
557
|
+
# @api private
|
558
|
+
def stdout
|
559
|
+
$stdout
|
560
|
+
end
|
561
|
+
|
562
|
+
# Return standard error
|
563
|
+
#
|
564
|
+
# @api private
|
565
|
+
def stderr
|
566
|
+
$stderr
|
567
|
+
end
|
568
|
+
|
569
|
+
# Inspect this instance public attributes
|
570
|
+
#
|
571
|
+
# @return [String]
|
572
|
+
#
|
573
|
+
# @api public
|
574
|
+
def inspect
|
575
|
+
attributes = [
|
576
|
+
:prefix,
|
577
|
+
:quiet,
|
578
|
+
:enabled_color,
|
579
|
+
:active_color,
|
580
|
+
:error_color,
|
581
|
+
:help_color,
|
582
|
+
:input,
|
583
|
+
:output,
|
584
|
+
]
|
585
|
+
name = self.class.name
|
586
|
+
"#<#{name}#{attributes.map { |attr| " #{attr}=#{send(attr).inspect}" }.join}>"
|
587
|
+
end
|
588
|
+
end # Prompt
|
589
|
+
end # TTY
|