class Crystallabs::Helpers::KillRing

Overview

An emacs/readline-style kill ring: the shared text register that readline editing keys push deleted text into (Ctrl-W / Ctrl-U / Ctrl-K / Alt-D) and Ctrl-Y yanks back.

As in emacs, consecutive kills accumulate into one entry (so Ctrl-K Ctrl-K yanks both lines, and a backward kill prepends) until a non-kill action calls #interrupt. Older entries are retained up to #capacity for a future yank-pop.

Defined in:

crystallabs-helpers.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.default : KillRing #

Shared default ring (all inputs of a program, unless overridden).


[View source]
def self.new(capacity : Int32 = 60) #

[View source]

Class Method Detail

def self.default=(default : KillRing) #

Shared default ring (all inputs of a program, unless overridden).


[View source]

Instance Method Detail

def capacity : Int32 #

Maximum number of entries kept (older ones are dropped).


[View source]
def capacity=(capacity : Int32) #

Maximum number of entries kept (older ones are dropped).


[View source]
def clear : Nil #

Drops all entries (and resets the accumulation flag).


[View source]
def entries : Array(String) #

Kill entries, oldest first; the last is what #yank returns.


[View source]
def interrupt : Nil #

Marks that a non-kill action happened, so the next kill starts a new entry.


[View source]
def kill(text : String, *, prepend : Bool = false) : Nil #

Records text as a kill. A backward kill (prepend true — Ctrl-W / Ctrl-U) joins the front of the current entry; a forward kill (prepend false — Ctrl-K / Alt-D) joins the back. Consecutive kills merge; an intervening #interrupt starts a fresh entry. Empty text is ignored.


[View source]
def yank : String | Nil #

The most-recently killed text (what Ctrl-Y yanks), or nil when empty.


[View source]