Module: Charming
- Defined in:
- lib/charming/spring.rb,
lib/charming.rb,
lib/charming/cli.rb,
lib/charming/image.rb,
lib/charming/escape.rb,
lib/charming/router.rb,
lib/charming/screen.rb,
lib/charming/runtime.rb,
lib/charming/version.rb,
lib/charming/welcome.rb,
lib/charming/response.rb,
lib/charming/controller.rb,
lib/charming/projectile.rb,
lib/charming/tasks/task.rb,
lib/charming/application.rb,
lib/charming/test_helper.rb,
lib/charming/audio/player.rb,
lib/charming/audio/system.rb,
lib/charming/image/source.rb,
lib/charming/image/protocol.rb,
lib/charming/image/terminal.rb,
lib/charming/image/transmit.rb,
lib/charming/tasks/progress.rb,
lib/charming/generators/base.rb,
lib/charming/generators/name.rb,
lib/charming/presentation/ui.rb,
lib/charming/tasks/cancelled.rb,
lib/charming/controller/focus.rb,
lib/charming/events/key_event.rb,
lib/charming/generators/error.rb,
lib/charming/application_state.rb,
lib/charming/controller/timers.rb,
lib/charming/database/commands.rb,
lib/charming/events/task_event.rb,
lib/charming/presentation/view.rb,
lib/charming/welcome/show_view.rb,
lib/charming/events/focus_event.rb,
lib/charming/events/mouse_event.rb,
lib/charming/events/paste_event.rb,
lib/charming/events/timer_event.rb,
lib/charming/welcome/controller.rb,
lib/charming/controller/terminal.rb,
lib/charming/events/resize_event.rb,
lib/charming/internal/event_loop.rb,
lib/charming/presentation/layout.rb,
lib/charming/controller/rendering.rb,
lib/charming/image/protocol/kitty.rb,
lib/charming/presentation/markdown.rb,
lib/charming/presentation/ui/style.rb,
lib/charming/presentation/ui/theme.rb,
lib/charming/presentation/ui/width.rb,
lib/charming/tasks/inline_executor.rb,
lib/charming/controller/dispatching.rb,
lib/charming/internal/timer_control.rb,
lib/charming/presentation/component.rb,
lib/charming/presentation/templates.rb,
lib/charming/presentation/ui/border.rb,
lib/charming/presentation/ui/canvas.rb,
lib/charming/controller/action_hooks.rb,
lib/charming/controller/key_dispatch.rb,
lib/charming/tasks/threaded_executor.rb,
lib/charming/controller/class_methods.rb,
lib/charming/controller/session_state.rb,
lib/charming/generators/app_generator.rb,
lib/charming/presentation/layout/pane.rb,
lib/charming/presentation/layout/rect.rb,
lib/charming/presentation/ui/gradient.rb,
lib/charming/presentation/ui/truncate.rb,
lib/charming/generators/view_generator.rb,
lib/charming/internal/terminal/adapter.rb,
lib/charming/presentation/layout/split.rb,
lib/charming/controller/command_palette.rb,
lib/charming/events/task_progress_event.rb,
lib/charming/generators/model_generator.rb,
lib/charming/presentation/template_view.rb,
lib/charming/presentation/ui/ansi_codes.rb,
lib/charming/presentation/ui/background.rb,
lib/charming/controller/focus_management.rb,
lib/charming/generators/layout_generator.rb,
lib/charming/generators/screen_generator.rb,
lib/charming/presentation/layout/builder.rb,
lib/charming/presentation/layout/overlay.rb,
lib/charming/presentation/ui/ansi_slicer.rb,
lib/charming/presentation/components/form.rb,
lib/charming/presentation/components/list.rb,
lib/charming/presentation/components/tree.rb,
lib/charming/presentation/ui/text_wrapper.rb,
lib/charming/controller/sidebar_navigation.rb,
lib/charming/generators/app_file_generator.rb,
lib/charming/generators/database_installer.rb,
lib/charming/internal/terminal/tty_backend.rb,
lib/charming/presentation/components/audio.rb,
lib/charming/presentation/components/badge.rb,
lib/charming/presentation/components/chart.rb,
lib/charming/presentation/components/image.rb,
lib/charming/presentation/components/modal.rb,
lib/charming/presentation/components/table.rb,
lib/charming/presentation/components/timer.rb,
lib/charming/presentation/components/toast.rb,
lib/charming/presentation/ui/color_support.rb,
lib/charming/generators/component_generator.rb,
lib/charming/generators/migration_generator.rb,
lib/charming/generators/migration_timestamp.rb,
lib/charming/internal/renderer/differential.rb,
lib/charming/internal/renderer/full_repaint.rb,
lib/charming/internal/terminal/mouse_parser.rb,
lib/charming/presentation/layout/pane_style.rb,
lib/charming/presentation/markdown/renderer.rb,
lib/charming/presentation/ui/adaptive_color.rb,
lib/charming/presentation/ui/border_painter.rb,
lib/charming/presentation/ui/braille_canvas.rb,
lib/charming/generators/controller_generator.rb,
lib/charming/presentation/components/spinner.rb,
lib/charming/presentation/components/tab_bar.rb,
lib/charming/controller/component_dispatching.rb,
lib/charming/internal/terminal/key_normalizer.rb,
lib/charming/internal/terminal/memory_backend.rb,
lib/charming/presentation/components/markdown.rb,
lib/charming/presentation/components/viewport.rb,
lib/charming/presentation/components/form/note.rb,
lib/charming/presentation/components/paginator.rb,
lib/charming/presentation/components/sparkline.rb,
lib/charming/presentation/components/stopwatch.rb,
lib/charming/presentation/components/text_area.rb,
lib/charming/presentation/layout/pane_behavior.rb,
lib/charming/presentation/layout/pane_geometry.rb,
lib/charming/presentation/layout/screen_layout.rb,
lib/charming/presentation/components/filepicker.rb,
lib/charming/presentation/components/form/field.rb,
lib/charming/presentation/components/form/input.rb,
lib/charming/presentation/components/status_bar.rb,
lib/charming/presentation/components/text_input.rb,
lib/charming/presentation/markdown/style_config.rb,
lib/charming/presentation/markdown/url_resolver.rb,
lib/charming/presentation/templates/erb_handler.rb,
lib/charming/presentation/components/breadcrumbs.rb,
lib/charming/presentation/components/empty_state.rb,
lib/charming/presentation/components/form/select.rb,
lib/charming/presentation/components/progressbar.rb,
lib/charming/presentation/components/autocomplete.rb,
lib/charming/presentation/components/error_screen.rb,
lib/charming/presentation/components/form/builder.rb,
lib/charming/presentation/components/form/confirm.rb,
lib/charming/presentation/components/help_overlay.rb,
lib/charming/presentation/components/time_display.rb,
lib/charming/presentation/markdown/render_context.rb,
lib/charming/presentation/markdown/table_renderer.rb,
lib/charming/internal/terminal/modified_key_parser.rb,
lib/charming/presentation/components/form/textarea.rb,
lib/charming/presentation/components/fuzzy_matcher.rb,
lib/charming/presentation/components/command_palette.rb,
lib/charming/presentation/components/form/multiselect.rb,
lib/charming/presentation/components/keyboard_handler.rb,
lib/charming/presentation/markdown/syntax_highlighter.rb,
lib/charming/presentation/components/multi_select_list.rb,
lib/charming/presentation/components/viewport/position.rb,
lib/charming/presentation/components/activity_indicator.rb,
lib/charming/presentation/components/viewport/line_window.rb,
lib/charming/presentation/components/command_palette_modal.rb,
lib/charming/presentation/components/viewport/content_lines.rb,
sig/charming.rbs
Overview
Copyright (c) 2008-2012 Ryan Juckett http://www.ryanjuckett.com/
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
-
The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
-
Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-
This notice may not be removed or altered from any source distribution.
Ported to Go by Charmbracelet, Inc. in 2021 (charmbracelet/harmonica, MIT). Ported to Ruby for Charming in 2026 from charmbracelet/harmonica.
For background on the algorithm see: https://www.ryanjuckett.com/damped-springs/
Defined Under Namespace
Modules: Audio, Components, Database, Escape, Events, Generators, Image, Internal, Layout, Markdown, Tasks, Templates, TestHelper, UI, Welcome Classes: Application, ApplicationState, CLI, Component, Controller, Error, Projectile, Response, Router, Runtime, Screen, Spring, TemplateView, View
Constant Summary collapse
- VERSION =
"0.3.0"
Class Method Summary collapse
-
.env ⇒ Object
The current environment, read from CHARMING_ENV (default "development").
-
.env=(value) ⇒ Object
Overrides the environment (used by tests and the CLI).
-
.fps(frames_per_second) ⇒ Object
Returns the seconds-per-frame time delta for a frame rate, for initializing physics primitives:
Charming::Spring.new(delta_time: Charming.fps(60)). -
.key_binding_name(name) ⇒ Object
Normalizes key declarations so
control+pandctrl+presolve to the same binding. -
.key_of(event) ⇒ Object
Returns the normalized key symbol for an event-like object —
event.keywhen the object responds to it, otherwiseevent.to_sym. -
.key_signature(event) ⇒ Object
Returns the key signature used for controller bindings, including modifier flags.
-
.run(application, backend: nil) ⇒ Object
Entry point for running a Charming application.
Class Method Details
.env ⇒ Object
The current environment, read from CHARMING_ENV (default "development"). Returns a
StringInquirer so callers can write Charming.env.test? / Charming.env.production?.
31 32 33 |
# File 'lib/charming.rb', line 31 def self.env @env ||= ActiveSupport::StringInquirer.new(ENV["CHARMING_ENV"] || "development") end |
.env=(value) ⇒ Object
Overrides the environment (used by tests and the CLI).
36 37 38 |
# File 'lib/charming.rb', line 36 def self.env=(value) @env = value.nil? ? nil : ActiveSupport::StringInquirer.new(value.to_s) end |
.fps(frames_per_second) ⇒ Object
Returns the seconds-per-frame time delta for a frame rate, for initializing
physics primitives: Charming::Spring.new(delta_time: Charming.fps(60)).
48 49 50 |
# File 'lib/charming.rb', line 48 def self.fps(frames_per_second) 1.0 / frames_per_second end |
.key_binding_name(name) ⇒ Object
Normalizes key declarations so control+p and ctrl+p resolve to the same binding.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/charming.rb', line 73 def self.key_binding_name(name) parts = name.to_s.split("+") return name.to_sym if parts.size == 1 key = parts.pop.downcase modifiers = parts.map do |part| modifier = part.downcase (modifier == "control") ? "ctrl" : modifier end ordered_modifiers = %w[ctrl alt shift].select { |modifier| modifiers.include?(modifier) } ordered_modifiers += modifiers - ordered_modifiers :"#{(ordered_modifiers + [key]).join("+")}" end |
.key_of(event) ⇒ Object
Returns the normalized key symbol for an event-like object — event.key when the object responds
to it, otherwise event.to_sym. Lets components treat raw strings and KeyEvent objects uniformly.
54 55 56 57 |
# File 'lib/charming.rb', line 54 def self.key_of(event) key = event.respond_to?(:key) ? event.key : event key.to_sym end |
.key_signature(event) ⇒ Object
Returns the key signature used for controller bindings, including modifier flags.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/charming.rb', line 60 def self.key_signature(event) key = key_of(event) modifiers = [] modifiers << "ctrl" if event.respond_to?(:ctrl) && event.ctrl modifiers << "alt" if event.respond_to?(:alt) && event.alt modifiers << "shift" if event.respond_to?(:shift) && event.shift return key if modifiers.empty? :"#{modifiers.join("+")}+#{key}" end |
.run(application, backend: nil) ⇒ Object
Entry point for running a Charming application. Instantiates a Runtime for application and starts
the event loop. backend defaults to TTYBackend; tests pass MemoryBackend directly via Charming::Runtime.new.
42 43 44 |
# File 'lib/charming.rb', line 42 def self.run(application, backend: nil) Runtime.new(application, backend: backend).run end |