Class: Ncurses::WINDOW

Inherits:
Object show all
Defined in:
lib/tagen/ncurses.rb

Constant Summary collapse

KEYS =
keys

Instance Method Summary collapse

Constructor Details

#initializeWINDOW

Returns a new instance of WINDOW.



123
124
125
126
# File 'lib/tagen/ncurses.rb', line 123

def initialize
  @stdscr = Ncurses.stdscr
  @curscr = Ncurses.curscr
end

Instance Method Details

#beginxObject



170
# File 'lib/tagen/ncurses.rb', line 170

def beginx; beginxy[0] end

#beginxyObject



165
166
167
168
169
# File 'lib/tagen/ncurses.rb', line 165

def beginxy
  y,x=[],[]
  Ncurses.getbegyx(self,y,x)
  [x,y]
end

#beginyObject



171
# File 'lib/tagen/ncurses.rb', line 171

def beginy; beginxy[1] end

#convert_xy(x = nil, y = nil) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/tagen/ncurses.rb', line 173

def convert_xy x=nil,y=nil
  x = self.x+x.to_i if x and String===x
  y = self.y+y.to_i if y and String===y

  if x and y
    [x,y]
  elsif x
    x
  elsif y
    y
  end
end

#echo(*args) ⇒ Object



243
# File 'lib/tagen/ncurses.rb', line 243

def echo *args; necho *args, "\n" end

#getcObject



229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/tagen/ncurses.rb', line 229

def getc
  key = getch
  if key==27
  c = getch
  (value=KEYS[[27, c]]) ?  value : "\e"+c.chr
  elsif value=KEYS[key]
  value
  else
  # a "\C-a"
  key.chr
  end
end

#hObject



163
# File 'lib/tagen/ncurses.rb', line 163

def h; wh[1] end

#mvx(x, &blk) ⇒ Object



150
# File 'lib/tagen/ncurses.rb', line 150

def mvx x, &blk; mvxy(x, self.y) end

#mvxy(x, y, &blk) ⇒ Object



140
141
142
143
144
145
146
147
148
# File 'lib/tagen/ncurses.rb', line 140

def mvxy x,y, &blk
  x,y = convert_xy(x,y)
  x_, y_ = self.xy
  Ncurses.move(y,x) 
  if blk
  blk.call
  Ncurses.move(y_, x_)
  end
end

#mvy(y, &blk) ⇒ Object



151
# File 'lib/tagen/ncurses.rb', line 151

def mvy y, &blk; mvxy(self.x, y) end

#necho(*args) ⇒ Object



242
# File 'lib/tagen/ncurses.rb', line 242

def necho(*args); Ncurses.addstr(args.gach{|v|v.to_s}.join(" ")) end

#restoreObject



138
# File 'lib/tagen/ncurses.rb', line 138

def restore; xy *@save_xy end

#rmvx(x, &blk) ⇒ Object



154
# File 'lib/tagen/ncurses.rb', line 154

def rmvx x, &blk; mvx(x.to_s, &blk) end

#rmvxy(x, y, &blk) ⇒ Object



153
# File 'lib/tagen/ncurses.rb', line 153

def rmvxy x,y, &blk; mvxy(x.to_s, y.to_s, &blk) end

#rmvy(y, &blk) ⇒ Object



155
# File 'lib/tagen/ncurses.rb', line 155

def rmvy y, &blk; mvy(y.to_s, &blk) end

#saveObject



137
# File 'lib/tagen/ncurses.rb', line 137

def save; @save_xy = xy end

#wObject



162
# File 'lib/tagen/ncurses.rb', line 162

def w; wh[0] end

#whObject



157
158
159
160
161
# File 'lib/tagen/ncurses.rb', line 157

def wh
  y,x=[],[]
  Ncurses.getmaxyx(self,y,x)
  [x, y]
end

#xObject



134
# File 'lib/tagen/ncurses.rb', line 134

def x; xy[0] end

#xyObject

xy mvxy wh ..



129
130
131
132
133
# File 'lib/tagen/ncurses.rb', line 129

def xy
  y,x=[],[]
  Ncurses.getyx(self,y,x)
  [x[0], y[0]]
end

#yObject



135
# File 'lib/tagen/ncurses.rb', line 135

def y; xy[1] end