Class: AsciiParadise::Base
- Inherits:
-
Object
- Object
- AsciiParadise::Base
- Defined in:
- lib/ascii_paradise/base/base.rb,
lib/ascii_paradise/base/menu.rb,
lib/ascii_paradise/base/debug.rb,
lib/ascii_paradise/base/reset.rb,
lib/ascii_paradise/base/colours.rb,
lib/ascii_paradise/base/initialize.rb
Overview
AsciiParadise::Base
Direct Known Subclasses
Animation, AttractiveLady, Box, CatFace, ColourfulFlowers, Flexbox, GUI::UniversalWidgets::AnimatedFrame, GUI::UniversalWidgets::Widget, Lobster, MonaLisa, PinkPanther, Ponies, SeductiveLady, SierpinksiTriangle
Class Method Summary collapse
-
.animation_dir? ⇒ Boolean
# === AsciiParadise::Base.animation_dir? ========================================================================= #.
-
.e(i = '') ⇒ Object
# === Base.e ========================================================================= #.
-
.run ⇒ Object
# === AsciiParadise::Base.run ========================================================================= #.
Instance Method Summary collapse
-
#animation_directory? ⇒ Boolean
(also: #animation_dir?, #which_dir?, #main_dir?)
# === animation_directory? ========================================================================= #.
-
#clear_screen ⇒ Object
# === clear_screen ========================================================================= #.
-
#colour_parse_this_string(i) ⇒ Object
# === colour_parse_this_string ========================================================================= #.
-
#debug? ⇒ Boolean
# === debug? ========================================================================= #.
-
#do_not_run_already ⇒ Object
(also: #do_not_run_yet)
# === do_not_run_already ========================================================================= #.
-
#do_not_use_clear ⇒ Object
# === do_not_use_clear ========================================================================= #.
-
#do_use_random_colour ⇒ Object
(also: #use_a_random_colour)
# === do_use_random_colour ========================================================================= #.
-
#do_wait_for_keypress_event(i = true) ⇒ Object
# === do_wait_for_keypress_event.
-
#e(i = '') ⇒ Object
# === e ========================================================================= #.
-
#enable_debug ⇒ Object
# === enable_debug.
-
#initialize(optional_arguments = ARGV) ⇒ Base
constructor
# === initialize ========================================================================= #.
-
#is_animated? ⇒ Boolean
# === is_animated?.
-
#menu(i) ⇒ Object
# === menu (menu tag) ========================================================================= #.
-
#project_base_dir? ⇒ Boolean
# === project_base_dir? ========================================================================= #.
-
#register_sigint ⇒ Object
# === register_sigint ========================================================================= #.
-
#remove_trailing_ansci_escape_code(i) ⇒ Object
# === remove_trailing_ansci_escape_code ========================================================================= #.
-
#report_how_many_animated_components_exist ⇒ Object
# === report_how_many_animated_components_exist ========================================================================= #.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#return_basename_of_this_file_without_the_extension(i) ⇒ Object
# === return_basename_of_this_file_without_the_extension ========================================================================= #.
-
#return_random_colour ⇒ Object
# === return_random_colour.
-
#rev(use_colours = use_colours? ) ⇒ Object
# === rev (rev tag) ========================================================================= #.
-
#royalblue(i = '', use_colours = use_colours? ) ⇒ Object
# === royalblue ========================================================================= #.
-
#set_use_this_colour(i = ::AsciiParadise.colour?) ⇒ Object
(also: #set_colour, #use_this_colour)
# === set_use_this_colour.
-
#sfancy(i) ⇒ Object
# === sfancy ========================================================================= #.
-
#sfile(i) ⇒ Object
# === sfile ========================================================================= #.
-
#show_available_components ⇒ Object
# === show_available_components ========================================================================= #.
-
#show_help ⇒ Object
(also: #help)
# === show_help (help tag).
-
#simp(i) ⇒ Object
# === simp ========================================================================= #.
-
#slategrey(i = '') ⇒ Object
# === slategrey ========================================================================= #.
-
#sort_files(i) ⇒ Object
# === sort_files ========================================================================= #.
-
#static_dir? ⇒ Boolean
# === static_dir? ========================================================================= #.
-
#steelblue(i = '') ⇒ Object
(also: #tomato)
# === steelblue ========================================================================= #.
-
#swarn(i) ⇒ Object
# === swarn ========================================================================= #.
-
#use_colours? ⇒ Boolean
# === use_colours? ========================================================================= #.
Constructor Details
#initialize(optional_arguments = ARGV) ⇒ Base
#
initialize
#
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ascii_paradise/base/initialize.rb', line 14 def initialize( optional_arguments = ARGV ) register_sigint reset # ======================================================================= # # === Handle blocks given to us next # ======================================================================= # if block_given? yielded = yield if yielded.is_a? Hash # =================================================================== # # === :run_n_times # =================================================================== # if yielded.has_key? :run_n_times set_run_n_times(yielded.delete(:run_n_times)) end # =================================================================== # # === main_dir # =================================================================== # if yielded.has_key? :main_dir set_main_dir(yielded.delete(:main_dir)) # =================================================================== # # === :animation_dir # =================================================================== # elsif yielded.has_key? :animation_dir set_main_dir(yielded.delete(:animation_dir)) end # =================================================================== # # === :sleep_for_n_seconds # =================================================================== # if yielded.has_key? :sleep_for_n_seconds set_sleep_for_n_seconds(yielded.delete(:sleep_for_n_seconds)) end else # Else assume a Symbol. case yielded # =================================================================== # # Prevent instant running. # =================================================================== # when :do_not_run_already, :do_not_run_yet do_not_run_already end end end end |
Class Method Details
.animation_dir? ⇒ Boolean
#
AsciiParadise::Base.animation_dir?
#
129 130 131 |
# File 'lib/ascii_paradise/base/base.rb', line 129 def self.animation_dir? ::AsciiParadise.animations_dir? end |
.e(i = '') ⇒ Object
#
Base.e
#
111 112 113 |
# File 'lib/ascii_paradise/base/colours.rb', line 111 def self.e(i = '') ::AsciiParadise.e(i) end |
.run ⇒ Object
#
AsciiParadise::Base.run
#
152 153 154 |
# File 'lib/ascii_paradise/base/base.rb', line 152 def self.run new end |
Instance Method Details
#animation_directory? ⇒ Boolean Also known as: animation_dir?, which_dir?, main_dir?
#
animation_directory?
#
136 137 138 |
# File 'lib/ascii_paradise/base/base.rb', line 136 def animation_directory? Base.animation_dir? end |
#clear_screen ⇒ Object
#
clear_screen
#
53 54 55 |
# File 'lib/ascii_paradise/base/base.rb', line 53 def clear_screen ::AsciiParadise.clear_screen end |
#colour_parse_this_string(i) ⇒ Object
#
colour_parse_this_string
#
132 133 134 |
# File 'lib/ascii_paradise/base/colours.rb', line 132 def colour_parse_this_string(i) ::AsciiParadise.colour_parse_this_string(i) end |
#debug? ⇒ Boolean
#
debug?
#
25 26 27 |
# File 'lib/ascii_paradise/base/debug.rb', line 25 def debug? ::AsciiParadise.debug? end |
#do_not_run_already ⇒ Object Also known as: do_not_run_yet
#
do_not_run_already
#
70 71 72 |
# File 'lib/ascii_paradise/base/base.rb', line 70 def do_not_run_already @run_already = false end |
#do_not_use_clear ⇒ Object
#
do_not_use_clear
#
46 47 48 |
# File 'lib/ascii_paradise/base/base.rb', line 46 def do_not_use_clear @do_clear = false end |
#do_use_random_colour ⇒ Object Also known as: use_a_random_colour
#
do_use_random_colour
#
50 51 52 |
# File 'lib/ascii_paradise/base/colours.rb', line 50 def do_use_random_colour set_colour(:random_colour) end |
#do_wait_for_keypress_event(i = true) ⇒ Object
#
do_wait_for_keypress_event
The argument can be true, by default, or also another argument. Some symbols may have a special instruction.
#
63 64 65 |
# File 'lib/ascii_paradise/base/base.rb', line 63 def do_wait_for_keypress_event(i = true) @wait_for_keypress_on_each_frame = i end |
#e(i = '') ⇒ Object
#
e
#
118 119 120 |
# File 'lib/ascii_paradise/base/colours.rb', line 118 def e(i = '') Base.e(i) end |
#enable_debug ⇒ Object
#
enable_debug
Delegate to the toplevel-method next.
#
18 19 20 |
# File 'lib/ascii_paradise/base/debug.rb', line 18 def enable_debug ::AsciiParadise.enable_debug end |
#is_animated? ⇒ Boolean
#
is_animated?
By default, sublcasses of this class are not animated. This is different for those ruby files that subclass from AsciiParadise::Animation.
#
110 111 112 |
# File 'lib/ascii_paradise/base/base.rb', line 110 def is_animated? false end |
#menu(i) ⇒ Object
#
menu (menu tag)
#
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 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 99 100 101 102 103 104 105 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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/ascii_paradise/base/menu.rb', line 20 def (i) if i.is_a? Array i.each {|entry| (entry) } else case i.to_s # case tag # ===================================================================== # # === volcano --full-debug # # This entry-point is called "full-debug", which means that we will # try to heavily "debug" the ascii-animation at hand, e. g. correct # faulty entries and such. # ===================================================================== # when /^-?-?everything$/i, /^-?-?full(-|_)?debug$/i, /^-?-?query$/i, /^-?-?frame(-|_)?wait$/i, /^-?-?all$/i, /^-?-?debugeverything$/i, /^-?-?debug(-|_)?per(-|_)?frame$/i, '-all', '-query' enable_debug do_wait_for_keypress_event # ===================================================================== # # === turtles --random # ===================================================================== # when /^-?-?random$/i sample = AsciiParadise.available_ascii_components?.sample AsciiParadise.run(sample) exit # ===================================================================== # # === turtles --overview # ===================================================================== # when *AsciiParadise. show_available_components exit # ===================================================================== # # === turtles --colourspray # ===================================================================== # when /^-?-?colour(-|_| )?spray$/i, /^-?-?use(-|_| )?colour(-|_| )?spray$/i # =================================================================== # # Must invoke use_a_random_colour here so that we start by # using a random colour already. # =================================================================== # use_a_random_colour do_use_colour_spray # ===================================================================== # # === ademo --frame # ===================================================================== # when /^-?-?debug$/, /^-?-?frames?$/, /^-?-?enable(-|_)?frames$/ enable_debug # ===================================================================== # # === volcano --numbers # ===================================================================== # when /^-?-?numbers\??$/i, /^-?-?super(-|_)?debug$/, /^-?-?individual(_|-)?frames$/i, # === swimming_lanes --individual-frames /^-?-?slow$/i enable_debug do_wait_for_keypress_event(:also_show_red_numbers) # jumpingpig --numbers # ===================================================================== # # === turtle --framerate # === whip --framerate # ===================================================================== # when /-?-?framerate\??$/i, /-?-?delay\??$/i _ = self _.do_not_run_yet e 'The delay for '+simp(self.class.to_s)+ ' is '+sfancy(_.delay?.to_s+' seconds')+' per frame.' exit # ===================================================================== # # === volcano --wait-for-keypress # ===================================================================== # when /^-?-?keypress$/i, /^-?-?wait$/i, # diver --wait /^-?-?wait(_|-)?for(_|-)?keypress$/i, /^-?-?steps?$/i do_wait_for_keypress_event # ===================================================================== # # === volcano --help # ===================================================================== # when /^-?-?help$/i # help tag show_help exit # ===================================================================== # # === volcano --n_animated_components? # ===================================================================== # when /^-?-?n(_|-)?animated(_|-)?components\??$/i, /^-?-?n(_|-)?components\??$/i # === volcano --n_components? report_how_many_animated_components_exist exit # ===================================================================== # # === volcano --rainbow-colours # === volcano --rainbows # ===================================================================== # when /^-?-?rainbow(-|_| )?colou?rs$/i, /^-?-?rainbow(_|-| )?line$/i, /^-?-?rainbows?$/i do_use_rainbow_colours # ===================================================================== # # === volcano --show-frame=25 # === volcano --frame15 # ===================================================================== # when /^-?-?show(-|_)?frames?=(.+)$/i, # === $2 /^-?-?frame(\d+)$/i # === $2 _ = $1.to_s.dup _ = $2.to_s.dup if $2 show_frame_at_this_position(_) exit # ===================================================================== # # === ademon :default # ===================================================================== # when :default, 'default' set_run_n_times :default # ===================================================================== # # === turtles --run-n-times=2 # ===================================================================== # when /^-?-?run(-|_)?n(-|_)?times=(\d+)$/i # $3 set_run_n_times($3.to_s.dup) # ===================================================================== # # === turtles --half-colour # ===================================================================== # when /^-?-?half(-|_)?colou?r$/ do_use_half_colours # ===================================================================== # # === turtles --disco-inferno # # URL is at: # # http://rubular.com/r/eEYhiWpEpx # # Additional invocation examples: # # trampoline --disco-inferno # volcano --disco-inferno # # ===================================================================== # when /^-?-?disco(-|_)?inferno$/i, /colour-?animation/, /disco/, /inferno/, /random-?colours/, # earth --random-colours '--random-colours' do_use_disco_inferno # ===================================================================== # # === turtles --is_animated? # ===================================================================== # when /^-?-?is(-|_)?animated\??$/i, /^-?-?animated\??$/i e is_animated? exit # ===================================================================== # # === turtles 1 # ===================================================================== # when /^\d+$/ # If only numbers. set_run_n_times(i) # ===================================================================== # # === turtles --random-colour # ===================================================================== # when /^-?-?random(-|_)?colou?r$/i, /rcolour$/i, 'RCOL' do_use_random_colour # ===================================================================== # # === turtle --colour=slateblue # ===================================================================== # when /^-?-?colou?r=(.+)/, /^-?-?use(-|_)?this(-|_)?colour=(.+)/ # See: http://rubular.com/r/kH829if9FU _ = $1.to_s.dup _ = $3.to_s.dup if $3 set_use_this_colour(_) # ===================================================================== # # === whip --noclear # ===================================================================== # when 'dont_clear','dontclear','do_not_use_clear', /^-?-?no(-|_)?clear$/i, 'noc' do_not_use_clear # ===================================================================== # # === exploding_bubbles --delay=5 # === turtles --delay=12 # ===================================================================== # when /-?-?delay=(\d{1,2})/ set_delay($1) else # else it was not found, so we decide what to do. # =================================================================== # # Handle Konsole-colours next: # =================================================================== # if ::Colours.is_this_input_a_html_colour?(i.delete('-')) set_use_this_colour( i.delete('-') ) end end end end |
#project_base_dir? ⇒ Boolean
#
project_base_dir?
#
84 85 86 |
# File 'lib/ascii_paradise/base/base.rb', line 84 def project_base_dir? ::AsciiParadise.project_base_dir? end |
#register_sigint ⇒ Object
#
register_sigint
#
32 33 34 |
# File 'lib/ascii_paradise/base/base.rb', line 32 def register_sigint ::AsciiParadise.register_sigint end |
#remove_trailing_ansci_escape_code(i) ⇒ Object
#
remove_trailing_ansci_escape_code
#
125 126 127 |
# File 'lib/ascii_paradise/base/colours.rb', line 125 def remove_trailing_ansci_escape_code(i) ::Colours.remove_trailing_end_from(i) end |
#report_how_many_animated_components_exist ⇒ Object
#
report_how_many_animated_components_exist
#
98 99 100 101 102 |
# File 'lib/ascii_paradise/base/base.rb', line 98 def report_how_many_animated_components_exist e 'There are '+ sfancy(::AsciiParadise.n_animated_components?.to_s)+ ' animated entries available.' end |
#reset ⇒ Object
#
reset
#
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ascii_paradise/base/reset.rb', line 14 def reset # ======================================================================= # # By default we will use colours. # ======================================================================= # @use_colours = true # ======================================================================= # # === @wait_for_keypress_on_each_frame # # Whether to wait for a keypress event, on each frame, or whether # we will not. This is mostly only used for debugging purposes. # # Thus, by default this variable is set to false. # ======================================================================= # @wait_for_keypress_on_each_frame = false # ======================================================================= # # === @run_already # # If true then the animation will be run at once when called. # ======================================================================= # @run_already = true end |
#return_basename_of_this_file_without_the_extension(i) ⇒ Object
#
return_basename_of_this_file_without_the_extension
#
145 146 147 |
# File 'lib/ascii_paradise/base/base.rb', line 145 def return_basename_of_this_file_without_the_extension(i) File.basename(i).sub(/#{File.extname(i)}$/,'') end |
#return_random_colour ⇒ Object
#
return_random_colour
This method will return, as String, a random HTML colour, such as “steelblue”.
#
60 61 62 |
# File 'lib/ascii_paradise/base/colours.rb', line 60 def return_random_colour ::Colours.random_html_colour end |
#rev(use_colours = use_colours? ) ⇒ Object
#
rev (rev tag)
#
177 178 179 180 181 182 |
# File 'lib/ascii_paradise/base/colours.rb', line 177 def rev( use_colours = use_colours? ) return ::Colours.rev if use_colours return '' # else return an empty String. end |
#royalblue(i = '', use_colours = use_colours? ) ⇒ Object
#
royalblue
#
166 167 168 169 170 171 172 |
# File 'lib/ascii_paradise/base/colours.rb', line 166 def royalblue( i = '', use_colours = use_colours? ) i = i.dup i = ::Colours.send(__method__, i) if use_colours return i end |
#set_use_this_colour(i = ::AsciiParadise.colour?) ⇒ Object Also known as: set_colour, use_this_colour
#
set_use_this_colour
Set a specific colour through this method here.
Setting a random colour is also possible, e. g. by using as argument :random_colour.
#
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ascii_paradise/base/colours.rb', line 29 def set_use_this_colour( i = ::AsciiParadise.colour? ) case i when nil, :default i = DEFAULT_COLOUR_TO_USE # Hardcoded default in this case. end i = i.to_s.dup # Do not retain the String as frozen. i.delete!('-') if i.include? '--' case i # case tag when /^-?-?random(_|-)?colour$/i # handofgod --colour=random-colour i = return_random_colour end i = i.to_sym unless i.is_a? Symbol @use_this_colour = i end |
#sfancy(i) ⇒ Object
#
sfancy
#
78 79 80 81 82 83 84 |
# File 'lib/ascii_paradise/base/colours.rb', line 78 def sfancy(i) if @use_colours AsciiParadise.sfancy(i) else '' end end |
#sfile(i) ⇒ Object
#
sfile
#
89 90 91 92 93 94 95 |
# File 'lib/ascii_paradise/base/colours.rb', line 89 def sfile(i) if @use_colours AsciiParadise.sfile(i) else '' end end |
#show_available_components ⇒ Object
#
show_available_components
#
91 92 93 |
# File 'lib/ascii_paradise/base/base.rb', line 91 def show_available_components ::AsciiParadise.show_available_ascii_components end |
#show_help ⇒ Object Also known as: help
#
show_help (help tag)
To invoke this method, try:
fireworks --help
#
122 123 124 |
# File 'lib/ascii_paradise/base/base.rb', line 122 def show_help ::AsciiParadise.show_help end |
#simp(i) ⇒ Object
#
simp
#
67 68 69 70 71 72 73 |
# File 'lib/ascii_paradise/base/colours.rb', line 67 def simp(i) if @use_colours AsciiParadise.simp(i) else '' end end |
#slategrey(i = '') ⇒ Object
#
slategrey
#
157 158 159 160 161 |
# File 'lib/ascii_paradise/base/colours.rb', line 157 def slategrey(i = '') i = i.dup i = ::Colours.send(__method__, i) if @use_colours return i end |
#sort_files(i) ⇒ Object
#
sort_files
#
39 40 41 |
# File 'lib/ascii_paradise/base/base.rb', line 39 def sort_files(i) ::AsciiParadise.sort_files(i) end |
#static_dir? ⇒ Boolean
#
static_dir?
#
77 78 79 |
# File 'lib/ascii_paradise/base/base.rb', line 77 def static_dir? "#{project_base_dir?}static_ascii/" end |
#steelblue(i = '') ⇒ Object Also known as: tomato
#
steelblue
#
139 140 141 142 143 |
# File 'lib/ascii_paradise/base/colours.rb', line 139 def steelblue(i = '') i = i.dup i = ::Colours.send(__method__, i) if @use_colours return i end |
#swarn(i) ⇒ Object
#
swarn
#
100 101 102 103 104 105 106 |
# File 'lib/ascii_paradise/base/colours.rb', line 100 def swarn(i) if @use_colours AsciiParadise.swarn(i) else '' end end |
#use_colours? ⇒ Boolean
#
use_colours?
#
17 18 19 |
# File 'lib/ascii_paradise/base/colours.rb', line 17 def use_colours? @use_colours end |