module Chamomile::Commands
Helper methods for creating command lambdas (quit, batch, tick, etc.).
Public Class Methods
Source
# File lib/chamomile/commands.rb, line 77 def batch(*cmds) valid = cmds.flatten.compact return nil if valid.empty? -> { valid } end
Source
# File lib/chamomile/commands.rb, line 145 def cancel(token) -> { CancelCommand.new(token: token) } end
Returns a command that cancels a running token.
Source
# File lib/chamomile/commands.rb, line 134 def cancellable(&block) token = CancelToken.new wrapped = -> { return nil if token.cancelled? block.call(token) } [token, wrapped] end
Creates a cancel token and returns [token, command_wrapper]. The block receives the token for cooperative cancellation checking.
Source
# File lib/chamomile/commands.rb, line 250 def clear_screen -> { ClearScreenMsg.new } end
Source
# File lib/chamomile/commands.rb, line 113 def cmd(callable) -> { callable.call } end
Source
# File lib/chamomile/commands.rb, line 188 def cursor_position(row, col) -> { CursorPositionCommand.new(row: row, col: col) } end
Source
# File lib/chamomile/commands.rb, line 192 def cursor_shape(shape) -> { CursorShapeCommand.new(shape: shape) } end
Source
# File lib/chamomile/commands.rb, line 118 def deliver(msg) -> { msg } end
Posts a message directly to the event queue β no thread, no async.
Source
# File lib/chamomile/commands.rb, line 238 def disable_bracketed_paste -> { DisableBracketedPasteMsg.new } end
Source
# File lib/chamomile/commands.rb, line 230 def disable_mouse -> { DisableMouseMsg.new } end
Source
# File lib/chamomile/commands.rb, line 246 def disable_report_focus -> { DisableReportFocusMsg.new } end
Source
# File lib/chamomile/commands.rb, line 234 def enable_bracketed_paste -> { EnableBracketedPasteMsg.new } end
Source
# File lib/chamomile/commands.rb, line 226 def enable_mouse_all_motion -> { EnableMouseAllMotionMsg.new } end
Source
# File lib/chamomile/commands.rb, line 222 def enable_mouse_cell_motion -> { EnableMouseCellMotionMsg.new } end
Source
# File lib/chamomile/commands.rb, line 242 def enable_report_focus -> { EnableReportFocusMsg.new } end
Source
# File lib/chamomile/commands.rb, line 214 def enter_alt_screen -> { EnterAltScreenMsg.new } end
Runtime mode toggles β return these as commands from update
Source
# File lib/chamomile/commands.rb, line 104 def every(duration, &block) -> { now = Time.now next_tick = (now + duration) - (now.to_f % duration) sleep(next_tick - Time.now) block ? block.call : TickEvent.new(time: Time.now) } end
Source
# File lib/chamomile/commands.rb, line 204 def exec(command, *args, &callback) -> { ExecCommand.new(command: command, args: args, callback: callback) } end
Source
# File lib/chamomile/commands.rb, line 218 def exit_alt_screen -> { ExitAltScreenMsg.new } end
Source
# File lib/chamomile/commands.rb, line 200 def hide_cursor -> { CursorVisibilityCommand.new(visible: false) } end
Source
# File lib/chamomile/commands.rb, line 123 def map(cmd, &transform) return nil if cmd.nil? -> { result = cmd.call result ? transform.call(result) : nil } end
Transforms a commandβs result before it reaches update.
Source
# File lib/chamomile/commands.rb, line 209 def println(text) -> { PrintlnCommand.new(text: text) } end
Print a line above the rendered TUI area
Source
# File lib/chamomile/commands.rb, line 254 def request_window_size -> { RequestWindowSizeMsg.new } end
Source
# File lib/chamomile/commands.rb, line 84 def sequence(*cmds) valid = cmds.flatten.compact return nil if valid.empty? -> { [:sequence, *valid] } end
Source
# File lib/chamomile/commands.rb, line 163 def shell(command, envelope:, dir: Dir.pwd, env: {}) -> { stdout, stderr, status = Open3.capture3(env, command, chdir: dir) ShellResult.new( envelope: envelope, stdout: stdout.force_encoding("UTF-8"), stderr: stderr.force_encoding("UTF-8"), status: status.exitstatus, success: status.success? ) } end
Run a shell command and return a ShellResult message with the given envelope name.
Source
# File lib/chamomile/commands.rb, line 196 def show_cursor -> { CursorVisibilityCommand.new(visible: true) } end
Source
# File lib/chamomile/commands.rb, line 152 def stream(&block) token = CancelToken.new cmd = -> { return nil if token.cancelled? StreamCommand.new(token: token, producer: block) } [token, cmd] end
A streaming command that emits multiple messages over time. The block receives a push callable and a token for cancellation. Returns [cancel_token, command].
Source
# File lib/chamomile/commands.rb, line 97 def tick(duration, &block) -> { sleep(duration) block ? block.call : TickEvent.new(time: Time.now) } end
Source
# File lib/chamomile/commands.rb, line 177 def timer(duration, envelope:) -> { sleep(duration) TimerTick.new(envelope: envelope, time: Time.now) } end
Fire a timer message with a typed envelope.
Source
# File lib/chamomile/commands.rb, line 184 def window_title(title) -> { WindowTitleCommand.new(title: title) } end