Class: Settings
- Inherits:
-
Object
- Object
- Settings
- Defined in:
- lib/bsod/settings.rb
Overview
Global configurations of the program, along with a commandline argument parser.
Contains the program’s specific configuration rules.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Returns a specific setting previously set.
-
#initialize ⇒ Settings
constructor
Creates a configuration, with default values.
-
#parse(args) ⇒ Object
Sets options based on commandline arguments ‘args`.
- #show_list ⇒ Object
- #show_version ⇒ Object
Constructor Details
#initialize ⇒ Settings
Creates a configuration, with default values.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bsod/settings.rb', line 12 def initialize @settings = {} # Makes possible to sleep for a while before BSODing @settings[:sleep_time] = nil # Default BSOD @settings[:bsod_type] = BSOD::ALL.first # This doesn't matter because it will go fullscreen anyways. # Just change it if looks ugly @settings[:width] = 800 @settings[:height] = 600 @settings[:fullscreen] = true # SDL-specific key to exit BSOD @settings[:exit_key] = SDL::Key::F8 # This is the default font, distributed with the gem. # It's `../../fonts/droidsansmono.ttf` based on `settings.rb` path. fontname = File.("../../", __FILE__) fontname = File.dirname fontname fontname += "/fonts/droidsansmono.ttf" @settings[:font_filename] = fontname @settings[:font_size] = 14 @settings[:font_bold] = false # Curses mode for consoles! # Most of the settings above won't make any sense if this # is true @settings[:curses] = false end |
Instance Method Details
#[](name) ⇒ Object
Returns a specific setting previously set.
101 102 103 |
# File 'lib/bsod/settings.rb', line 101 def [] name return @settings[name] end |
#parse(args) ⇒ Object
Sets options based on commandline arguments ‘args`. It should be `ARGV`.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/bsod/settings.rb', line 47 def parse args opts = OptionParser.new do |parser| parser. = "Usage: bsod [options]" # Make output beautiful parser.separator "" parser.separator "Note: Default key to exit BSOD is `F8`" parser.separator "" parser.separator "Options:" parser.on("-w", "--wait N", "Waits N (float) seconds before BSODing") do |n| @settings[:sleep_time] = n.to_f end parser.on("-s", "--style STYLE", "Select the BSOD style to show. To see all options use `--list`. ") do |type| @settings[:bsod_type] = type.to_s end parser.on("--[no-]fullscreen", "Runs on fullscreen mode (default on)") do |f| @settings[:fullscreen] = f end parser.on("-c", "--[no-]curses", "Runs on the terminal, without a graphical window") do |f| @settings[:curses] = f end # parser.on("-r", "--random", "Select a random BSOD") do # DO SOMETHING ABOUT IT # end parser.on("-l", "--list", "Show all possible BSODs") do self.show_list exit end # These options appear if no other is given. parser.on("-h", "--help", "Show this message") do puts parser exit end parser.on("--version", "Show version and license info") do self.show_version exit end end opts.parse! args return @settings end |
#show_list ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/bsod/settings.rb', line 130 def show_list puts "Usage: bsod -t [type]" puts " where [type] can be:" puts # Kinda ugly, right? BSOD::ALL.each_with_index do |type, i| if i == 0 puts "#{type} [default]" next end puts "#{type}" end end |
#show_version ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/bsod/settings.rb', line 105 def show_version puts <<END_OF_VERSION _ __ _ _ |_) (_ / \\ | \\ |_) __) \\_/ |_/ #{BSOD::VERSION} (http://alexdantas.net/projects/bsod) Copyright (C) 2011-2012 Alexandre Dantas <[email protected]> bsod is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. The Droid Sans font family is licensed under the Apache license. END_OF_VERSION end |