class RatatuiRuby::Event::Paste
Encapsulates pasted text.
Users frequently paste text into terminals. Without specific handling, a paste appears as a flood of rapid keystrokes, often triggering accidental commands or confusing the input state.
This event makes pasting safe. It groups the entire inserted block into a single atomic action.
Handle this event to support bulk text insertion cleanly. Insert the content directly into your field or buffer without triggering per-character logic.
Examples
Using predicates:
if event.paste? puts "Pasted: #{event.content}" end
Using pattern matching:
case event in type: :paste, content: puts "Pasted: #{content}" end
Attributes
The pasted content.
puts event.content # => "https://example.com"
Public Class Methods
Source
# File lib/ratatui_ruby/event/paste.rb, line 78 def initialize(content:) @content = content.freeze end
Creates a new Paste event.
- content
-
Pasted text (String).
Public Instance Methods
Source
# File lib/ratatui_ruby/event/paste.rb, line 102 def ==(other) return false unless other.is_a?(Paste) content == other.content end
Compares this event with another for equality.
Source
# File lib/ratatui_ruby/event/paste.rb, line 113 def blank? @content.strip.empty? end
Returns true if the pasted content is empty or whitespace-only.
Source
# File lib/ratatui_ruby/event/paste.rb, line 96 def deconstruct_keys(keys) { type: :paste, content: @content } end
Deconstructs the event for pattern matching.
case event in type: :paste, content: puts "User pasted: #{content}" end
Source
# File lib/ratatui_ruby/event/paste.rb, line 108 def empty? @content.empty? end
Returns true if the pasted content is empty.
Source
# File lib/ratatui_ruby/event/paste.rb, line 118 def multiline? @content.include?("\n") end
Returns true if the pasted content spans multiple lines.
Source
# File lib/ratatui_ruby/event/paste.rb, line 67 def paste? true end
Returns true for Paste events.
event.paste? # => true event.key? # => false event.resize? # => false
Source
# File lib/ratatui_ruby/event/paste.rb, line 124 def single_line? !multiline? end
Returns true if the pasted content is a single line.