Class: Nutils

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

Class Method Summary collapse

Class Method Details



210
211
212
213
214
215
216
217
# File 'lib/ncurses_ui.rb', line 210

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.map(color)) if color
  scr.setpos row, col
  scr.addstr t
  scr.attroff(Colors.map(color)) if color
end

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



219
220
221
222
223
224
225
226
227
# File 'lib/ncurses_ui.rb', line 219

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



229
230
231
232
# File 'lib/ncurses_ui.rb', line 229

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