Module: RTask::UI::CursesInterface::Attribute
- Defined in:
- lib/rtask/ui/curses.rb
Overview
Attribute list window.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
-
#build_gem ⇒ Object
Build the gem.
- #change ⇒ Object
-
#down ⇒ Object
Move down.
- #draw ⇒ Object
- #quit ⇒ Object
- #save ⇒ Object
- #show_attribute(name, highlight) ⇒ Object
- #start ⇒ Object
-
#toogle_show_all ⇒ Object
Show all items.
-
#up ⇒ Object
Move up.
Class Method Details
.extended(obj) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/rtask/ui/curses.rb', line 124 def self.extended(obj) obj.instance_eval do # doesn't show all @show_all = false # gem spec @spec = parent.spec # displayed top item @top = 0 # selected position @position = 0 # width @key_width = @spec.attributes.inject(0) do |m, n| m > n.to_s.size ? m : n.to_s.size end # keypad is ok keypad(true) end end |
Instance Method Details
#attributes ⇒ Object
143 144 145 |
# File 'lib/rtask/ui/curses.rb', line 143 def attributes @show_all ? @spec.attributes : @spec.standard end |
#build_gem ⇒ Object
Build the gem.
201 202 203 204 205 206 207 208 |
# File 'lib/rtask/ui/curses.rb', line 201 def build_gem unless RTask::Gem.build(@spec) parent. "You need to fill out all the required fields" else gemname = "#{@spec.name}-#{@spec.version}.gem" parent.("Created " + gemname) end end |
#change ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/rtask/ui/curses.rb', line 237 def change name = attributes[@position] val = parent.spec.send(name) res = case @spec.type_of(name) when :array msg = "#{name.to_s.capitalize}(Split by ',')" (parent.input msg, val.join(",")).strip.split(",") when :bool !val when :string parent.input name.to_s.capitalize, val end if name == :dependencies parent.spec.dependencies.clear res.each {|dep| parent.spec.add_runtime_dependency dep} else parent.spec.send("#{name}=", res) end parent. "Updated '#{name}'" @changed = true end |
#down ⇒ Object
Move down.
187 188 189 190 191 192 |
# File 'lib/rtask/ui/curses.rb', line 187 def down if @position < attributes.size - 1 @position += 1 @top += 1 if @position == @top + maxy end end |
#draw ⇒ Object
147 148 149 150 151 152 153 154 155 |
# File 'lib/rtask/ui/curses.rb', line 147 def draw clear @top.upto(@top+maxy-1) do |idx| break unless attributes[idx] setpos(idx - @top, 0) show_attribute(attributes[idx], @position == idx) end refresh end |
#quit ⇒ Object
227 228 229 230 231 232 233 234 235 |
# File 'lib/rtask/ui/curses.rb', line 227 def quit if @changed res = ::Curses.keyname(parent.input_char(<<-__Q__.chomp)) Changes are not saved. Quit? (y or n) __Q__ return unless res.upcase == "Y" end exit end |
#save ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/rtask/ui/curses.rb', line 210 def save specname = "#{@spec.name}.gemspec" # check required attrs if Gem::Specification.required_attributes.any? do |sym| @spec.send(sym).nil? end parent. "You need to fill out all the required fields" else File.open(specname, "w") do |file| file.write @spec.to_ruby end parent. "Saved #{specname}" @changed = false end end |
#show_attribute(name, highlight) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/rtask/ui/curses.rb', line 259 def show_attribute(name, highlight) val = @spec.send(name) # star attron(highlight ? ::Curses::A_UNDERLINE : 0) addstr " * " addstr name.to_s key_width = name.to_s.size # required if Gem::Specification.required_attribute?(name) and val.nil? attron(color(:required)){ addstr " (required)" } key_width += 11 end # padding + separator addstr " ".rjust(@key_width - key_width + 1) # value case val when Array addstr val.join(", ") else addstr val.to_s end unless val.nil? attroff(highlight ? ::Curses::A_UNDERLINE : 0) end |
#start ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/rtask/ui/curses.rb', line 157 def start loop do # handles input case c = getch when ?a; toogle_show_all when ?u, ::Curses::KEY_UP ; up when ?d, ::Curses::KEY_DOWN ; down when ?c, ::Curses::KEY_CTRL_J ; change when ?b; build_gem when ?s; save when ?i; IncludedFiles.new(parent.files) when ?q; quit else parent. "[" + ::Curses.keyname(c).to_s + "]" if $DEBUG end # redraw draw end end |
#toogle_show_all ⇒ Object
Show all items.
195 196 197 198 |
# File 'lib/rtask/ui/curses.rb', line 195 def toogle_show_all @show_all = !@show_all @top, @position = 0, 0 end |
#up ⇒ Object
Move up.
179 180 181 182 183 184 |
# File 'lib/rtask/ui/curses.rb', line 179 def up if @position != 0 @position -= 1 @top -= 1 if @top == @position + 1 end end |