module BBS::Petscii::Screen::Prompts
What a Screen asks the caller: a key (choose, pause), a line (ask), a text (edit), and the menus, which are BBS::Selector configurations (pick, menu, actions).
Public Instance Methods
Source
# File lib/bbs/petscii/screen/prompts.rb, line 105 def actions(*actions) puts menu(actions.map { |k, label| Selector.item(label, key: k, value: k) }, across: true, back: 'q') end
The keys of actions, [key, label] pairs, as a menu on one row under what is on the screen (after a line end), the cursor moving along it.
case screen.actions(%w[d download], %w[q back]) when 'd' then download end
Returns the key taken; 'q' for โ or RUN/STOP.
# File lib/bbs/petscii/screen/prompts.rb, line 36 def ask(prompt, text: '', mask: nil, max: nil) Field.ask(@session, prompt, text: text, max: max, mask: mask, cols: @cols).to_s.strip end
Writes prompt and reads a line in a BBS::Field after it, as wide as the rest of the screen, starting from text; mask hides what is typed, max limits its length.
Returns the line, stripped; empty when the caller cancelled with RUN/STOP or โ.
# File lib/bbs/petscii/screen/prompts.rb, line 17 def choose(prompt, keys, back: 'q') write "\r\n#{prompt}" loop do k = key k = back if k == :escape k = k.downcase if k.is_a?(String) next unless keys.include?(k) puts(k.is_a?(String) ? k.upcase : '') return k end end
Writes prompt on a new line and waits for one of keys (lowercase letters, or key symbols); โ and RUN/STOP (Esc) give back. Echoes the letter taken in capitals and ends the line.
Returns the key taken, downcased.
# File lib/bbs/petscii/screen/prompts.rb, line 46 def edit(text = '', title:, single_line: false, max: nil) Editor.new(@session, text: text, title: title, single_line: single_line, max: max, cols: @cols, rows: @rows).run end
text edited in the full-screen BBS::Editor at this screenโs size, titled title; single_line makes it one paragraph that RETURN saves, max limits its length. The screen is left as the editor leaves it.
Returns the text when saved, nil when the caller quit.
# File lib/bbs/petscii/screen/prompts.rb, line 54 def pause(text = 'return: back') write "\r\n #{DG}#{text}#{LG} " k = key puts k end
Writes text dim on a new line and waits for a key.
Returns the key.
# File lib/bbs/petscii/screen/prompts.rb, line 72 def pick(heading, items, empty: EMPTY, right: '', commands: {}, &label) label ||= :to_s.to_proc title(heading, right) if items.empty? say(empty, color: GR) pause return nil end hint = commands.empty? ? PICK_HINT : "#{commands.map { |k, v| "#{k}: #{v}" }.join(' ')} q: back" Selector.list(@session, items, width: @cols - 1, height: page_size, hint: hint, exits: commands.keys.to_h { |k| [k, k] }.merge('q' => nil)) do |item| plain(label.call(item)) end end
A numbered list of items, each labelled by the block (made #plain; default to_s), under the #title of heading and right: a BBS::Selector.list a #page_size high. CRSR and RETURN or the number pick, CRSR left and right turn the pages.
- empty
-
shown, with a
pause, whenitemsis empty - commands
-
single-key commands,
{ 's' => 'search' }: the hint row lists them, and pressing one returns its key
Returns the item picked, a commands key, or nil for q, โ or RUN/STOP (and for no items).