Class: RatatuiRuby::Event::Paste

Inherits:
RatatuiRuby::Event show all
Defined in:
lib/ratatui_ruby/event/paste.rb

Overview

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: – SPDX-SnippetBegin SPDX-FileCopyrightText: 2025 Kerrick Long SPDX-License-Identifier: MIT-0 ++

if event.paste?
  puts "Pasted: #{event.content}"
end

– SPDX-SnippetEnd ++ Using pattern matching: – SPDX-SnippetBegin SPDX-FileCopyrightText: 2025 Kerrick Long SPDX-License-Identifier: MIT-0 ++

case event
in type: :paste, content:
  puts "Pasted: #{content}"
end

– SPDX-SnippetEnd ++

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RatatuiRuby::Event

#focus_gained?, #focus_lost?, #key?, #method_missing, #mouse?, #none?, #resize?, #respond_to_missing?, #sync?

Constructor Details

#initialize(content:) ⇒ Paste

Creates a new Paste event.

content

Pasted text (String).



78
79
80
# File 'lib/ratatui_ruby/event/paste.rb', line 78

def initialize(content:)
  @content = content.freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RatatuiRuby::Event

Instance Attribute Details

#contentObject (readonly)

The pasted content.

puts event.content # => "https://example.com"


52
53
54
# File 'lib/ratatui_ruby/event/paste.rb', line 52

def content
  @content
end

Instance Method Details

#==(other) ⇒ Object

Compares this event with another for equality.



102
103
104
105
# File 'lib/ratatui_ruby/event/paste.rb', line 102

def ==(other)
  return false unless other.is_a?(Paste)
  content == other.content
end

#blank?Boolean

Returns true if the pasted content is empty or whitespace-only.

Returns:

  • (Boolean)


113
114
115
# File 'lib/ratatui_ruby/event/paste.rb', line 113

def blank?
  @content.strip.empty?
end

#deconstruct_keys(keys) ⇒ Object

Deconstructs the event for pattern matching.

– SPDX-SnippetBegin SPDX-FileCopyrightText: 2025 Kerrick Long SPDX-License-Identifier: MIT-0 ++

case event
in type: :paste, content:
  puts "User pasted: #{content}"
end

– SPDX-SnippetEnd ++



96
97
98
# File 'lib/ratatui_ruby/event/paste.rb', line 96

def deconstruct_keys(keys)
  { type: :paste, content: @content }
end

#empty?Boolean

Returns true if the pasted content is empty.

Returns:

  • (Boolean)


108
109
110
# File 'lib/ratatui_ruby/event/paste.rb', line 108

def empty?
  @content.empty?
end

#multiline?Boolean Also known as: multi_line?

Returns true if the pasted content spans multiple lines.

Returns:

  • (Boolean)


118
119
120
# File 'lib/ratatui_ruby/event/paste.rb', line 118

def multiline?
  @content.include?("\n")
end

#paste?Boolean Also known as: clipboard?, pasteboard?, pasted?

Returns true for Paste events.

– SPDX-SnippetBegin SPDX-FileCopyrightText: 2025 Kerrick Long SPDX-License-Identifier: MIT-0 ++

event.paste?  # => true
event.key?    # => false
event.resize? # => false

– SPDX-SnippetEnd ++

Returns:

  • (Boolean)


67
68
69
# File 'lib/ratatui_ruby/event/paste.rb', line 67

def paste?
  true
end

#single_line?Boolean Also known as: singleline?

Returns true if the pasted content is a single line.

Returns:

  • (Boolean)


124
125
126
# File 'lib/ratatui_ruby/event/paste.rb', line 124

def single_line?
  !multiline?
end