llm-shell 0.9.2 → 0.10.0
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 +4 -4
- data/README.md +61 -66
- data/lib/llm/shell/command.rb +40 -40
- data/lib/llm/shell/commands/clear_screen.rb +4 -18
- data/lib/llm/shell/commands/debug_mode.rb +12 -0
- data/lib/llm/shell/commands/dir_import.rb +4 -20
- data/lib/llm/shell/commands/disable_tool.rb +33 -0
- data/lib/llm/shell/commands/enable_tool.rb +33 -0
- data/lib/llm/shell/commands/file_import.rb +4 -20
- data/lib/llm/shell/commands/help.rb +23 -36
- data/lib/llm/shell/commands/show_chat.rb +4 -19
- data/lib/llm/shell/commands/show_version.rb +4 -20
- data/lib/llm/shell/commands/system_prompt.rb +4 -18
- data/lib/llm/shell/completion.rb +5 -5
- data/lib/llm/shell/config.rb +4 -5
- data/lib/llm/shell/formatter.rb +1 -2
- data/lib/llm/shell/internal/coderay/lib/coderay/duo.rb +81 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/_map.rb +17 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/comment_filter.rb +25 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/count.rb +39 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/debug.rb +49 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/debug_lint.rb +63 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/div.rb +23 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/encoder.rb +190 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/filter.rb +58 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html/css.rb +65 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html/numbering.rb +108 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html/output.rb +164 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html.rb +333 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/json.rb +83 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/lines_of_code.rb +45 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/lint.rb +59 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/null.rb +18 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/page.rb +24 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/span.rb +23 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/statistic.rb +95 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/terminal.rb +195 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/text.rb +46 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/token_kind_filter.rb +111 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/xml.rb +72 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders/yaml.rb +50 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/encoders.rb +18 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/for_redcloth.rb +95 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/helpers/file_type.rb +151 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/helpers/plugin.rb +55 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/helpers/plugin_host.rb +221 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/helpers/word_list.rb +72 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/_map.rb +24 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/c.rb +189 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/clojure.rb +217 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/cpp.rb +217 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/css.rb +196 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/debug.rb +75 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/delphi.rb +144 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/diff.rb +221 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/erb.rb +81 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/go.rb +208 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/groovy.rb +268 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/haml.rb +168 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/html.rb +275 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/java/builtin_types.rb +421 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/java.rb +174 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/java_script.rb +236 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/json.rb +98 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/lua.rb +280 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/php.rb +527 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/python.rb +287 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/raydebug.rb +75 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/ruby/patterns.rb +178 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/ruby/string_state.rb +79 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/ruby.rb +477 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/sass.rb +232 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/scanner.rb +337 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/sql.rb +169 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/taskpaper.rb +36 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/text.rb +26 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/xml.rb +17 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners/yaml.rb +140 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/scanners.rb +27 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/styles/_map.rb +7 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/styles/alpha.rb +153 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/styles/style.rb +18 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/styles.rb +15 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/token_kinds.rb +85 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/tokens.rb +164 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/tokens_proxy.rb +55 -0
- data/lib/llm/shell/internal/coderay/lib/coderay/version.rb +3 -0
- data/lib/llm/shell/internal/coderay/lib/coderay.rb +284 -0
- data/lib/llm/shell/internal/io-line/lib/io/line/multiple.rb +19 -0
- data/lib/{io → llm/shell/internal/io-line/lib/io}/line.rb +2 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/bot/builder.rb +31 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/bot/conversable.rb +37 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/bot/prompt/completion.rb +49 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/bot/prompt/respond.rb +49 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/bot.rb +150 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/buffer.rb +162 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/client.rb +36 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/error.rb +49 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/eventhandler.rb +44 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/eventstream/event.rb +69 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/eventstream/parser.rb +88 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/eventstream.rb +8 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/file.rb +91 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/function.rb +177 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/message.rb +178 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/mime.rb +140 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/multipart.rb +101 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/object/builder.rb +38 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/object/kernel.rb +53 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/object.rb +89 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/provider.rb +352 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/error_handler.rb +36 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/files.rb +155 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/format/completion_format.rb +88 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/format.rb +29 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/models.rb +54 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/completion.rb +39 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/enumerable.rb +11 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/file.rb +23 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/web_search.rb +21 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/stream_parser.rb +66 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic.rb +138 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/deepseek/format/completion_format.rb +68 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/deepseek/format.rb +27 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/deepseek.rb +75 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/audio.rb +73 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/error_handler.rb +47 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/files.rb +146 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format/completion_format.rb +69 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format.rb +39 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/images.rb +133 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/models.rb +60 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/completion.rb +35 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/embedding.rb +8 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/file.rb +11 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/files.rb +15 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/image.rb +31 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/models.rb +15 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/web_search.rb +22 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/stream_parser.rb +86 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini.rb +173 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/llamacpp.rb +74 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/error_handler.rb +36 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/format/completion_format.rb +77 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/format.rb +29 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/models.rb +56 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/response/completion.rb +28 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/response/embedding.rb +9 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/stream_parser.rb +44 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama.rb +116 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/audio.rb +91 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/error_handler.rb +46 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/files.rb +134 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format/completion_format.rb +90 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format/moderation_format.rb +35 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format/respond_format.rb +72 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format.rb +54 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/images.rb +109 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/models.rb +55 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/moderations.rb +65 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/audio.rb +7 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/completion.rb +40 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/embedding.rb +9 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/enumerable.rb +23 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/file.rb +7 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/image.rb +16 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/moderations.rb +34 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/responds.rb +48 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/web_search.rb +21 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/responses/stream_parser.rb +76 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/responses.rb +99 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/stream_parser.rb +86 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/vector_stores.rb +228 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai.rb +206 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/xai/images.rb +58 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/xai.rb +72 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/providers/zai.rb +74 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/response.rb +67 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/array.rb +26 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/boolean.rb +13 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/integer.rb +43 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/leaf.rb +78 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/null.rb +13 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/number.rb +43 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/object.rb +41 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/string.rb +34 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema/version.rb +8 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/schema.rb +81 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/server_tool.rb +32 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/tool/param.rb +75 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/tool.rb +78 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/utils.rb +19 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm/version.rb +5 -0
- data/lib/llm/shell/internal/llm.rb/lib/llm.rb +121 -0
- data/lib/llm/shell/internal/optparse/lib/optionparser.rb +2 -0
- data/lib/llm/shell/internal/optparse/lib/optparse/ac.rb +70 -0
- data/lib/llm/shell/internal/optparse/lib/optparse/date.rb +18 -0
- data/lib/llm/shell/internal/optparse/lib/optparse/kwargs.rb +27 -0
- data/lib/llm/shell/internal/optparse/lib/optparse/shellwords.rb +7 -0
- data/lib/llm/shell/internal/optparse/lib/optparse/time.rb +11 -0
- data/lib/llm/shell/internal/optparse/lib/optparse/uri.rb +7 -0
- data/lib/llm/shell/internal/optparse/lib/optparse/version.rb +80 -0
- data/lib/llm/shell/internal/optparse/lib/optparse.rb +2469 -0
- data/lib/llm/shell/internal/paint/lib/paint/constants.rb +104 -0
- data/lib/llm/shell/internal/paint/lib/paint/pa.rb +13 -0
- data/lib/llm/shell/internal/paint/lib/paint/rgb_colors.rb +14 -0
- data/lib/llm/shell/internal/paint/lib/paint/shortcuts.rb +100 -0
- data/lib/llm/shell/internal/paint/lib/paint/shortcuts_version.rb +5 -0
- data/lib/llm/shell/internal/paint/lib/paint/util.rb +16 -0
- data/lib/llm/shell/internal/paint/lib/paint/version.rb +5 -0
- data/lib/llm/shell/internal/paint/lib/paint.rb +261 -0
- data/lib/llm/shell/internal/reline/lib/reline/config.rb +378 -0
- data/lib/llm/shell/internal/reline/lib/reline/face.rb +199 -0
- data/lib/llm/shell/internal/reline/lib/reline/history.rb +76 -0
- data/lib/llm/shell/internal/reline/lib/reline/io/ansi.rb +322 -0
- data/lib/llm/shell/internal/reline/lib/reline/io/dumb.rb +120 -0
- data/lib/llm/shell/internal/reline/lib/reline/io/windows.rb +530 -0
- data/lib/llm/shell/internal/reline/lib/reline/io.rb +55 -0
- data/lib/llm/shell/internal/reline/lib/reline/key_actor/base.rb +37 -0
- data/lib/llm/shell/internal/reline/lib/reline/key_actor/composite.rb +17 -0
- data/lib/llm/shell/internal/reline/lib/reline/key_actor/emacs.rb +517 -0
- data/lib/llm/shell/internal/reline/lib/reline/key_actor/vi_command.rb +518 -0
- data/lib/llm/shell/internal/reline/lib/reline/key_actor/vi_insert.rb +517 -0
- data/lib/llm/shell/internal/reline/lib/reline/key_actor.rb +8 -0
- data/lib/llm/shell/internal/reline/lib/reline/key_stroke.rb +119 -0
- data/lib/llm/shell/internal/reline/lib/reline/kill_ring.rb +125 -0
- data/lib/llm/shell/internal/reline/lib/reline/line_editor.rb +2356 -0
- data/lib/llm/shell/internal/reline/lib/reline/unicode/east_asian_width.rb +1292 -0
- data/lib/llm/shell/internal/reline/lib/reline/unicode.rb +421 -0
- data/lib/llm/shell/internal/reline/lib/reline/version.rb +3 -0
- data/lib/llm/shell/internal/reline/lib/reline.rb +527 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/generated_parser.rb +712 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/handler.rb +268 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/local_date.rb +35 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/local_date_time.rb +42 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/local_time.rb +40 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/parser.rb +21 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/scanner.rb +92 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/string_utils.rb +40 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb/version.rb +5 -0
- data/lib/llm/shell/internal/tomlrb/lib/tomlrb.rb +49 -0
- data/lib/llm/shell/options.rb +1 -1
- data/lib/llm/shell/renderer.rb +2 -3
- data/lib/llm/shell/repl.rb +21 -16
- data/lib/llm/shell/tool.rb +42 -0
- data/lib/llm/shell/tools/read_file.rb +15 -0
- data/lib/llm/shell/tools/system.rb +17 -0
- data/lib/llm/shell/tools/write_file.rb +16 -0
- data/lib/llm/shell/version.rb +1 -1
- data/lib/llm/shell.rb +83 -39
- data/libexec/llm-shell/shell +4 -6
- data/llm-shell.gemspec +0 -4
- metadata +233 -63
- data/lib/llm/function.rb +0 -17
- data/lib/llm/shell/command/extension.rb +0 -42
- data/lib/llm/shell/commands/utils.rb +0 -21
- data/lib/llm/shell/functions/read_file.rb +0 -22
- data/lib/llm/shell/functions/write_file.rb +0 -22
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
class Reline::Config
|
|
2
|
+
attr_reader :test_mode
|
|
3
|
+
|
|
4
|
+
KEYSEQ_PATTERN = /\\(?:C|Control)-[A-Za-z_]|\\(?:M|Meta)-[0-9A-Za-z_]|\\(?:C|Control)-\\(?:M|Meta)-[A-Za-z_]|\\(?:M|Meta)-\\(?:C|Control)-[A-Za-z_]|\\e|\\[\\\"\'abdfnrtv]|\\\d{1,3}|\\x\h{1,2}|./
|
|
5
|
+
|
|
6
|
+
class InvalidInputrc < RuntimeError
|
|
7
|
+
attr_accessor :file, :lineno
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
VARIABLE_NAMES = %w{
|
|
11
|
+
completion-ignore-case
|
|
12
|
+
convert-meta
|
|
13
|
+
disable-completion
|
|
14
|
+
history-size
|
|
15
|
+
keyseq-timeout
|
|
16
|
+
show-all-if-ambiguous
|
|
17
|
+
show-mode-in-prompt
|
|
18
|
+
vi-cmd-mode-string
|
|
19
|
+
vi-ins-mode-string
|
|
20
|
+
emacs-mode-string
|
|
21
|
+
enable-bracketed-paste
|
|
22
|
+
isearch-terminators
|
|
23
|
+
}
|
|
24
|
+
VARIABLE_NAME_SYMBOLS = VARIABLE_NAMES.map { |v| :"#{v.tr(?-, ?_)}" }
|
|
25
|
+
VARIABLE_NAME_SYMBOLS.each do |v|
|
|
26
|
+
attr_accessor v
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
attr_accessor :autocompletion
|
|
30
|
+
|
|
31
|
+
def initialize
|
|
32
|
+
reset_variables
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def reset
|
|
36
|
+
if editing_mode_is?(:vi_command)
|
|
37
|
+
@editing_mode_label = :vi_insert
|
|
38
|
+
end
|
|
39
|
+
@oneshot_key_bindings.clear
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def reset_variables
|
|
43
|
+
@additional_key_bindings = { # from inputrc
|
|
44
|
+
emacs: Reline::KeyActor::Base.new,
|
|
45
|
+
vi_insert: Reline::KeyActor::Base.new,
|
|
46
|
+
vi_command: Reline::KeyActor::Base.new
|
|
47
|
+
}
|
|
48
|
+
@oneshot_key_bindings = Reline::KeyActor::Base.new
|
|
49
|
+
@editing_mode_label = :emacs
|
|
50
|
+
@keymap_label = :emacs
|
|
51
|
+
@keymap_prefix = []
|
|
52
|
+
@default_key_bindings = {
|
|
53
|
+
emacs: Reline::KeyActor::Base.new(Reline::KeyActor::EMACS_MAPPING),
|
|
54
|
+
vi_insert: Reline::KeyActor::Base.new(Reline::KeyActor::VI_INSERT_MAPPING),
|
|
55
|
+
vi_command: Reline::KeyActor::Base.new(Reline::KeyActor::VI_COMMAND_MAPPING)
|
|
56
|
+
}
|
|
57
|
+
@vi_cmd_mode_string = '(cmd)'
|
|
58
|
+
@vi_ins_mode_string = '(ins)'
|
|
59
|
+
@emacs_mode_string = '@'
|
|
60
|
+
# https://tiswww.case.edu/php/chet/readline/readline.html#IDX25
|
|
61
|
+
@history_size = -1 # unlimited
|
|
62
|
+
@keyseq_timeout = 500
|
|
63
|
+
@test_mode = false
|
|
64
|
+
@autocompletion = false
|
|
65
|
+
@convert_meta = seven_bit_encoding?(Reline::IOGate.encoding)
|
|
66
|
+
@loaded = false
|
|
67
|
+
@enable_bracketed_paste = true
|
|
68
|
+
@show_mode_in_prompt = false
|
|
69
|
+
@default_inputrc_path = nil
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def editing_mode
|
|
73
|
+
@default_key_bindings[@editing_mode_label]
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def editing_mode=(val)
|
|
77
|
+
@editing_mode_label = val
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def editing_mode_is?(*val)
|
|
81
|
+
val.any?(@editing_mode_label)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def keymap
|
|
85
|
+
@default_key_bindings[@keymap_label]
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def loaded?
|
|
89
|
+
@loaded
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def inputrc_path
|
|
93
|
+
case ENV['INPUTRC']
|
|
94
|
+
when nil, ''
|
|
95
|
+
else
|
|
96
|
+
return File.expand_path(ENV['INPUTRC'])
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# In the XDG Specification, if ~/.config/readline/inputrc exists, then
|
|
100
|
+
# ~/.inputrc should not be read, but for compatibility with GNU Readline,
|
|
101
|
+
# if ~/.inputrc exists, then it is given priority.
|
|
102
|
+
home_rc_path = File.expand_path('~/.inputrc')
|
|
103
|
+
return home_rc_path if File.exist?(home_rc_path)
|
|
104
|
+
|
|
105
|
+
case path = ENV['XDG_CONFIG_HOME']
|
|
106
|
+
when nil, ''
|
|
107
|
+
else
|
|
108
|
+
path = File.join(path, 'readline/inputrc')
|
|
109
|
+
return path if File.exist?(path) and path == File.expand_path(path)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
path = File.expand_path('~/.config/readline/inputrc')
|
|
113
|
+
return path if File.exist?(path)
|
|
114
|
+
|
|
115
|
+
return home_rc_path
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
private def default_inputrc_path
|
|
119
|
+
@default_inputrc_path ||= inputrc_path
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def read(file = nil)
|
|
123
|
+
@loaded = true
|
|
124
|
+
file ||= default_inputrc_path
|
|
125
|
+
begin
|
|
126
|
+
if file.respond_to?(:readlines)
|
|
127
|
+
lines = file.readlines
|
|
128
|
+
else
|
|
129
|
+
lines = File.readlines(file)
|
|
130
|
+
end
|
|
131
|
+
rescue Errno::ENOENT
|
|
132
|
+
return nil
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
read_lines(lines, file)
|
|
136
|
+
self
|
|
137
|
+
rescue InvalidInputrc => e
|
|
138
|
+
warn e.message
|
|
139
|
+
nil
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def key_bindings
|
|
143
|
+
# The key bindings for each editing mode will be overwritten by the user-defined ones.
|
|
144
|
+
Reline::KeyActor::Composite.new([@oneshot_key_bindings, @additional_key_bindings[@editing_mode_label], @default_key_bindings[@editing_mode_label]])
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def add_oneshot_key_binding(keystroke, target)
|
|
148
|
+
# IRB sets invalid keystroke [Reline::Key]. We should ignore it.
|
|
149
|
+
return unless keystroke.all? { |c| c.is_a?(Integer) }
|
|
150
|
+
|
|
151
|
+
@oneshot_key_bindings.add(keystroke, target)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def reset_oneshot_key_bindings
|
|
155
|
+
@oneshot_key_bindings.clear
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def add_default_key_binding_by_keymap(keymap, keystroke, target)
|
|
159
|
+
@default_key_bindings[keymap].add(keystroke, target)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def add_default_key_binding(keystroke, target)
|
|
163
|
+
add_default_key_binding_by_keymap(@keymap_label, keystroke, target)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def read_lines(lines, file = nil)
|
|
167
|
+
if not lines.empty? and lines.first.encoding != Reline.encoding_system_needs
|
|
168
|
+
begin
|
|
169
|
+
lines = lines.map do |l|
|
|
170
|
+
l.encode(Reline.encoding_system_needs)
|
|
171
|
+
rescue Encoding::UndefinedConversionError
|
|
172
|
+
mes = "The inputrc encoded in #{lines.first.encoding.name} can't be converted to the locale #{Reline.encoding_system_needs.name}."
|
|
173
|
+
raise Reline::ConfigEncodingConversionError.new(mes)
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
if_stack = []
|
|
178
|
+
|
|
179
|
+
lines.each_with_index do |line, no|
|
|
180
|
+
# Even after encoding conversion, we need to verify the encoding is valid
|
|
181
|
+
# as some invalid byte sequences might pass through the conversion.
|
|
182
|
+
unless line.valid_encoding?
|
|
183
|
+
raise InvalidInputrc, "#{file}:#{no + 1}: can't be converted to the locale #{Reline.encoding_system_needs.name}"
|
|
184
|
+
end
|
|
185
|
+
next if line.match(/\A\s*#/)
|
|
186
|
+
|
|
187
|
+
no += 1
|
|
188
|
+
|
|
189
|
+
line = line.chomp.lstrip
|
|
190
|
+
if line.start_with?('$')
|
|
191
|
+
handle_directive(line[1..-1], file, no, if_stack)
|
|
192
|
+
next
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
next if if_stack.any? { |_no, skip| skip }
|
|
196
|
+
|
|
197
|
+
case line
|
|
198
|
+
when /^set +([^ ]+) +(.+)/i
|
|
199
|
+
# value ignores everything after a space, raw_value does not.
|
|
200
|
+
var, value, raw_value = $1.downcase, $2.partition(' ').first, $2
|
|
201
|
+
bind_variable(var, value, raw_value)
|
|
202
|
+
when /^\s*(?:M|Meta)-([a-zA-Z_])\s*:\s*(.*)\s*$/o
|
|
203
|
+
bind_key("\"\\M-#$1\"", $2)
|
|
204
|
+
when /^\s*(?:C|Control)-([a-zA-Z_])\s*:\s*(.*)\s*$/o
|
|
205
|
+
bind_key("\"\\C-#$1\"", $2)
|
|
206
|
+
when /^\s*(?:(?:C|Control)-(?:M|Meta)|(?:M|Meta)-(?:C|Control))-([a-zA-Z_])\s*:\s*(.*)\s*$/o
|
|
207
|
+
bind_key("\"\\M-\\C-#$1\"", $2)
|
|
208
|
+
when /^\s*("#{KEYSEQ_PATTERN}+")\s*:\s*(.*)\s*$/o
|
|
209
|
+
bind_key($1, $2)
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
unless if_stack.empty?
|
|
213
|
+
raise InvalidInputrc, "#{file}:#{if_stack.last[0]}: unclosed if"
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def handle_directive(directive, file, no, if_stack)
|
|
218
|
+
directive, args = directive.split(' ')
|
|
219
|
+
case directive
|
|
220
|
+
when 'if'
|
|
221
|
+
condition = false
|
|
222
|
+
case args
|
|
223
|
+
when /^mode=(vi|emacs)$/i
|
|
224
|
+
mode = $1.downcase
|
|
225
|
+
# NOTE: mode=vi means vi-insert mode
|
|
226
|
+
mode = 'vi_insert' if mode == 'vi'
|
|
227
|
+
if @editing_mode_label == mode.to_sym
|
|
228
|
+
condition = true
|
|
229
|
+
end
|
|
230
|
+
when 'term'
|
|
231
|
+
when 'version'
|
|
232
|
+
else # application name
|
|
233
|
+
condition = true if args == 'Ruby'
|
|
234
|
+
condition = true if args == 'Reline'
|
|
235
|
+
end
|
|
236
|
+
if_stack << [no, !condition]
|
|
237
|
+
when 'else'
|
|
238
|
+
if if_stack.empty?
|
|
239
|
+
raise InvalidInputrc, "#{file}:#{no}: unmatched else"
|
|
240
|
+
end
|
|
241
|
+
if_stack.last[1] = !if_stack.last[1]
|
|
242
|
+
when 'endif'
|
|
243
|
+
if if_stack.empty?
|
|
244
|
+
raise InvalidInputrc, "#{file}:#{no}: unmatched endif"
|
|
245
|
+
end
|
|
246
|
+
if_stack.pop
|
|
247
|
+
when 'include'
|
|
248
|
+
read(File.expand_path(args))
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def bind_variable(name, value, raw_value)
|
|
253
|
+
case name
|
|
254
|
+
when 'history-size'
|
|
255
|
+
begin
|
|
256
|
+
@history_size = Integer(value)
|
|
257
|
+
rescue ArgumentError
|
|
258
|
+
@history_size = 500
|
|
259
|
+
end
|
|
260
|
+
when 'isearch-terminators'
|
|
261
|
+
@isearch_terminators = retrieve_string(raw_value)
|
|
262
|
+
when 'editing-mode'
|
|
263
|
+
case value
|
|
264
|
+
when 'emacs'
|
|
265
|
+
@editing_mode_label = :emacs
|
|
266
|
+
@keymap_label = :emacs
|
|
267
|
+
@keymap_prefix = []
|
|
268
|
+
when 'vi'
|
|
269
|
+
@editing_mode_label = :vi_insert
|
|
270
|
+
@keymap_label = :vi_insert
|
|
271
|
+
@keymap_prefix = []
|
|
272
|
+
end
|
|
273
|
+
when 'keymap'
|
|
274
|
+
case value
|
|
275
|
+
when 'emacs', 'emacs-standard'
|
|
276
|
+
@keymap_label = :emacs
|
|
277
|
+
@keymap_prefix = []
|
|
278
|
+
when 'emacs-ctlx'
|
|
279
|
+
@keymap_label = :emacs
|
|
280
|
+
@keymap_prefix = [?\C-x.ord]
|
|
281
|
+
when 'emacs-meta'
|
|
282
|
+
@keymap_label = :emacs
|
|
283
|
+
@keymap_prefix = [?\e.ord]
|
|
284
|
+
when 'vi', 'vi-move', 'vi-command'
|
|
285
|
+
@keymap_label = :vi_command
|
|
286
|
+
@keymap_prefix = []
|
|
287
|
+
when 'vi-insert'
|
|
288
|
+
@keymap_label = :vi_insert
|
|
289
|
+
@keymap_prefix = []
|
|
290
|
+
end
|
|
291
|
+
when 'keyseq-timeout'
|
|
292
|
+
@keyseq_timeout = value.to_i
|
|
293
|
+
when 'show-mode-in-prompt'
|
|
294
|
+
case value
|
|
295
|
+
when 'off'
|
|
296
|
+
@show_mode_in_prompt = false
|
|
297
|
+
when 'on'
|
|
298
|
+
@show_mode_in_prompt = true
|
|
299
|
+
else
|
|
300
|
+
@show_mode_in_prompt = false
|
|
301
|
+
end
|
|
302
|
+
when 'vi-cmd-mode-string'
|
|
303
|
+
@vi_cmd_mode_string = retrieve_string(raw_value)
|
|
304
|
+
when 'vi-ins-mode-string'
|
|
305
|
+
@vi_ins_mode_string = retrieve_string(raw_value)
|
|
306
|
+
when 'emacs-mode-string'
|
|
307
|
+
@emacs_mode_string = retrieve_string(raw_value)
|
|
308
|
+
when *VARIABLE_NAMES then
|
|
309
|
+
variable_name = :"@#{name.tr(?-, ?_)}"
|
|
310
|
+
instance_variable_set(variable_name, value.nil? || value == '1' || value == 'on')
|
|
311
|
+
end
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
def retrieve_string(str)
|
|
315
|
+
str = $1 if str =~ /\A"(.*)"\z/
|
|
316
|
+
parse_keyseq(str).map { |c| c.chr(Reline.encoding_system_needs) }.join
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
def bind_key(key, value)
|
|
320
|
+
keystroke, func = parse_key_binding(key, value)
|
|
321
|
+
@additional_key_bindings[@keymap_label].add(@keymap_prefix + keystroke, func) if keystroke
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
def parse_key_binding(key, func_name)
|
|
325
|
+
if key =~ /\A"(.*)"\z/
|
|
326
|
+
keyseq = parse_keyseq($1)
|
|
327
|
+
else
|
|
328
|
+
keyseq = nil
|
|
329
|
+
end
|
|
330
|
+
if func_name =~ /"(.*)"/
|
|
331
|
+
func = parse_keyseq($1)
|
|
332
|
+
else
|
|
333
|
+
func = func_name.split.first.tr(?-, ?_).to_sym # It must be macro.
|
|
334
|
+
end
|
|
335
|
+
[keyseq, func]
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
def key_notation_to_code(notation)
|
|
339
|
+
case notation
|
|
340
|
+
when /(?:\\(?:C|Control)-\\(?:M|Meta)|\\(?:M|Meta)-\\(?:C|Control))-([A-Za-z_])/
|
|
341
|
+
[?\e.ord, $1.ord % 32]
|
|
342
|
+
when /\\(?:C|Control)-([A-Za-z_])/
|
|
343
|
+
($1.upcase.ord % 32)
|
|
344
|
+
when /\\(?:M|Meta)-([0-9A-Za-z_])/
|
|
345
|
+
[?\e.ord, $1.ord]
|
|
346
|
+
when /\\(\d{1,3})/ then $1.to_i(8) # octal
|
|
347
|
+
when /\\x(\h{1,2})/ then $1.to_i(16) # hexadecimal
|
|
348
|
+
when "\\e" then ?\e.ord
|
|
349
|
+
when "\\\\" then ?\\.ord
|
|
350
|
+
when "\\\"" then ?".ord
|
|
351
|
+
when "\\'" then ?'.ord
|
|
352
|
+
when "\\a" then ?\a.ord
|
|
353
|
+
when "\\b" then ?\b.ord
|
|
354
|
+
when "\\d" then ?\d.ord
|
|
355
|
+
when "\\f" then ?\f.ord
|
|
356
|
+
when "\\n" then ?\n.ord
|
|
357
|
+
when "\\r" then ?\r.ord
|
|
358
|
+
when "\\t" then ?\t.ord
|
|
359
|
+
when "\\v" then ?\v.ord
|
|
360
|
+
else notation.ord
|
|
361
|
+
end
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
def parse_keyseq(str)
|
|
365
|
+
str.scan(KEYSEQ_PATTERN).flat_map do |notation|
|
|
366
|
+
key_notation_to_code(notation)
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
def reload
|
|
371
|
+
reset_variables
|
|
372
|
+
read
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
private def seven_bit_encoding?(encoding)
|
|
376
|
+
encoding == Encoding::US_ASCII
|
|
377
|
+
end
|
|
378
|
+
end
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Reline::Face
|
|
4
|
+
SGR_PARAMETERS = {
|
|
5
|
+
foreground: {
|
|
6
|
+
black: 30,
|
|
7
|
+
red: 31,
|
|
8
|
+
green: 32,
|
|
9
|
+
yellow: 33,
|
|
10
|
+
blue: 34,
|
|
11
|
+
magenta: 35,
|
|
12
|
+
cyan: 36,
|
|
13
|
+
white: 37,
|
|
14
|
+
bright_black: 90,
|
|
15
|
+
gray: 90,
|
|
16
|
+
bright_red: 91,
|
|
17
|
+
bright_green: 92,
|
|
18
|
+
bright_yellow: 93,
|
|
19
|
+
bright_blue: 94,
|
|
20
|
+
bright_magenta: 95,
|
|
21
|
+
bright_cyan: 96,
|
|
22
|
+
bright_white: 97
|
|
23
|
+
},
|
|
24
|
+
background: {
|
|
25
|
+
black: 40,
|
|
26
|
+
red: 41,
|
|
27
|
+
green: 42,
|
|
28
|
+
yellow: 43,
|
|
29
|
+
blue: 44,
|
|
30
|
+
magenta: 45,
|
|
31
|
+
cyan: 46,
|
|
32
|
+
white: 47,
|
|
33
|
+
bright_black: 100,
|
|
34
|
+
gray: 100,
|
|
35
|
+
bright_red: 101,
|
|
36
|
+
bright_green: 102,
|
|
37
|
+
bright_yellow: 103,
|
|
38
|
+
bright_blue: 104,
|
|
39
|
+
bright_magenta: 105,
|
|
40
|
+
bright_cyan: 106,
|
|
41
|
+
bright_white: 107,
|
|
42
|
+
},
|
|
43
|
+
style: {
|
|
44
|
+
reset: 0,
|
|
45
|
+
bold: 1,
|
|
46
|
+
faint: 2,
|
|
47
|
+
italicized: 3,
|
|
48
|
+
underlined: 4,
|
|
49
|
+
slowly_blinking: 5,
|
|
50
|
+
blinking: 5,
|
|
51
|
+
rapidly_blinking: 6,
|
|
52
|
+
negative: 7,
|
|
53
|
+
concealed: 8,
|
|
54
|
+
crossed_out: 9
|
|
55
|
+
}
|
|
56
|
+
}.freeze
|
|
57
|
+
|
|
58
|
+
class Config
|
|
59
|
+
ESSENTIAL_DEFINE_NAMES = %i(default enhanced scrollbar).freeze
|
|
60
|
+
RESET_SGR = "\e[0m".freeze
|
|
61
|
+
|
|
62
|
+
def initialize(name, &block)
|
|
63
|
+
@definition = {}
|
|
64
|
+
block.call(self)
|
|
65
|
+
ESSENTIAL_DEFINE_NAMES.each do |name|
|
|
66
|
+
@definition[name] ||= { style: :reset, escape_sequence: RESET_SGR }
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
attr_reader :definition
|
|
71
|
+
|
|
72
|
+
def define(name, **values)
|
|
73
|
+
values[:escape_sequence] = format_to_sgr(values.to_a).freeze
|
|
74
|
+
@definition[name] = values
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def reconfigure
|
|
78
|
+
@definition.each_value do |values|
|
|
79
|
+
values.delete(:escape_sequence)
|
|
80
|
+
values[:escape_sequence] = format_to_sgr(values.to_a).freeze
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def [](name)
|
|
85
|
+
@definition.dig(name, :escape_sequence) or raise ArgumentError, "unknown face: #{name}"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
private
|
|
89
|
+
|
|
90
|
+
def sgr_rgb(key, value)
|
|
91
|
+
return nil unless rgb_expression?(value)
|
|
92
|
+
if Reline::Face.truecolor?
|
|
93
|
+
sgr_rgb_truecolor(key, value)
|
|
94
|
+
else
|
|
95
|
+
sgr_rgb_256color(key, value)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def sgr_rgb_truecolor(key, value)
|
|
100
|
+
case key
|
|
101
|
+
when :foreground
|
|
102
|
+
"38;2;"
|
|
103
|
+
when :background
|
|
104
|
+
"48;2;"
|
|
105
|
+
end + value[1, 6].scan(/../).map(&:hex).join(";")
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def sgr_rgb_256color(key, value)
|
|
109
|
+
# 256 colors are
|
|
110
|
+
# 0..15: standard colors, high intensity colors
|
|
111
|
+
# 16..232: 216 colors (R, G, B each 6 steps)
|
|
112
|
+
# 233..255: grayscale colors (24 steps)
|
|
113
|
+
# This methods converts rgb_expression to 216 colors
|
|
114
|
+
rgb = value[1, 6].scan(/../).map(&:hex)
|
|
115
|
+
# Color steps are [0, 95, 135, 175, 215, 255]
|
|
116
|
+
r, g, b = rgb.map { |v| v <= 95 ? v / 48 : (v - 35) / 40 }
|
|
117
|
+
color = (16 + 36 * r + 6 * g + b)
|
|
118
|
+
case key
|
|
119
|
+
when :foreground
|
|
120
|
+
"38;5;#{color}"
|
|
121
|
+
when :background
|
|
122
|
+
"48;5;#{color}"
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def format_to_sgr(ordered_values)
|
|
127
|
+
sgr = "\e[" + ordered_values.map do |key_value|
|
|
128
|
+
key, value = key_value
|
|
129
|
+
case key
|
|
130
|
+
when :foreground, :background
|
|
131
|
+
case value
|
|
132
|
+
when Symbol
|
|
133
|
+
SGR_PARAMETERS[key][value]
|
|
134
|
+
when String
|
|
135
|
+
sgr_rgb(key, value)
|
|
136
|
+
end
|
|
137
|
+
when :style
|
|
138
|
+
[ value ].flatten.map do |style_name|
|
|
139
|
+
SGR_PARAMETERS[:style][style_name]
|
|
140
|
+
end.then do |sgr_parameters|
|
|
141
|
+
sgr_parameters.include?(nil) ? nil : sgr_parameters
|
|
142
|
+
end
|
|
143
|
+
end.then do |rendition_expression|
|
|
144
|
+
unless rendition_expression
|
|
145
|
+
raise ArgumentError, "invalid SGR parameter: #{value.inspect}"
|
|
146
|
+
end
|
|
147
|
+
rendition_expression
|
|
148
|
+
end
|
|
149
|
+
end.join(';') + "m"
|
|
150
|
+
sgr == RESET_SGR ? RESET_SGR : RESET_SGR + sgr
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def rgb_expression?(color)
|
|
154
|
+
color.respond_to?(:match?) and color.match?(/\A#[0-9a-fA-F]{6}\z/)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
private_constant :SGR_PARAMETERS, :Config
|
|
159
|
+
|
|
160
|
+
def self.truecolor?
|
|
161
|
+
@force_truecolor || %w[truecolor 24bit].include?(ENV['COLORTERM'])
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def self.force_truecolor
|
|
165
|
+
@force_truecolor = true
|
|
166
|
+
@configs&.each_value(&:reconfigure)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def self.[](name)
|
|
170
|
+
@configs[name]
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def self.config(name, &block)
|
|
174
|
+
@configs ||= {}
|
|
175
|
+
@configs[name] = Config.new(name, &block)
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def self.configs
|
|
179
|
+
@configs.transform_values(&:definition)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def self.load_initial_configs
|
|
183
|
+
config(:default) do |conf|
|
|
184
|
+
conf.define :default, style: :reset
|
|
185
|
+
conf.define :enhanced, style: :reset
|
|
186
|
+
conf.define :scrollbar, style: :reset
|
|
187
|
+
end
|
|
188
|
+
config(:completion_dialog) do |conf|
|
|
189
|
+
conf.define :default, foreground: :bright_white, background: :gray
|
|
190
|
+
conf.define :enhanced, foreground: :black, background: :white
|
|
191
|
+
conf.define :scrollbar, foreground: :white, background: :gray
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def self.reset_to_initial_configs
|
|
196
|
+
@configs = {}
|
|
197
|
+
load_initial_configs
|
|
198
|
+
end
|
|
199
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
class Reline::History < Array
|
|
2
|
+
def initialize(config)
|
|
3
|
+
@config = config
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def to_s
|
|
7
|
+
'HISTORY'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def delete_at(index)
|
|
11
|
+
index = check_index(index)
|
|
12
|
+
super(index)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def [](index)
|
|
16
|
+
index = check_index(index) unless index.is_a?(Range)
|
|
17
|
+
super(index)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def []=(index, val)
|
|
21
|
+
index = check_index(index)
|
|
22
|
+
super(index, Reline::Unicode.safe_encode(val, Reline.encoding_system_needs))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def concat(*val)
|
|
26
|
+
val.each do |v|
|
|
27
|
+
push(*v)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def push(*val)
|
|
32
|
+
# If history_size is zero, all histories are dropped.
|
|
33
|
+
return self if @config.history_size.zero?
|
|
34
|
+
# If history_size is negative, history size is unlimited.
|
|
35
|
+
if @config.history_size.positive?
|
|
36
|
+
diff = size + val.size - @config.history_size
|
|
37
|
+
if diff > 0
|
|
38
|
+
if diff <= size
|
|
39
|
+
shift(diff)
|
|
40
|
+
else
|
|
41
|
+
diff -= size
|
|
42
|
+
clear
|
|
43
|
+
val.shift(diff)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
super(*(val.map{ |v|
|
|
48
|
+
Reline::Unicode.safe_encode(v, Reline.encoding_system_needs)
|
|
49
|
+
}))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def <<(val)
|
|
53
|
+
# If history_size is zero, all histories are dropped.
|
|
54
|
+
return self if @config.history_size.zero?
|
|
55
|
+
# If history_size is negative, history size is unlimited.
|
|
56
|
+
if @config.history_size.positive?
|
|
57
|
+
shift if size + 1 > @config.history_size
|
|
58
|
+
end
|
|
59
|
+
super(Reline::Unicode.safe_encode(val, Reline.encoding_system_needs))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private def check_index(index)
|
|
63
|
+
index += size if index < 0
|
|
64
|
+
if index < -2147483648 or 2147483647 < index
|
|
65
|
+
raise RangeError.new("integer #{index} too big to convert to 'int'")
|
|
66
|
+
end
|
|
67
|
+
# If history_size is negative, history size is unlimited.
|
|
68
|
+
if @config.history_size.positive?
|
|
69
|
+
if index < -@config.history_size or @config.history_size < index
|
|
70
|
+
raise RangeError.new("index=<#{index}>")
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
raise IndexError.new("index=<#{index}>") if index < 0 or size <= index
|
|
74
|
+
index
|
|
75
|
+
end
|
|
76
|
+
end
|