Archived
1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
cli-old/lib/widgets/menu.rb

49 lines
1.1 KiB
Ruby
Raw Normal View History

2017-07-21 11:00:11 -04:00
# frozen_string_literal: true
module Widgets
2017-07-22 05:00:28 -04:00
class Menu < Base
2017-07-22 08:51:01 -04:00
LOGO = <<~END.lines.map { |s| s.gsub(/\n$/, '') }
____________ _____ _ _
|_ _/ _ \\ \\/ / _ \\| \\ | |
| || | | \\ / | | | \\ | |
| || |_| / \\ |_| | |\\ |
|_| \\___/_/\\_\\___/|_| \\_|
END
LOGO_WIDTH = LOGO.map(&:length).max
SIDE_PADDING = 1
2017-07-21 11:00:11 -04:00
ITEMS = [
'Foo menu item',
'Bar Car menu item',
'Hello, World!',
2017-07-21 11:07:17 -04:00
].freeze
2017-07-21 11:00:11 -04:00
2017-07-22 08:51:01 -04:00
def initialize(x, y, _width, height)
super x, y, LOGO_WIDTH + 2 * SIDE_PADDING, height
end
2017-07-21 11:00:11 -04:00
def render
2017-07-22 08:51:01 -04:00
LOGO.each_with_index do |s, index|
Curses.setpos y + index, SIDE_PADDING
Curses.addstr s
end
list_y = y + LOGO.count + 1
2017-07-21 11:00:11 -04:00
ITEMS.each_with_index do |item, index|
2017-07-22 05:46:15 -04:00
Style.default.menu_item do
2017-07-22 08:51:01 -04:00
Curses.setpos 0 + list_y + index * 4, 2
2017-07-22 05:46:15 -04:00
Curses.addstr ' ' * (width - 4)
2017-07-21 11:05:10 -04:00
2017-07-22 08:51:01 -04:00
Curses.setpos 1 + list_y + index * 4, 2
2017-07-22 05:46:15 -04:00
Curses.addstr " #{item}".ljust width - 4
2017-07-21 11:05:10 -04:00
2017-07-22 08:51:01 -04:00
Curses.setpos 2 + list_y + index * 4, 2
2017-07-22 05:46:15 -04:00
Curses.addstr ' ' * (width - 4)
end
2017-07-21 11:00:11 -04:00
end
end
end
end