Class: Cliptic::Interface::Menu

Inherits:
Menu_Box show all
Defined in:
lib/cliptic/interface.rb

Constant Summary

Constants included from Chars

Chars::Block, Chars::HL, Chars::LL, Chars::LS, Chars::LU, Chars::MS, Chars::Nums, Chars::RL, Chars::RS, Chars::RU, Chars::TD, Chars::TL, Chars::TR, Chars::TU, Chars::Tick, Chars::VL, Chars::XX

Instance Attribute Summary collapse

Attributes inherited from Menu_Box

#bot_b, #draw_bars, #logo, #title, #top_b

Attributes inherited from Windows::Window

#centered_x, #centered_y, #col, #line, #x, #y

Instance Method Summary collapse

Methods inherited from Menu_Box

#add_title, #draw, #line

Methods inherited from Windows::Window

#add_str, #bold, #clear, #color, #draw, #move, #refresh, #reset_attrs, #setpos, #standend, #standout, #time_str, #wrap_str

Methods included from Chars

small_num

Constructor Details

#initialize(height: opts.length+6, sel: Selector, sel_opts: opts.keys, tick: nil) ⇒ Menu

Returns a new instance of Menu.



169
170
171
172
173
174
175
# File 'lib/cliptic/interface.rb', line 169

def initialize(height:opts.length+6,
               sel:Selector, sel_opts:opts.keys,
               tick:nil, **)
  super(y:height, title:title)
  @height = height
  @selector = sel.new(opts:sel_opts, ctrls:ctrls, line:line+5, x:.x, tick:tick)
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



168
169
170
# File 'lib/cliptic/interface.rb', line 168

def height
  @height
end

#selectorObject (readonly)

Returns the value of attribute selector.



168
169
170
# File 'lib/cliptic/interface.rb', line 168

def selector
  @selector
end

Instance Method Details

#back(post_proc: ->{hide}) ⇒ Object



186
187
188
189
# File 'lib/cliptic/interface.rb', line 186

def back(post_proc:->{hide})
  selector.stop
  post_proc.call if post_proc
end

#choose_optObject



176
177
178
179
# File 'lib/cliptic/interface.rb', line 176

def choose_opt
  show
  selector.select
end

#ctrlsObject



196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/cliptic/interface.rb', line 196

def ctrls
  {
    ?j  => ->{selector.cursor += 1},
    ?k  => ->{selector.cursor -= 1},
    258 => ->{selector.cursor += 1},
    259 => ->{selector.cursor -= 1},
    10  => ->{enter},
    ?q  => ->{back},
    3   => ->{back},
    Curses::KEY_RESIZE => 
      ->{Screen.redraw(cb:->{redraw})}
  }
end

#enter(pre_proc: ->{hide}, post_proc: ->{show}) ⇒ Object



180
181
182
183
184
185
# File 'lib/cliptic/interface.rb', line 180

def enter(pre_proc:->{hide}, post_proc:->{show})
  pre_proc.call if pre_proc
  opts.values[selector.cursor]&.call
  reset_pos
  post_proc.call if post_proc
end

#hideObject



193
194
195
# File 'lib/cliptic/interface.rb', line 193

def hide
  clear
end

#redrawObject



213
214
215
216
# File 'lib/cliptic/interface.rb', line 213

def redraw
  reset_pos
  draw
end

#reset_posObject



209
210
211
212
# File 'lib/cliptic/interface.rb', line 209

def reset_pos
  super
  selector.move(line:line+5)
end

#showObject



190
191
192
# File 'lib/cliptic/interface.rb', line 190

def show
  draw
end