Class: Tiqbi::View::MainView

Inherits:
Base
  • Object
show all
Defined in:
lib/tiqbi/view/main_view.rb

Constant Summary

Constants included from Utils

Utils::ENTITY_MAP

Instance Attribute Summary

Attributes inherited from Base

#c_window, #collection, #cursor, #top_statement

Instance Method Summary collapse

Methods inherited from Base

#box!, #br, #change_focus_line, #clear_collection, #cursor_down, #cursor_on_end_of_collection?, #cursor_up, #enhansive_line, #hr, #in_color, #in_pos, #normalize_line, #print, #resize!, #restore_initial_size!, #scroll_down, #scroll_up, #virtual_close

Methods included from Utils

#format_str, #split_str_with_width, #unescape_entity

Constructor Details

#initialize(*args) ⇒ MainView

Returns a new instance of MainView.



8
9
10
11
12
13
# File 'lib/tiqbi/view/main_view.rb', line 8

def initialize(*args)
  # create subwindow
  super(*args)
  # scroll on
  @c_window.scrollok(true)
end

Instance Method Details

#draw_at(virtual_index, color = true) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/tiqbi/view/main_view.rb', line 15

def draw_at(virtual_index, color = true)
  line = collection.at(virtual_index) do |item|
    comment_count = "c: #{item.comment_count || 0} "
    score         = "s: #{item.stock_count || 0} "
    title_w       = maxx - "#{comment_count}#{score.size}".size - 10
    title         = format_str(item.title || '', title_w)
    [
      { color: Tiqbi::F_YELLOW_B_BLACK, value: comment_count },
      { color: Tiqbi::F_RED_B_BLACK, value: score },
      { color: 0, value: title }
    ]
  end
  x = 0
  clrtoeol
  line.each do |e|
    setpos(cursor.y, x)
    if color
      in_color(e[:color] || 0) { addstr(e[:value]) }
    else
      addstr(e[:value])
    end
    x += e[:value].size
  end
end