Class: Tiqbi::View::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Utils
Defined in:
lib/tiqbi/view/base.rb

Direct Known Subclasses

CommandView, DetailView, MainView

Constant Summary

Constants included from Utils

Utils::ENTITY_MAP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#format_str, #split_str_with_width, #unescape_entity

Constructor Details

#initialize(curses_parent, h, w, y, x) ⇒ Base

Returns a new instance of Base.



15
16
17
18
19
20
21
22
# File 'lib/tiqbi/view/base.rb', line 15

def initialize(curses_parent, h, w, y, x)
  @c_window = curses_parent.subwin(h, w, y, x)
  @cursor = Cursor.new
  @collection = Collection.new
  @top_statement = 0
  @initial_h = h
  @initial_w = w
end

Instance Attribute Details

#c_windowObject

Returns the value of attribute c_window.



10
11
12
# File 'lib/tiqbi/view/base.rb', line 10

def c_window
  @c_window
end

#collectionObject

Returns the value of attribute collection.



11
12
13
# File 'lib/tiqbi/view/base.rb', line 11

def collection
  @collection
end

#cursorObject

Returns the value of attribute cursor.



10
11
12
# File 'lib/tiqbi/view/base.rb', line 10

def cursor
  @cursor
end

#top_statementObject

Returns the value of attribute top_statement.



10
11
12
# File 'lib/tiqbi/view/base.rb', line 10

def top_statement
  @top_statement
end

Instance Method Details

#box!(*args) ⇒ Object



66
67
68
69
# File 'lib/tiqbi/view/base.rb', line 66

def box!(*args)
  box(*args)
  refresh
end

#brObject



155
156
157
# File 'lib/tiqbi/view/base.rb', line 155

def br
  ''
end

#change_focus_line(&block) ⇒ Object



95
96
97
98
99
# File 'lib/tiqbi/view/base.rb', line 95

def change_focus_line(&block)
  normalize_line
  yield
  enhansive_line
end

#clear_collectionObject



50
51
52
53
54
# File 'lib/tiqbi/view/base.rb', line 50

def clear_collection
  self.collection.clear if collection
  self.cursor.clear
  self.top_statement = 0
end

#cursor_downObject



111
112
113
114
115
116
117
118
119
120
# File 'lib/tiqbi/view/base.rb', line 111

def cursor_down
  return if cursor_on_end_of_collection?
  if cursor.y >= (maxy - 1)
    scroll_down
  else
    change_focus_line {
      cursor.down
    }
  end
end

#cursor_on_end_of_collection?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/tiqbi/view/base.rb', line 122

def cursor_on_end_of_collection?
  cursor.y >= (collection.size - 1)
end

#cursor_upObject



101
102
103
104
105
106
107
108
109
# File 'lib/tiqbi/view/base.rb', line 101

def cursor_up
  if cursor.y <= 0
    scroll_up
  else
    change_focus_line {
      cursor.up
    }
  end
end

#draw_at(virtual_index, color = true) ⇒ Object



77
78
79
80
81
# File 'lib/tiqbi/view/base.rb', line 77

def draw_at(virtual_index, color = true)
  setpos(cursor.y, 0)
  clrtoeol
  addstr(collection.at(virtual_index))
end

#enhansive_lineObject



88
89
90
91
92
93
# File 'lib/tiqbi/view/base.rb', line 88

def enhansive_line
  in_color(Tiqbi::F_YELLOW_B_BLACK) {
    in_pos(cursor.y, cursor.x) { draw_at(cursor.y + top_statement, false) }
    refresh
  }
end

#hrObject



159
160
161
# File 'lib/tiqbi/view/base.rb', line 159

def hr
  '-' * (maxx - 1)
end

#in_color(color) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



33
34
35
36
37
# File 'lib/tiqbi/view/base.rb', line 33

def in_color(color, &block)
  c_window.attron(Curses.color_pair(color))
  yield self
  c_window.attroff(Curses::A_COLOR)
end

#in_pos(y, x) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



71
72
73
74
75
# File 'lib/tiqbi/view/base.rb', line 71

def in_pos(y, x, &block)
  setpos(y, x)
  yield self
  setpos(y, x)
end

#normalize_lineObject



83
84
85
86
# File 'lib/tiqbi/view/base.rb', line 83

def normalize_line
  in_pos(cursor.y, cursor.x) { draw_at(cursor.y + top_statement) }
  refresh
end


39
40
41
42
43
44
45
46
47
48
# File 'lib/tiqbi/view/base.rb', line 39

def print
  in_pos(0, 0) {
    collection.all[0..(c_window.maxy - 1)].each_with_index { |e, virtual_index|
      draw_at(virtual_index)
      cursor.down
    }
    cursor.clear
  }
  refresh
end

#resize!(h, w) ⇒ Object



60
61
62
63
64
# File 'lib/tiqbi/view/base.rb', line 60

def resize!(h, w)
  resize(h, w)
  clear
  print
end

#restore_initial_size!Object



56
57
58
# File 'lib/tiqbi/view/base.rb', line 56

def restore_initial_size!
  resize!(@initial_h, @initial_w)
end

#scroll_downObject



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/tiqbi/view/base.rb', line 138

def scroll_down
  if top_statement + maxy < collection.size
    change_focus_line {
      in_pos(cursor.y, 0) {
        scrl(1)
        self.top_statement += 1
      }
      refresh
    }
  end
end

#scroll_upObject



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/tiqbi/view/base.rb', line 126

def scroll_up
  if top_statement > 0
    change_focus_line {
      scrl(-1)
      in_pos(cursor.y, 0) {
        self.top_statement -= 1
      }
      refresh
    }
  end
end

#virtual_closeObject



150
151
152
153
# File 'lib/tiqbi/view/base.rb', line 150

def virtual_close
  clear_collection
  resize!(0, 0)
end