Module: Chamomile
- Defined in:
- lib/chamomile.rb,
lib/chamomile/frame.rb,
lib/chamomile/model.rb,
lib/chamomile/keymap.rb,
lib/chamomile/router.rb,
lib/chamomile/key_map.rb,
lib/chamomile/logging.rb,
lib/chamomile/options.rb,
lib/chamomile/program.rb,
lib/chamomile/testing.rb,
lib/chamomile/version.rb,
lib/chamomile/commands.rb,
lib/chamomile/messages.rb,
lib/chamomile/renderer.rb,
lib/chamomile/view_dsl.rb,
lib/chamomile/layout/raw.rb,
lib/chamomile/application.rb,
lib/chamomile/layout/base.rb,
lib/chamomile/layout/list.rb,
lib/chamomile/layout/text.rb,
lib/chamomile/input_reader.rb,
lib/chamomile/layout/panel.rb,
lib/chamomile/layout/table.rb,
lib/chamomile/styling/ansi.rb,
lib/chamomile/styling/join.rb,
lib/chamomile/styling/wrap.rb,
lib/chamomile/configuration.rb,
lib/chamomile/escape_parser.rb,
lib/chamomile/styling/align.rb,
lib/chamomile/styling/color.rb,
lib/chamomile/styling/place.rb,
lib/chamomile/styling/style.rb,
lib/chamomile/layout/spinner.rb,
lib/chamomile/styling/border.rb,
lib/chamomile/components/help.rb,
lib/chamomile/components/list.rb,
lib/chamomile/layout/vertical.rb,
lib/chamomile/components/table.rb,
lib/chamomile/components/timer.rb,
lib/chamomile/components/cursor.rb,
lib/chamomile/layout/horizontal.rb,
lib/chamomile/layout/status_bar.rb,
lib/chamomile/components/spinner.rb,
lib/chamomile/components/log_view.rb,
lib/chamomile/components/progress.rb,
lib/chamomile/components/viewport.rb,
lib/chamomile/components/paginator.rb,
lib/chamomile/components/stopwatch.rb,
lib/chamomile/components/text_area.rb,
lib/chamomile/components/text_input.rb,
lib/chamomile/styling/color_profile.rb,
lib/chamomile/components/file_picker.rb,
lib/chamomile/components/key_binding.rb,
lib/chamomile/components/list/key_map.rb,
lib/chamomile/components/render_cache.rb,
lib/chamomile/components/spinner/types.rb,
lib/chamomile/components/table/key_map.rb,
lib/chamomile/components/command_palette.rb,
lib/chamomile/components/viewport/key_map.rb,
lib/chamomile/components/paginator/key_map.rb,
lib/chamomile/components/text_area/key_map.rb,
lib/chamomile/components/text_input/key_map.rb,
lib/chamomile/components/file_picker/key_map.rb
Overview
:nodoc:
Defined Under Namespace
Modules: ANSI, Align, Application, Border, Color, ColorProfile, Commands, Join, KeyBinding, KeyMap, Layout, Model, Place, RenderCache, Router, Spinners, Testing, ViewDSL, Widgets, Wrap Classes: BlurEvent, BorderDef, CancelCommand, CancelToken, ClearScreenMsg, CommandPalette, Configuration, Cursor, CursorBlinkMsg, CursorPositionCommand, CursorShapeCommand, CursorVisibilityCommand, DisableBracketedPasteMsg, DisableMouseMsg, DisableReportFocusMsg, EnableBracketedPasteMsg, EnableMouseAllMotionMsg, EnableMouseCellMotionMsg, EnableReportFocusMsg, EnterAltScreenMsg, ErrorEvent, EscapeParser, ExecCommand, ExitAltScreenMsg, FilePicker, FilePickerReadDirMsg, FilterMatchesMsg, FocusEvent, Frame, Help, InputReader, InterruptEvent, KeyEvent, Keymap, List, ListStatusTimeoutMsg, LogView, MouseEvent, NullRenderer, Options, Paginator, PasteEvent, PrintlnCommand, Program, Progress, ProgressFrameMsg, QuitEvent, Renderer, RequestWindowSizeMsg, ResizeEvent, ResumeEvent, ShellResult, Spinner, SpinnerTickMsg, SpinnerType, Stopwatch, StopwatchTickMsg, StreamCommand, Style, SuspendEvent, Table, TextArea, TextInput, TickEvent, Timer, TimerTick, TimerTickMsg, TimerTimeoutMsg, Viewport, WindowTitleCommand
Constant Summary collapse
- TOP =
Position constants
0.0- LEFT =
0.0- CENTER =
0.5- BOTTOM =
1.0- RIGHT =
1.0- POSITION_MAP =
Symbol-to-float position map
{ top: 0.0, left: 0.0, center: 0.5, bottom: 1.0, right: 1.0, }.freeze
- VALID_MOUSE_MODES =
%i[none cell_motion all_motion].freeze
- VERSION =
"1.0.0"- WindowTitleCmd =
backward compat
WindowTitleCommand- CursorPositionCmd =
backward compat
CursorPositionCommand- CursorShapeCmd =
backward compat
CursorShapeCommand- CursorVisibilityCmd =
backward compat
CursorVisibilityCommand- ExecCmd =
backward compat
ExecCommand- PrintlnCmd =
backward compat
PrintlnCommand- CancelCmd =
backward compat
CancelCommand- StreamCmd =
backward compat
StreamCommand- QuitMsg =
backward compat
QuitEvent- WindowSizeMsg =
backward compat
ResizeEvent- KeyMsg =
backward compat
KeyEvent- MOUSE_LEFT =
Mouse button constants
:left- MOUSE_MIDDLE =
:middle- MOUSE_RIGHT =
:right- MOUSE_NONE =
:none- MOUSE_WHEEL_UP =
:wheel_up- MOUSE_WHEEL_DOWN =
:wheel_down- MOUSE_PRESS =
Mouse action constants
:press- MOUSE_RELEASE =
:release- MOUSE_MOTION =
:motion- MouseMsg =
backward compat
MouseEvent- PasteMsg =
backward compat
PasteEvent- FocusMsg =
backward compat
FocusEvent- BlurMsg =
backward compat
BlurEvent- InterruptMsg =
backward compat
InterruptEvent- SuspendMsg =
backward compat
SuspendEvent- ResumeMsg =
backward compat
ResumeEvent- ErrorMsg =
backward compat
ErrorEvent- TickMsg =
backward compat
TickEvent
Class Method Summary collapse
- .close_log ⇒ Object
- .height(str) ⇒ Object
-
.horizontal(strs = nil, align: :top, &block) ⇒ Object
New primary API — accepts array or block, keyword align.
-
.join_horizontal(position, *strs) ⇒ Object
Old API — kept for backward compat.
-
.join_vertical(position, *strs) ⇒ Object
Old API — kept for backward compat.
- .log(msg, level: :debug) ⇒ Object
- .log_to_file(path) ⇒ Object
-
.place(first, second = nil, third = nil, fourth = nil, fifth = nil, width: nil, height: nil, align: :left, valign: :top, content: nil) ⇒ Object
New primary API — content first, keyword args Also supports old positional form for backward compat.
- .place_horizontal(width, pos, str) ⇒ Object
- .place_vertical(height, pos, str) ⇒ Object
-
.resolve_position(val) ⇒ Object
Convert symbol positions to float values.
- .run(model, **opts, &block) ⇒ Object
- .size(str) ⇒ Object
-
.vertical(strs = nil, align: :left, &block) ⇒ Object
New primary API — accepts array or block, keyword align.
- .width(str) ⇒ Object
Class Method Details
.close_log ⇒ Object
28 29 30 31 32 33 |
# File 'lib/chamomile/logging.rb', line 28 def self.close_log @log_mutex.synchronize do @logger&.close @logger = nil end end |
.height(str) ⇒ Object
104 105 106 |
# File 'lib/chamomile.rb', line 104 def height(str) ANSI.height(str) end |
.horizontal(strs = nil, align: :top, &block) ⇒ Object
New primary API — accepts array or block, keyword align
113 114 115 116 117 |
# File 'lib/chamomile.rb', line 113 def horizontal(strs = nil, align: :top, &block) strs = block.call if block && strs.nil? strs = Array(strs) Join.horizontal(resolve_position(align), *strs) end |
.join_horizontal(position, *strs) ⇒ Object
Old API — kept for backward compat
142 143 144 |
# File 'lib/chamomile.rb', line 142 def join_horizontal(position, *strs) Join.horizontal(resolve_position(position), *strs) end |
.join_vertical(position, *strs) ⇒ Object
Old API — kept for backward compat
147 148 149 |
# File 'lib/chamomile.rb', line 147 def join_vertical(position, *strs) Join.vertical(resolve_position(position), *strs) end |
.log(msg, level: :debug) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/chamomile/logging.rb', line 20 def self.log(msg, level: :debug) @log_mutex.synchronize do return unless @logger @logger.send(level, msg) end end |
.log_to_file(path) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/chamomile/logging.rb', line 10 def self.log_to_file(path) @log_mutex.synchronize do @logger&.close @logger = Logger.new(path) @logger.formatter = proc { |severity, time, _, msg| "#{time.strftime("%Y-%m-%d %H:%M:%S.%L")} [#{severity}] #{msg}\n" } end end |
.place(first, second = nil, third = nil, fourth = nil, fifth = nil, width: nil, height: nil, align: :left, valign: :top, content: nil) ⇒ Object
New primary API — content first, keyword args Also supports old positional form for backward compat
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/chamomile.rb', line 128 def place(first, second = nil, third = nil, fourth = nil, fifth = nil, width: nil, height: nil, align: :left, valign: :top, content: nil) if fifth # Old 5-arg form: place(width, height, h_pos, v_pos, str) Place.place(first, second, resolve_position(third), resolve_position(fourth), fifth.to_s) else # New keyword form: place(content, width:, height:, align:, valign:) content = (content || first).to_s Place.place(width || 80, height || 24, resolve_position(align), resolve_position(valign), content) end end |
.place_horizontal(width, pos, str) ⇒ Object
151 152 153 |
# File 'lib/chamomile.rb', line 151 def place_horizontal(width, pos, str) Place.place_horizontal(width, resolve_position(pos), str) end |
.place_vertical(height, pos, str) ⇒ Object
155 156 157 |
# File 'lib/chamomile.rb', line 155 def place_vertical(height, pos, str) Place.place_vertical(height, resolve_position(pos), str) end |
.resolve_position(val) ⇒ Object
Convert symbol positions to float values. Accepts symbols (:top, :left, :center, :bottom, :right) or floats.
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/chamomile.rb', line 161 def resolve_position(val) case val when Symbol POSITION_MAP.fetch(val) { raise ArgumentError, "Unknown position: #{val.inspect}" } when Numeric val.to_f else raise ArgumentError, "Expected a Symbol or Numeric position, got #{val.inspect}" end end |
.run(model, **opts, &block) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/chamomile.rb', line 91 def run(model, **opts, &block) if block config = Configuration.new block.call(config) opts = config.to_h.merge(opts) end Program.new(model, **opts).run end |
.size(str) ⇒ Object
108 109 110 |
# File 'lib/chamomile.rb', line 108 def size(str) ANSI.size(str) end |
.vertical(strs = nil, align: :left, &block) ⇒ Object
New primary API — accepts array or block, keyword align
120 121 122 123 124 |
# File 'lib/chamomile.rb', line 120 def vertical(strs = nil, align: :left, &block) strs = block.call if block && strs.nil? strs = Array(strs) Join.vertical(resolve_position(align), *strs) end |
.width(str) ⇒ Object
100 101 102 |
# File 'lib/chamomile.rb', line 100 def width(str) ANSI.printable_width(str) end |