Class: Nutils

Inherits:
Object
  • Object
show all
Defined in:
lib/ncurses_ui.rb

Class Method Summary collapse

Class Method Details



223
224
225
226
227
228
229
230
# File 'lib/ncurses_ui.rb', line 223

def self.print(scr, row, col, text, color, width = (Curses.cols))
  width = [Curses.cols, col+width].min - col
  t = "%-#{width}s" % [scroll(text, width)]
  scr.attron(Colors.pairMap(color)) if color
  scr.setpos row, col
  scr.addstr t
  scr.attroff(Colors.pairMap(color)) if color
end

.scroll(text, width, offset = 0) ⇒ Object



232
233
234
235
236
237
238
239
240
# File 'lib/ncurses_ui.rb', line 232

def self.scroll(text, width, offset=0)
  return unless text
  ellipsis = "*"
  t = text
  if t.size+offset > width
    t = t[offset..(width-ellipsis.size-1)] << ellipsis
  end
  t
end

.timestr(sec) ⇒ Object



242
243
244
245
# File 'lib/ncurses_ui.rb', line 242

def self.timestr(sec)
  sec = sec.to_i
  "%02d:%02d" % [sec/60, sec%60]
end