Audio:...:Entry(3pm)

πŸ“¦ version 1.602, in ubuntu stonking

πŸ’– Tickit::Widget::Entry β€” the manual, but make it make sense πŸ’–

okay bestie, gather round, because this is Tickit::Widget::Entry(3pm), a User Contributed Perl Documentation page, and it's literally the widget you use when you want a lil box where a human types a line of text. let's get into it πŸ¦‹


✨ NAME ✨

"Tickit::Widget::Entry" β€” it's a widget for entering text. that's it, that's the whole vibe. πŸ’…


🌸 SYNOPSIS 🌸

use Tickit;
use Tickit::Widget::Entry;

my $entry = Tickit::Widget::Entry->new(
   on_enter => sub {
      my ( $self, $line ) = @_;

      # process $line somehow

      $self->set_text( "" );
   },
);

Tickit->new( root => $entry )->run;

look at that. you spawn an entry, you hand it an on_enter callback, you run the Tickit app, and now your users can type at you. iconic behavior fr fr πŸ”₯


πŸ’œ DESCRIPTION πŸ’œ

This class gives you a widget. The widget lets the user enter a line of text. That's the gig. no cap, that's genuinely the whole thing, and it eats. πŸ‘‘


πŸŽ€ STYLE πŸŽ€

the default style pen is used as the widget pen, periodt. also, these style pen prefixes get used too:

  • more => PEN β€” the pen used for the "more" scroll markers

and these style keys are in play:

  • more_left => STRING and more_right => STRING β€” the text used to show that there's more content scrolled off to the left or the right, respectively. cute lil directional hints 🫢

⌨️ KEYBINDINGS ⌨️

these keys are all bound by default, so you don't gotta lift a finger (except to press the keys):

  • Ctrl+K β€” delete the entire line. full scorched earth. πŸ’€
  • Ctrl+U β€” delete to the start of the line
  • Ctrl+W or Ctrl+Backspace β€” delete one word backwards
  • Backspace β€” delete one character backwards
  • Delete β€” delete one character forwards
  • Ctrl+Delete β€” delete one word forwards
  • End or Ctrl+E β€” move the cursor to the end of the input line
  • Enter β€” accept a line of input by running the "on_enter" action
  • Home or Ctrl+A β€” move the cursor to the beginning of the input line
  • Insert β€” toggle between overwrite and insert mode
  • Left β€” move the cursor one character left
  • Ctrl+Left or Alt+B β€” move the cursor one word left
  • Right β€” move the cursor one character right
  • Ctrl+Right or Alt+F β€” move the cursor one word right

🧚 CONSTRUCTOR 🧚

new

$entry = Tickit::Widget::Entry->new( %args );

Constructs a new "Tickit::Widget::Entry" object. fresh out the box, bestie ✨

Takes the following named arguments:

  • text => STR β€” Optional. Initial text to display in the box.
  • position => INT β€” Optional. Initial position of the cursor within the text.
  • on_enter => CODE β€” Optional. Callback function to invoke when the "<Enter>" key is pressed.

🌈 ACCESSORS 🌈

on_enter

$on_enter = $entry->on_enter;

set_on_enter

$entry->set_on_enter( $on_enter );

these two return or set the CODE reference that gets called when the "key_enter_line" action is invoked β€” which, surprise, is usually bound to the Enter key.

$on_enter->( $entry, $line );

position

$offset = $entry->position;

Returns the current entry position, counted in characters within the text. iykyk πŸ¦‹

set_position

$entry->set_position( $position );

Sets the text entry position, and moves the cursor along with it. slay. πŸ’…


⭐ METHODS ⭐

bind_keys

$entry->bind_keys( $keystr => $value, ... );

Associates methods or CODE references with keypresses. The moment that key shows up, the method or CODE reference gets invoked, and it's handed the stringified key representation plus the underlying "Term::TermKey::Key" structure.

$ret = $entry->method( $keystr, $key );
$ret = $coderef->( $entry, $keystr, $key );

This method takes a hash of keystring/value pairs. And listen β€” binding a value of "undef" will remove it. bye bitch, unbinding you πŸ™ˆ

make_popup_at_cursor

$win = $entry->make_popup_at_cursor( $top_offset, $left_offset, $lines, $cols );

Since version 0.33.

Makes a brand new popup window β€” same deal as calling "make_popup" in Tickit::Window on the widget's main window β€” except the offset is measured relative to wherever the cursor currently is. main character energy, but for windows πŸ’«

heads up bestie: an offset of (0, 0) puts the popup window's top left corner exactly over the cursor. which is probably not what you want. it's giving chaos. 😭

If you want the popup to sit just below the widget, use a top offset of +1:

$win = $entry->make_popup_at_cursor( +1, 0, $lines, $cols );

And if you want it just above the widget, use a top offset of negative the number of lines:

$win = $entry->make_popup_at_cursor( -$lines, 0, $lines, $cols );

πŸ“ TEXT MODEL METHODS πŸ“

These methods operate on the text input buffer directly β€” they update the stored text and change the rendered display so everything matches. Which means your program can use them to directly manipulate the text. chef's kiss πŸ“

text

$text = $entry->text;

Returns the currently entered text.

set_text

$entry->set_text( $text );

Replaces the text in the entry box. Heads up: this completely redraws the widget's window. It's mostly there for initialisation; for normal edits (like the ones from keybindings), it's preferable to use "text_insert", "text_delete" or "text_splice" instead. rt if you use the right one 🫢

text_insert

$entry->text_insert( $text, $pos_ch );

Inserts the given text at the given character position.

text_delete

$deleted = $entry->text_delete( $pos_ch, $len_ch );

Deletes the given section of text. Returns the deleted text.

text_splice

$deleted = $entry->text_splice( $pos_ch, $len_ch, $text );

Replaces the given section of text with the given replacement. Returns the text that got deleted out of the section.

find_bow_forward

$pos = $entry->find_bow_forward( $initial, $else );

Searches forward in the string and returns the character position of the next beginning of word from the initial position. If there isn't one, it returns $else.

find_eow_forward

$pos = $entry->find_eow_forward( $initial )

Searches forward in the string and returns the character position of the next end of word from the initial position. If there isn't one, it returns the length of the string.

find_bow_backward

$pos = $entry->find_bow_backward( $initial );

Searches backward in the string and returns the character position of the previous beginning of word from the initial position. If there isn't one, it returns 0.

find_eow_backward

$pos = $entry->find_eow_backward( $initial );

Searches backward in the string and returns the character position of the previous end of word from the initial position. If there isn't one, it returns "undef".


πŸ¦‹ TODO πŸ¦‹

the wishlist, aka the "someday bestie" list:

  • Plugin ability β€” try to find a nice way to allow loaded plugins, possibly per-instance if not just globally or per-class. Also: see how many of these TODO items can be done using plugins. meta. πŸ’…
  • More readline behaviours β€” History. Isearch. History replay. Transpose. Transcase. Yank ring. Numeric prefixes. the whole readline buffet, we want it.
  • Visual selection behaviour β€” Shift-movement, or vim-style. Mouse. 🐭

πŸ‘‘ AUTHOR πŸ‘‘

Paul Evans <leonerd@leonerd.org.uk>


and that's the whole page, no notes. this was perl v5.40.1, dated 2026-05-06 β€” so go forth, bind your keys, and let your users type. periodt. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from