module AsciiParadise
#¶ ↑
require 'ascii_paradise/animation/reset.rb'
#¶ ↑
#¶ ↑
require 'ascii_paradise/ascii_say/say.rb'
#¶ ↑
#¶ ↑
AsciiParadise::AsciiTable::Cell
#¶ ↑
#¶ ↑
AsciiParadise::Table::Style¶ ↑
A Style object holds all the formatting information for a Table
object.
To create a table with a certain style, use either the constructor option :style, the Table#style
object or the Table#style=
method.
All these examples have the same effect:
# by constructor @table = Table.new(:style => {:padding_left => 2, :width => 40}) # by object @table.style.padding_left = 2 @table.style.width = 40 # by method @table.style = {:padding_left => 2, :width => 40}
To set a default style for all tables created afterwards, use Style.defaults=
AsciiParadise::AsciiTable::Style.defaults = {:width => 80}
#¶ ↑
#¶ ↑
#¶ ↑
AsciiParadise::AsciiTable::TableHelper
¶ ↑
#¶ ↑
#¶ ↑
AsciiParadise::AsciiTable
¶ ↑
#¶ ↑
require 'asciitable/toplevel_methods.rb'
#¶ ↑
#¶ ↑
require 'ascii_paradise/base/initialize.rb'
#¶ ↑
#¶ ↑
require 'ascii_paradise/base/menu.rb'
#¶ ↑
#¶ ↑
require 'ascii_paradise/base/reset.rb'
#¶ ↑
#¶ ↑
AsciiParadise::ClockCounter
¶ ↑
This class will show a little ASCII clock counter.
#¶ ↑
require 'ascii_paradise/clock_counter/clock_counter.rb' AsciiParadise::ClockCounter.new
{ :rename_kde_konsole_tab }
#¶ ↑
#¶ ↑
require 'ascii_paradise/commandline/help.rb'
#¶ ↑
#¶ ↑
require 'ascii_paradise/commandline/menu.rb'
#¶ ↑
#¶ ↑
require 'ascii_paradise/constants/unicode_symbols.rb'
#¶ ↑
#¶ ↑
AsciiParadise::TableFlip
¶ ↑
This code was written by havenwood - ask him for the license.
https://gist.githubusercontent.com/havenwood/7387731/raw/555d8b0f8d11e5b85921f3d7c55618e8a72fe7b1/table_flip.rb
#¶ ↑
require 'ascii_paradise/curses/table_flip.rb'
#¶ ↑
#¶ ↑
Methods and attributes stored here reside under the module AsciiParadise
namespace.
#¶ ↑
require 'ascii_paradise/debug/debug.rb'
#¶ ↑
#¶ ↑
AsciiParadise::GUI::Gtk::AnimatedFrameConstants
¶ ↑
#¶ ↑
require 'ascii_paradise/gui/shared_code/animated_frame/animated_frame_constants.rb' include ::AsciiParadise::GUI::Gtk::AnimatedFrameConstants
#¶ ↑
#¶ ↑
AsciiParadise::GUI::Gtk::AnimatedFrameModule
¶ ↑
#¶ ↑
require 'ascii_paradise/gui/shared_code/animated_frame/animated_frame_module.rb' include ::AsciiParadise::GUI::Gtk::AnimatedFrameModule
#¶ ↑
#¶ ↑
AsciiParadise::GUI::Gtk::WidgetModule
¶ ↑
#¶ ↑
require 'ascii_paradise/gui/shared_code/animated_frame/widget_module.rb' include ::AsciiParadise::GUI::Gtk::WidgetModule
#¶ ↑
#¶ ↑
require 'ascii_paradise/project/project.rb' AsciiParadise::PROJECT_BASE_DIRECTORY
#¶ ↑
#¶ ↑
require 'ascii_paradise/requires/require_sparky_components.rb'
#¶ ↑
#¶ ↑
AsciiParadise::Sparky::CLI
¶ ↑
#¶ ↑
#¶ ↑
AsciiParadise::BeautifulPattern
¶ ↑
#¶ ↑
#¶ ↑
AsciiParadise::Heart
¶ ↑
This class will generate a red ruby heart. This is a tribute to _why.
Usage example:
AsciiParadise::Heart.new
#¶ ↑
#¶ ↑
#¶ ↑
require 'ascii_paradise/table/table.rb'
#¶ ↑
#¶ ↑
require 'ascii_paradise/toplevel_methods/available_ascii_components_options.rb'
#¶ ↑
#¶ ↑
require 'ascii_paradise/toplevel_methods/clear_screen.rb'
#¶ ↑
#¶ ↑
require 'ascii_paradise/toplevel_methods/colour_parse_this_string.rb' puts AsciiParadise.colour_parse_this_string(ARGV)
#¶ ↑
require 'ascii_paradise/toplevel_methods/colour_parse_this_string.rb'
#¶ ↑
#¶ ↑
require 'ascii_paradise/toplevel_methods/e.rb'
#¶ ↑
#¶ ↑
require 'ascii_paradise/toplevel_methods/new.rb'
#¶ ↑
#¶ ↑
require 'ascii_paradise/toplevel_methods/return_dataset_of_this_animated_ascii_component.rb' dataset = AsciiParadise.dataset_for(:rubber_duck)
#¶ ↑
#¶ ↑
require 'ascii_paradise/toplevel_methods/run_this_animated_component.rb' AsciiParadise.run_this_animated_component
#¶ ↑
#¶ ↑
require 'ascii_paradise/toplevel_methods/sort_files.rb' AsciiParadise.sort_files
#¶ ↑
#¶ ↑
require 'ascii_paradise/toplevel_methods/to_camelcase.rb'
#¶ ↑
#¶ ↑
require 'ascii_paradise/toplevel_methods/wrap_at.rb'
#¶ ↑
#¶ ↑
#¶ ↑
require 'ascii_paradise/www/embeddable_interface.rb' include AsciiParadise::EmbeddableInterface
#¶ ↑
Constants
- ARRAY_SAY_CONSTANTS
#¶ ↑
ARRAY_SAY_CONSTANTS
¶ ↑The names here correspond to .ascii files. For instance, there will be a file called “cat_in_the_hat.ascii”, in the subdirectory ascii_say/.
Sort this Array alphabetically.
#¶ ↑
- AsciiCounter
- CAT_FACE
#¶ ↑
AsciiParadise::CAT_FACE
¶ ↑#¶ ↑
- CHECKMARK_SYMBOL
#¶ ↑
CHECKMARK_SYMBOL
¶ ↑#¶ ↑
- CLEAR_COMMAND
#¶ ↑
CLEAR_COMMAND
¶ ↑#¶ ↑
- DEFAULT_COLOUR_TO_USE
#¶ ↑
DEFAULT_COLOUR_TO_USE
¶ ↑#¶ ↑
- HOME_DIRECTORY_OF_THE_USER_X
#¶ ↑
HOME_DIRECTORY_OF_THE_USER_X
¶ ↑#¶ ↑
- LAST_UPDATE
#¶ ↑
LAST_UPDATE
¶ ↑#¶ ↑
- MONA_LISA
#¶ ↑
AsciiParadise::MONA_LISA
¶ ↑#¶ ↑
- N
#¶ ↑
N
¶ ↑#¶ ↑
- N_CHARACTERS_PER_LINE
#¶ ↑
AsciiParadise::N_CHARACTERS_PER_LINE
¶ ↑Default value to be used for word-wrap splitting.
#¶ ↑
- PROJECT_BASE_DIRECTORY
#¶ ↑
AsciiParadise::PROJECT_BASE_DIRECTORY
¶ ↑#¶ ↑
- R
#¶ ↑
R
¶ ↑#¶ ↑
- REGISTERED_CLASS_METHODS
#¶ ↑
AsciiParadise::REGISTERED_CLASS_METHODS
¶ ↑Register all class methods that can be used via .random here.
#¶ ↑
- SLEEP_FOR_N_SECONDS
#¶ ↑
SLEEP_FOR_N_SECONDS
¶ ↑#¶ ↑
- SNOWMAN
#¶ ↑
SNOWMAN
¶ ↑#¶ ↑
- Table
#¶ ↑
Add an “alias” called
Table
next.#¶ ↑
- UNICODE_DOUBLE_BORDER_BOTTOM_LEFT
#¶ ↑
UNICODE_DOUBLE_BORDER_BOTTOM_LEFT
¶ ↑#¶ ↑
- UNICODE_DOUBLE_BORDER_BOTTOM_RIGHT
#¶ ↑
UNICODE_DOUBLE_BORDER_BOTTOM_RIGHT
¶ ↑#¶ ↑
- UNICODE_DOUBLE_BORDER_HORIZONTAL
#¶ ↑
UNICODE_DOUBLE_BORDER_HORIZONTAL
¶ ↑#¶ ↑
- UNICODE_DOUBLE_BORDER_TOP_LEFT
#¶ ↑
UNICODE_DOUBLE_BORDER_TOP_LEFT
¶ ↑#¶ ↑
- UNICODE_DOUBLE_BORDER_TOP_RIGHT
#¶ ↑
UNICODE_DOUBLE_BORDER_TOP_RIGHT
¶ ↑#¶ ↑
- UNICODE_DOUBLE_BORDER_VERTICAL
#¶ ↑
UNICODE_DOUBLE_BORDER_VERTICAL
¶ ↑#¶ ↑
- URL_TO_THE_DOCUMENTATION
#¶ ↑
URL_TO_THE_DOCUMENTATION
¶ ↑#¶ ↑
- VERSION
#¶ ↑
VERSION
¶ ↑#¶ ↑
Public Class Methods
#¶ ↑
AsciiParadise[]¶ ↑
This is an alias towards one of the registered methods listed above.
If it can not be found, we will use the last else clause and delegate to AsciiParadise.ascii_counter()
instead.
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/run_this_animated_component.rb, line 125 def self.[](i = 12) _ = available_ascii_components? case i when 'random','', # empty string also invokes random, as of Nov 2015. /^run(_|-)?random(_|-)?animation$/i run_random_animation else if i.to_s =~ /^\d+$/ run_this_animated_component( _[i.to_i - 1] ) else run_this_animated_component(i) end end end
#¶ ↑
AsciiParadise.ascii_say
¶ ↑
Use a simplified ascii-talker, a bit like in a cartoon.
The second argument of this method tells us which subcomponent is to be used.
Usage examples:
AsciiParadise.say 'Yo there how do you do?', :wizard
#¶ ↑
# File lib/ascii_paradise/ascii_say/say.rb, line 25 def self.ascii_say( i = 'Hello world!', use_which_subcomponent = :random ) if i.is_a? Array i = i.join(' ') end case use_which_subcomponent.to_sym # ======================================================================= # # === :random # # This entry point will list all possible components that respond # to .say(). # ======================================================================= # when :random array = [ AsciiParadise::Alien, AsciiParadise::Buddha, AsciiParadise::CatInTheHat, AsciiParadise::DomeTent, AsciiParadise::FlowerDecoration, AsciiParadise::Wizard, AsciiParadise::Knight, AsciiParadise::SexyAngel, AsciiParadise::Cowsay, AsciiParadise::Ponysay ] subcomponent_to_use = array.sample # ======================================================================= # # === :alien # ======================================================================= # when :alien subcomponent_to_use = AsciiParadise::Alien # ======================================================================= # # === :buddha # ======================================================================= # when :buddha subcomponent_to_use = AsciiParadise::Buddha # ======================================================================= # # === :dome_tent # ======================================================================= # when :dome_tent, :tent subcomponent_to_use = AsciiParadise::DomeTent # ======================================================================= # # === :flower # ======================================================================= # when :flower, :flower_decoration subcomponent_to_use = AsciiParadise::FlowerDecoration # ======================================================================= # # === :cat # ======================================================================= # when :cat, :cat_in_the_hat subcomponent_to_use = AsciiParadise::CatInTheHat # ======================================================================= # # === :wizard # ======================================================================= # when :wizard subcomponent_to_use = AsciiParadise::Wizard # ======================================================================= # # === :knight # ======================================================================= # when :knight subcomponent_to_use = AsciiParadise::Knight # ======================================================================= # # === :sexy_angel # ======================================================================= # when :sexy_angel subcomponent_to_use = AsciiParadise::SexyAngel # ======================================================================= # # === :cowsay # ======================================================================= # when :cowsay, :cow subcomponent_to_use = AsciiParadise::Cowsay # ======================================================================= # # === :ponysay # ======================================================================= # when :ponysay, :pony subcomponent_to_use = AsciiParadise::Ponysay end subcomponent_to_use.say i end
#¶ ↑
AsciiParadise.ask_the_user_which_component_should_be_run_next
¶ ↑
We will ask the user which component should be run next.
#¶ ↑
# File lib/ascii_paradise/interactive/interactive.rb, line 77 def self.ask_the_user_which_component_should_be_run_next e e 'Input your command next. Input "help" or "h" to get all options and' e '"exit" or "q" to exit from this user input loop again.' e return_value = loop { user_input = $stdin.gets.chomp.strip # ===================================================================== # # === Downcase it next # ===================================================================== # user_input.downcase! case user_input # case tag # ===================================================================== # # === clear # ===================================================================== # when /^clear$/i e 'Clearing colour assignments next.' clear_colours # ===================================================================== # # === help # ===================================================================== # when /^-?-?help$/i,'h' show_interactive_help # ===================================================================== # # === exit # ===================================================================== # when 'exit','q' e 'Exiting now.' exit else # Else the user did input something. We will evaluate this. if ::Colours.does_include? user_input e 'Now using Colours. '+user_input+' colour.' @colour = user_input else components = ::AsciiParadise.return_all_animated_ascii_components result = nil # possible_match = # result.map {|entry| entry.to_s }.select {|entry| entry.include? user_input } # =================================================================== # # === First check if it is a number # =================================================================== # if user_input =~ /^\d+$/ result = components[user_input.to_i - 1] # =================================================================== # # === Check if the input is part of the component # =================================================================== # # elsif !possible_match.empty? # Not enable dfor now. # else # Else we did not find anything. end if result _ = nil if @colour _ = '--use-this-colour='+@colour.to_s end result.new(_) # Instantiate it here. end end end } return return_value end
#¶ ↑
AsciiParadise.available_ascii_components?
¶ ↑
This will return a sorted Array which will have all the ascii components that are available.
This Array will look like so:
["AirplaneOverForest", "AnimatedCigarette"] # And so on.
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/available_ascii_components.rb, line 26 def self.available_ascii_components? target = ::AsciiParadise.animations_directory? array = [] Dir["#{target}*.rb"].each {|file| _ = File.basename(file). gsub(/ascii_/,''). sub(/\.rb$/,'').capitalize # ===================================================================== # # Camelcase it: # ===================================================================== # if _.include? '_' _ = _.split('_').map {|entry| entry.capitalize }.join end array << _ } array.sort # Must sort it alphabetically. end
#¶ ↑
AsciiParadise.available_ascii_components_options
¶ ↑
The Array that will be returned here, is used in a case-when menu elsewhere. It is used to determine which options are applicable in order to show the available ascii components of this project.
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/available_ascii_components_options.rb, line 17 def self.available_ascii_components_options %w( --available --show-available --showavailable --overview overview show-available ) end
#¶ ↑
AsciiParadise.colour_parse_this_string
¶ ↑
This method can take an existing String and replace all html colour tags, such as <steelblue>, with the corresponding ASCII escape code, on the commandline.
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/colour_parse_this_string.rb, line 21 def self.colour_parse_this_string(i) if i.is_a? Array i = i.first end if i and File.file?(i) i = File.readlines(i) end if i.is_a? String i = i.split("\n") end i.map! {|entry| if ::Colours.does_this_line_include_a_html_colour?(entry) # =================================================================== # # The line contains a HTML colour, so let's parse it. # =================================================================== # entry = ::Colours.replace_all_html_colours_in_this_line(entry, :default, :revert) end entry } if i.is_a? Array i = i.join end i end
#¶ ↑
AsciiParadise.demo
(demo tag, test tag)¶ ↑
We can use this method to demo what the AsciiParadise
is capable of doing.
#¶ ↑
# File lib/ascii_paradise/demo/demo.rb, line 21 def self.demo(delay = 12) # 12 Seconds between individual runs. if delay.is_a? Hash if delay.has_key? :delay delay = delay.delete :delay end end e 'We will next test the various components of the AsciiParadise project.' e e 'We will display a short header to explain which component we will test.' e e 'Next we test '+sfancy('AsciiParadise.seductive_lady')+':' AsciiParadise.seductive_lady e 'Next we test '+sfancy('AsciiParadise.attractive_lady')+':' AsciiParadise.attractive_lady # ======================================================================= # # === Next, show the Mona Lisa, as ASCII art. # ======================================================================= # e e 'Next, we show the Mona Lisa, via AsciiParadise.mona_lisa' e AsciiParadise.mona_lisa e # ======================================================================= # # === Next, showing the pink panther. # ======================================================================= # e e 'Next, showing the the pink panther:' AsciiParadise.pink_panther e e 'Next we try '+sfancy('AsciiParadise.ascii_counter')+':' AsciiParadise.ascii_counter(delay) e # Need this newline here. e 'Next we test '+sfancy('AsciiParadise.ascii_box')+':' AsciiParadise.ascii_box ['Hello World!', 'what a big world'] e 'Next we test '+sfancy('AsciiParadise.draw_heart')+':' AsciiParadise.draw_heart size: 25 e 'Next we test '+sfancy('AsciiParadise.sierpinski_triangle (size: 25)')+':' AsciiParadise.sierpinski_triangle size: 25 e 'Next we test '+sfancy('AsciiParadise.beautiful_pattern')+':' AsciiParadise.beautiful_pattern e e 'Next we test '+sfancy('AsciiParadise.ascii_circle')+': (radius will be 25)' AsciiParadise.ascii_circle(25) e e 'Next we test AsciiParadise.progress_bar:' AsciiParadise.progress_bar e e 'Next we test AsciiParadise.rotating_slash:' AsciiParadise.rotating_slash e 'Next we test AsciiParadise.rotating_dna :dna:' AsciiParadise.rotating_dna :dna e e 'Next we test AsciiParadise.rotating_dna :star:' AsciiParadise.rotating_dna :star # =========================================================================== # # === ASCII Animations # # At this point come the various ASCII-animations. # =========================================================================== # e 'Next we test AsciiParadise.volcano:' AsciiParadise.volcano {{ run_n_times: 10 }} # Run 10 times. e 'Next we test AsciiParadise.earth:' AsciiParadise.earth {{ run_n_times: 6 }} e 'Next we test AsciiParadise.steamer:' AsciiParadise.steamer {{ run_n_times: 6 }} e 'Next we test AsciiParadise.animated_clock:' AsciiParadise.animated_clock {{ run_n_times: 10 }} # Run 10 times. e 'Next we test AsciiParadise.bubble_dragon:' AsciiParadise.bubble_dragon_animation e 'Next we test AsciiParadise.swimming_lane:' AsciiParadise.swimming_lane e 'Next we test AsciiParadise.animated_cigarette:' AsciiParadise.animated_cigarette e 'Next we test AsciiParadise.animated_pacman:' AsciiParadise.animated_pacman e 'Next we test AsciiParadise.animated_duck:' AsciiParadise.animated_duck e 'Next testing animated progress bar' AsciiParadise.animated_progress_bar e 'Next we test AsciiParadise.dancing_girl (we will wait 8 seconds before doing so):' sleep delay AsciiParadise.dancing_girl # Pacman-dance also blocks the screen. e 'Next we test AsciiParadise.static_pacman:' AsciiParadise.static_pacman e 'Next, table flip:' AsciiParadise.table_flip end
#¶ ↑
AsciiParadise.enable_debug
¶ ↑
The first argument determines whether we will give a notification to the user, when he wants to have it. By default, no notification will be made, to lessen the noise-level.
This method will enable debug all across the AsciiParadise
components.
#¶ ↑
# File lib/ascii_paradise/debug/debug.rb, line 42 def self.enable_debug( optional_be_verbose = false ) case optional_be_verbose when :be_verbose optional_be_verbose = true end if optional_be_verbose e 'We will now debug when we run code from the AsciiParadise project.' end @debug = true end
#¶ ↑
AsciiParadise.figlet
¶ ↑
This method requires the program called 'figlet' installed - otherwise it will not work. If you wish to add more fonts then you can download them from websites such as www.jave.de/figlet/fonts/overview.html or other sites.
Figlet is a text-to-ASCII “symbols” converter. To make use of fonts, you can issue something like this:
figlet -w 120 -f ~/Downloads/broadway.flf
The first argument to this method should be a String. This string will be “figletized” - that is, converted into an ASCII representation.
The second (optional) argument can be used to specify the path to a locally existing .flf file (font file).
Note that this method will return a String.
The following list shows some fonts which I consider as useful; many other fonts are quite crappy, though.
Invocation examples:
AsciiParadise.figlet 'Wikipedia' AsciiParadise.figlet 'Wikipedia', '3d_diagonal' AsciiParadise.figlet 'Wikipedia', :acrobatic AsciiParadise.figlet 'Wikipedia', :alpha AsciiParadise.figlet 'Wikipedia', :broadway AsciiParadise.figlet 'Wikipedia', :colossal AsciiParadise.figlet 'Wikipedia', :doh AsciiParadise.figlet 'Wikipedia', 'Georgia11' AsciiParadise.figlet 'Wikipedia', 'pebbles' AsciiParadise.figlet 'Wikipedia', 'univers'
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/figlet.rb, line 49 def self.figlet( i, optional_use_this_font = nil ) if i.is_a? Array i = i.join(' ').strip end cmd_to_use = 'figlet -t'.dup if optional_use_this_font unless optional_use_this_font.include? '/' # =================================================================== # # Use a hardcoded path in this case. # =================================================================== # optional_use_this_font.prepend('/Depot/jjj/fonts/') end cmd_to_use << ' -f '+optional_use_this_font.to_s unless cmd_to_use.end_with? '.flf' cmd_to_use << '.flf' end end cmd_to_use << " #{i}" result = `#{cmd_to_use}` return result end
#¶ ↑
AsciiParadise.include_this_file?
¶ ↑
This method can be used to determine whether we do include a specific file. Any '-' tokens in the input will be ignored, thus allowing you to more easily search for the name of the file at hand.
Usage example:
AsciiParadise.include_this_file? '--endless_runner' AsciiParadise.include_this_file? '--volcano' # => true
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/misc.rb, line 27 def self.include_this_file?(i) i = File.basename(i.to_s.delete('-')) files = Dir[project_base_dir?+'animations/*.rb'].map {|entry| File.basename(entry) } files.any? {|filename| filename.include? i } end
#¶ ↑
AsciiParadise.initialize_the_animated_ascii_components
¶ ↑
This method will initialize all the animated ASCII components, but only if this has not yet been done.
#¶ ↑
# File lib/ascii_paradise/requires/require_animations_files.rb, line 30 def self.initialize_the_animated_ascii_components unless @have_the_animations_files_been_required require_animations_files end end
#¶ ↑
AsciiParadise.interactive
¶ ↑
Use this method if you want to ask interactively what component we should run next.
#¶ ↑
# File lib/ascii_paradise/interactive/interactive.rb, line 26 def self.interactive @show_this_message_on_exit = 'We will exit now, as requested.' register_sigint initialize_animated_ascii_components ask_the_user_which_component_should_be_run_next end
#¶ ↑
AsciiParadise.n_animated_ascii_components
¶ ↑
This method will return a number, which tells us how many ASCII components are registered in this project.
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/available_ascii_components.rb, line 51 def self.n_animated_ascii_components ::AsciiParadise.available_ascii_components?.size end
#¶ ↑
AsciiParadise.n_animated_components?
¶ ↑
This will return how many animated components we have.
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/n_animated_components.rb, line 17 def self.n_animated_components? # 66 files = Dir[ AsciiParadise.animations_subdirectory?+'*.rb' ] files.size # Return how many entries we have found here. end
#¶ ↑
AsciiParadise.register
¶ ↑
The second argument to this method is the path to the .ascii file in question, the template that we will use for the speak-bubble.
#¶ ↑
# File lib/ascii_paradise/ascii_say/parse_static_ascii.rb, line 243 def self.register(name, template) AsciiParadise.const_set( name, AsciiParadise::ParseStaticAscii.new(template) ) end
#¶ ↑
AsciiParadise.require_animations_files
¶ ↑
#¶ ↑
# File lib/ascii_paradise/requires/require_animations_files.rb, line 39 def self.require_animations_files # ======================================================================= # # Pull in all the subcomponents within the "ascii_paradise/animations/" # directory next. # ======================================================================= # Dir["#{project_base_dir?}animations/*.rb"].each {|file| require "ascii_paradise/animations/#{File.basename(file)}" } @have_the_animations_files_been_required = true end
#¶ ↑
AsciiParadise.require_static_ascii_files
¶ ↑
#¶ ↑
# File lib/ascii_paradise/requires/require_static_ascii_files.rb, line 14 def self.require_static_ascii_files # ======================================================================= # # Pull in all the subcomponents within the "ascii_paradise/static/" # directory next. # ======================================================================= # Dir["#{AsciiParadise.static_ascii?}*.rb"].each {|file| require "ascii_paradise/static_ascii/#{File.basename(file)}" } end
#¶ ↑
AsciiParadise.require_the_toplevel_methods
¶ ↑
#¶ ↑
# File lib/ascii_paradise/requires/require_the_toplevel_methods.rb, line 17 def self.require_the_toplevel_methods Dir["#{AsciiParadise::PROJECT_BASE_DIRECTORY}toplevel_methods/*.rb"].each {|this_file| require "ascii_paradise/toplevel_methods/#{File.basename(this_file)}" } end
#¶ ↑
AsciiParadise.return_all_animated_ascii_components
¶ ↑
This method will return all AsciiParadise
components that can be animated.
For now we assume that this will only work for all those components that are a subclass of class AsciiParadise::Animation
.
Usage example:
x = AsciiParadise.return_all_animated_ascii_components
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/available_ascii_components.rb, line 69 def self.return_all_animated_ascii_components # ======================================================================= # # First obtain the available candidates: # ======================================================================= # possible_candidates = available_ascii_components? # ======================================================================= # # Turn these into real constants, via const_get(). In order for this # to work, the whole dataset has to be initialized for these individual # classes. # ======================================================================= # possible_candidates.map! {|entry| if ::AsciiParadise.const_defined? entry.to_sym entry = ::AsciiParadise.const_get(entry) end entry } possible_candidates.compact! # ======================================================================= # # Next select the proper entries that contain the dataset.: # ======================================================================= # possible_candidates.select! {|entry| entry.is_animated? } # ======================================================================= # # Now we have the entries that we want to have, thus we can return them. # ======================================================================= # return possible_candidates end
#¶ ↑
AsciiParadise.return_dataset_of_this_animated_ascii_component
¶ ↑
This method can retrieve the dataset of a given animated ASCII component. This ASCII component must have been registered, though,
The argument to this method should be camelcased, e. g. :RubberDuck rather than :rubber_duck. In order to simplify the use of the API, the user can also send :rubber_duck, though.
A String can also be passed into this method, such as 'RubberDuck', but it is recommended to use Symbols, if possible, such as :rubber_duck or :RubberDuck.
Usage example:
dataset = AsciiParadise.dataset_for(:rubber_duck) dataset = AsciiParadise.dataset_for(:table_tennis) dataset = AsciiParadise.dataset_for('TableTennis') dataset = AsciiParadise.return_dataset_of_this_animated_ascii_component(:volcano)
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/return_dataset_of_this_animated_ascii_component.rb, line 35 def self.return_dataset_of_this_animated_ascii_component( i = :volcano, # :rubber_duck, convert_to_camelcase = true ) case convert_to_camelcase when :do_not_uppercase convert_to_camelcase = false end if i.is_a? Array i = i.first end # ======================================================================= # # Initialize the animated ASCII components next: # ======================================================================= # initialize_the_animated_ascii_components i = i.to_s i = to_camelcase(i) if convert_to_camelcase unless AsciiParadise.respond_to? i array_available_ascii_components = AsciiParadise.available_ascii_components? # ===================================================================== # # Try to find a fitting component in this case. # ===================================================================== # possible_matches = array_available_ascii_components.map {|inner_entry| inner_entry.to_s.downcase }.select {|entry| entry.include? i.to_s.downcase } if !possible_matches.empty? # =================================================================== # # In this case we have at the least one partial match. # =================================================================== # i = array_available_ascii_components.select {|entry| entry.to_s.downcase.include?(i.to_s.downcase) } if i.is_a? Array i = i.first end end end if AsciiParadise.respond_to? i instance = AsciiParadise.send(i) # ======================================================================= # # The dataset that will be returned is an Array. # ======================================================================= # dataset = instance.new { :do_not_run_yet }.dataset? return dataset else e "Not an animated component (#{i})." false end end
#¶ ↑
AsciiParadise.return_what_is_available
¶ ↑
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/show_available_ascii_components.rb, line 95 def self.return_what_is_available target = ::AsciiParadise.animations_directory? array = [] # ======================================================================= # # Next, obtain all entries residing in the Animations directory. # ======================================================================= # Dir["#{target}*.rb"].each {|file| # ===================================================================== # # Next, we modify it a bit, by getting rid of leading "ascii_" and # trailing ".rb" part, then capitalizing it: # ===================================================================== # _ = File.basename(file).sub(/^ascii_/,'').sub(/\.rb$/,'').capitalize.dup # ===================================================================== # # Followed by camelcasing it: # ===================================================================== # if _.include? '_' _ = _.split('_').map {|e| e.capitalize }.join end array << _ # And adding it to our Array. \o/ } return array end
#¶ ↑
AsciiParadise.run_class_based_on_this_filename
¶ ↑
This method should only be called after a prior call to AsciiParadise.include_this_file?()
.
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/run_class_based_on_this_filename.rb, line 17 def self.run_class_based_on_this_filename(i) if i.is_a? Array i = i.first end # ======================================================================= # # First, obtain the proper filename. # ======================================================================= # i = File.basename(i.to_s.delete('-')) i.sub!(/#{File.extname(i)}$/,'') run_this_animated_component(i) end
#¶ ↑
AsciiParadise.run_this_animated_component
¶ ↑
This toplevel method can be used to run an animated component of the AsciiParadise
project. The main purpose is, primarily, to allow this from the commandline directly, so that it can be used from the file residing at bin/ascii_paradise directly.
The API use may be like this:
AsciiParadise.run_this_animated_component '--endless_runner' AsciiParadise.run_this_animated_component '--chopper'
Note that you can also obtain individual frames, like this:
AsciiParadise.run(:spider) { :frame5 } AsciiParadise.run(:spider) { 5 }
This component will be returned.
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/run_this_animated_component.rb, line 34 def self.run_this_animated_component( i = :default ) if i.is_a? Array i = i.join(' ').strip # Aggregate the Array into a String. end case i when :default i = 'endless_runner' # This is the default value. end require 'abbrev' array_available_constants = available_ascii_components? this_constant = i.to_s.delete('-') # This will now be something like "endless_runner". case this_constant # Use some popular aliases/shortcuts. when 'tennis' this_constant = 'table_tennis' end if this_constant.include? '_' # This requires a camelcase-operation! this_constant = to_camelcase(this_constant) end unless array_available_constants.include? this_constant # ===================================================================== # # In this case, the input was not found, so we will try to # abbrev-find something more useful. # ===================================================================== # flattened = Abbrev.abbrev(array_available_constants).flatten alternatives = Hash[*flattened.sort] if alternatives.has_key? this_constant # =================================================================== # # Ok, the hash includes that key, so find the real constant next. # =================================================================== # this_constant = alternatives[this_constant] end end if this_constant.include? '=' # In this case, assume input such as "colour=slateblue" # ======================================================================= # # Pass through in this case. Not sure if this is still in use or not, # though. # ======================================================================= # else # ======================================================================= # # In a constant, the first character is ALWAYS upcased. The following # line ensures this to be the case. # ======================================================================= # this_constant = this_constant.dup if this_constant.frozen? this_constant[0,1] = this_constant[0,1].upcase # ======================================================================= # # Ensure that the animated ASCII components are initialized next. # ======================================================================= # initialize_the_animated_ascii_components if ::AsciiParadise.const_defined? this_constant yielded = nil if block_given? yielded = yield end if yielded if yielded.is_a? Symbol # Assume a symbol such as: frame5 if yielded.to_s.start_with?('frame') yielded = yielded.to_s.sub(/^frame/,'').to_i end end if yielded.is_a? Numeric _ = AsciiParadise.return_dataset_of_this_animated_ascii_component(this_constant) return _[yielded - 1] end end ::AsciiParadise.send(this_constant).animate # We will make use of the .animate method. end end end
#¶ ↑
AsciiParadise.show_available_ascii_components
¶ ↑
This method will show the available ASCII classes.
Since as of March 2017, this class accepts an optional argument, which should be a Symbol. The default Symbol is :everything which means that we will display everything, including the LINKS.md file - on my home system at least.
If the argument is :show_only_ascii_components then we will only show the ASCII components of the project.
To invoke this, do:
aparadise --help aparadise --show-available
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/show_available_ascii_components.rb, line 33 def self.show_available_ascii_components( display_mode = :everything ) target = ::AsciiParadise.animations_directory? if display_mode == :everything e 'The following classes are part of this project:' e end array = [] # ======================================================================= # # Next, obtain all entries residing in the Animations directory. # ======================================================================= # Dir["#{target}*.rb"].each {|file| # ===================================================================== # # Next, we modify it a bit, by getting rid of leading "ascii_" and # trailing ".rb" part, then capitalizing it: # ===================================================================== # _ = File.basename(file).sub(/^ascii_/,'').sub(/\.rb$/,'').capitalize.dup # ===================================================================== # # Followed by camelcasing it: # ===================================================================== # if _.include? '_' _ = _.split('_').map {|e| e.capitalize }.join end array << _ # And adding it to our Array. \o/ } # ======================================================================= # # Next, display that array in a sorted manner. # ======================================================================= # array.sort.each_with_index {|entry, _index| _index += 1 case display_mode when :everything, :default e ' '+sfancy(entry) when :show_only_ascii_components e simp(_index.to_s.rjust(5))+') '+sfancy(entry) end } case display_mode # ======================================================================= # # === :everything # ======================================================================= # when :everything e # ===================================================================== # # === Next, display the LINKS.md file if it is available. # # This is the primary use case for :everything. # ===================================================================== # _ = "#{HOME_DIRECTORY_OF_THE_USER_X}DATA/PROGRAMMING_LANGUAGES/RUBY/src/ascii_paradise/doc/LINKS.md" if File.exist? _ e 'Additionally, these links are available:'; e File.read(_).split(N).select {|entry| entry.start_with? ' '}.each {|file| e ' '+simp(file) }; e end end end
#¶ ↑
AsciiParadise.show_help
¶ ↑
This method can be used to show the available help options in general.
It is a class-method primarily so that we can display the help options without having to instantiate a new class.
An invocation example for the method follows:
asciispider --help
#¶ ↑
# File lib/ascii_paradise/commandline/help.rb, line 25 def self.show_help e 'These options are available:' e array = [] # Store it in an Array, primarily so that we can run .sort on it. array << ' --run-n-times=() # run n times' array << ' --no-clear # do not invoke "clear"; this '\ 'may be helpful for debugging' array << ' --wait-for-keypress # wait for keypress events' array << ' --colour=green # use a specific colour, in this example green' array << ' --colour=random-colour # this is equivalent to --random-colour' array << ' --colourspray # use a random colour during each (full) '\ 'iteration' array << ' --rainbow-line # this option will colourize every '\ 'individual cell of a given frame' array << ' --disco-inferno # change the colour during every iteration' array << ' --half-colour # use two random colours, one '\ 'for the upper area, another for the lower area ' array << ' --numbers # like --full-debug but also uses red '\ '"frame numbers"' array << ' --random-colour # use a random colour (useful if '\ 'you do not want to decide on any specific colour)' array << ' --overview # show the available components '\ '(most of them at least)' array << ' --n_components? # show how many components are '\ 'available (a number)' array << ' --interactive # enter the interactive part '\ 'of AsciiParadise' array << ' --random # run a random component of '\ 'the AsciiParadise project' array << ' --show-frame=33 # show a specific frame, '\ 'in this case, frame 33' array << ' --framerate # query, in seconds, the delay '\ 'before the next frame is shown' array << ' --delay=2 (Float or Integer) # set the delay to 2 '\ 'seconds, in this case; use any number as input' array << ' --random # animate a random component' array.sort.each {|entry| e entry } # ======================================================================= # # Check if Konsole is available, as part of the Colours namespace. # ======================================================================= # unless Object.const_defined? :Colours e; e 'Note that you do not appear to have Colours available.' e 'This means that we will use normal ansicolours instead.' end e end
#¶ ↑
AsciiParadise.show_interactive_help
(help tag)¶ ↑
This method will allow the user to select the relevant component to run.
#¶ ↑
# File lib/ascii_paradise/interactive/interactive.rb, line 39 def self.show_interactive_help e 'These interactive components are available:' e # ======================================================================= # # === Get a handle on all the ASCII components of this project next # # This requires that we initiate these components first when running # this interactive-component, which has been done before via # initialize_animated_ascii_components(). # ======================================================================= # components = return_all_animated_ascii_components components.each_with_index {|entry, index| index += 1 e index.to_s.rjust(4)+' '+Colours.simp(entry) } e e 'Please input the positional number only, such as "50", without '\ 'the "" quotes.' e e 'If you wish to use colours-gem, simply input the colour, '\ 'then press enter.' e 'All components from that point onwards will use this colour.' e 'Use "clear" to clear it again.' # e 'You can input either the full name, a partial name, or the '\ # 'positional number.' # e # e 'So for instance, if you have this line here "50 AsciiParadise::Worm", '\ # 'then' # e 'you can invoke this either by typing 50, by typing worm or Worm '\ # 'but also' # e 'by typing AsciiParadise::Worm or AsciiParadise.Worm.' end
#¶ ↑
AsciiParadise.sort_files
¶ ↑
This module-method will keep the files stored in the animations/ subdirectory properly sorted, from 01 etc.. to 100 and so on.
It will use a regex in order to achieve this.
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/sort_files.rb, line 18 def self.sort_files(sort_these_files) sort_these_files.sort_by! {|entry| regex = /\/.+_(\d+).ascii$/ # See: http://rubular.com/r/9UfgCczgPi entry =~ regex number_value = $1.to_s.dup number_value.to_i } end
#¶ ↑
AsciiParadise.sparky
¶ ↑
This method will return a UTF-8 “sparky” line.
Invocation example:
array = [3, 33] AsciiParadise.sparky(array)
Next, let's show an example with a block passed to the method:
Let's say you have your list of open and closed issues, but you want to format it so the open ones are red and the closed ones are green, so you can quickly see how you are doing. Let's further suppose you use a gem that adds a color method to String for ANSI coloring.
line = AsciiParadise.sparky(list) { |tick, count, index| if index == 0 tick.color(:red) else tick.color(:green) end } line
@param numbers [Array<String, Fixnum, Float>] the numbers to be rendered @param &block [Proc] optional, can be used to format the rendered string
@return [String]
#¶ ↑
# File lib/ascii_paradise/sparky/sparkline.rb, line 152 def self.sparky(numbers, &block) new_sparky_instance = Sparky.new(numbers) # ======================================================================= # # Handle blocks given to this method. # ======================================================================= # if block new_sparky_instance.format(&block) end new_sparky_instance.to_s end
#¶ ↑
AsciiParadise.table
¶ ↑
This method will show a simple ASCII Table
of the given input.
The input to this method should be an Array or just several strings.
Usage example:
AsciiParadise.table 'hello','world','john', 'doe'
#¶ ↑
# File lib/ascii_paradise/table/table.rb, line 21 def self.table(*dataset) chunk = dataset.each_slice(2).to_a line = '# =========================================================== #' e line chunk.each {|array| _ = array[0].rjust(28)+' | '+array[1].ljust(28) e '# '+_+' #' } e line end
#¶ ↑
AsciiParadise.to_camelcase
¶ ↑
This will camelcase the given input, from 'rubber_duck' to 'RubberDuck'.
#¶ ↑
# File lib/ascii_paradise/toplevel_methods/to_camelcase.rb, line 14 def self.to_camelcase(i) if i.is_a? Array i = i.first end if i if i.include? '_' return i.to_s.split('_').map { |_| _.capitalize }.join else i = i.dup if i.frozen? i[0] = i[0].upcase end end i end
#¶ ↑
AsciiParadise.wrap_at
(Begrenzung tag, limit tag, boundary tag)¶ ↑
Wraps at a specified position.
Specific examples:
puts "abc abc abdc abc abc abc abc abc abc abc abcdef abc abc abc abc abc abc abc abc abc ".wrap_at(20) puts AsciiParadise.wrap_at(("x"*200), 30) ("x"*200).wrap_at(30,true,5)
# ¶ ↑
# File lib/ascii_paradise/toplevel_methods/wrap_at.rb, line 28 def self.wrap_at( this_string, # <- This must be the input-String. my_limit = N_CHARACTERS_PER_LINE, add_newline = true, add_padding = nil ) case my_limit when :default my_limit = N_CHARACTERS_PER_LINE end begin add_padding = add_padding.to_i unless add_padding.nil? if add_newline _ = "\\1\\3\n" # newline at end unless add_padding.nil? _ = _.linsert(' ' * add_padding) end return this_string.gsub( /(.{1,#{my_limit}})( +|$)\n?|(.{#{my_limit}})/,_ ) else _ = "\\1\\3" unless add_padding.nil? _ = _.linsert(' ' * add_padding) end return this_string.gsub( /(.{1,#{my_limit}})( +|$)\n?|(.{#{my_limit}})/, _ ) # No newline at the end. end rescue Exception => error puts error end end