Class: Curses::Window

Inherits:
Object
  • Object
show all
Defined in:
lib/curses_extensions.rb,
lib/curses_color.rb

Overview

Curses::Window

Instance Method Summary collapse

Instance Method Details

#_orig_addstrObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/curses_extensions.rb', line 106

def addstr(str, color_name = nil, align = nil, ref = false)
  # color style on
  if color_name && Curses::Color.pair(color_name)
    attron(Curses::Color.pair(color_name))
  end

  # set alignment
  case(align)
  when :left
    setpos(cury, 0)
  when :right
    setpos(cury, width - str.size)
  when :center
    setpos(cury, (width - str.size) / 2)
  end

  # draw
  _orig_addstr(str)

  # color style off
  if color_name && Curses::Color.pair(color_name)
    attroff(Curses::Color.pair(color_name))
  end

  # refresh is required
  refresh if ref
end

#addstr(str, color_name = nil, align = nil, ref = false) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/curses_extensions.rb', line 107

def addstr(str, color_name = nil, align = nil, ref = false)
  # color style on
  if color_name && Curses::Color.pair(color_name)
    attron(Curses::Color.pair(color_name))
  end

  # set alignment
  case(align)
  when :left
    setpos(cury, 0)
  when :right
    setpos(cury, width - str.size)
  when :center
    setpos(cury, (width - str.size) / 2)
  end

  # draw
  _orig_addstr(str)

  # color style off
  if color_name && Curses::Color.pair(color_name)
    attroff(Curses::Color.pair(color_name))
  end

  # refresh is required
  refresh if ref
end

#next_lineObject



135
136
137
# File 'lib/curses_extensions.rb', line 135

def next_line
  setpos(cury + 1, 0)
end

#set_title(title, align = :center) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/curses_extensions.rb', line 139

def set_title(title, align = :center)
  return if width <= 6 # too small to show title

  orig_cur = {:x => curx, :y => cury}

  # shrink title
  title = title[0...(width-6)] if (title.size + 6) > width

  case(align)
  when :left
    setpos(0, 2)
  when :right
    setpos(0, width - title.size - 4)
  else # :center
    setpos(0, (width - title.size) / 2 - 1)
  end
  addstr(" #{title} ")

  setpos(orig_cur[:y], orig_cur[:x])
end