Class: AsciiParadise::AnimatedProgressBar

Inherits:
Animation show all
Defined in:
lib/ascii_paradise/animations/animated_progress_bar.rb

Constant Summary collapse

TopLeft =
#

The various constants - top left, top, top right and so forth.

These may be Unicode symbols.

#
"\342\224\214"
Top =
"\342\224\200"
TopRight =
"\342\224\220"
Left =
"\342\224\202"
Right =
"\342\224\202"
BottomLeft =
"\342\224\224"
Bottom =
"\342\224\200"
BottomRight =
"\342\224\230"
LightCheck =
"\e[32m\342\234\223\e[0m"
Check =

A checkbox here.

"\e[32m\342\234\224\e[0m"
BACKTRACKING =
#

BACKTRACKING

#
"\e[3A"
MAX_VALUE =
50
STEP_TO =
100
STEP_SIZE =
1.0

Constants inherited from Animation

AsciiParadise::Animation::RUN_N_TIMES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Animation

#ascii_files?, #dataset?, #delay?, #display, #display_the_frame, #do_clear?, #do_use_colour_spray, #do_use_disco_inferno, #do_use_half_colours, #do_use_rainbow_colours, #guess_filename, is_animated?, #is_animated?, #load_animated_ascii_files_from_this_directory, #load_ascii_files, #load_ascii_files_and_determine_the_dataset, #load_dataset, #mediumpurple, #parse_dataset_from_this_control_file, #return_filename, #return_the_name_to_the_proper_animation_directory_of_this_animated_component, run, #run_n_times?, #run_with_this_dataset, #run_with_this_dataset_while_waiting_for_keypress_events, #set_dataset, #set_delay, #set_run_n_times, #set_use_ascii_files_from_this_directory, #show_frame_at_this_position, #show_to_the_user_how_to_operate_the_keypress_interface, #sleep_with_the_default_delay, #use_disco_inferno?

Methods inherited from Base

animation_dir?, #animation_directory?, #clear_screen, #colour_parse_this_string, #debug?, #do_not_run_already, #do_not_use_clear, #do_use_random_colour, #do_wait_for_keypress_event, e, #e, #enable_debug, #is_animated?, #menu, #project_base_dir?, #register_sigint, #remove_trailing_ansci_escape_code, #report_how_many_animated_components_exist, #return_basename_of_this_file_without_the_extension, #return_random_colour, #rev, #royalblue, run, #set_use_this_colour, #sfancy, #sfile, #show_available_components, #show_help, #simp, #slategrey, #sort_files, #static_dir?, #steelblue, #swarn, #use_colours?

Constructor Details

#initialize(pad = ['','',''], io = $stdout) ⇒ AnimatedProgressBar

#

initialize

#


49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ascii_paradise/animations/animated_progress_bar.rb', line 49

def initialize(
    pad = ['','',''],
    io  = $stdout
  )
  register_sigint
  reset
  @pad = pad # An Array. Initially empty.
  @io  = io # Stdout.
  # output_three_newlines
  run
end

Instance Attribute Details

#progressObject

Returns the value of attribute progress.



44
45
46
# File 'lib/ascii_paradise/animations/animated_progress_bar.rb', line 44

def progress
  @progress
end

Instance Method Details

#finishObject

#

finish

#


99
100
101
102
103
104
105
# File 'lib/ascii_paradise/animations/animated_progress_bar.rb', line 99

def finish
  @io.print BACKTRACKING,
    @pad[0], TopLeft, Top * MAX_VALUE, TopRight, "\n",
    @pad[1], Left, "\e[44m", " " * MAX_VALUE, "\e[0m", Right, " ", Check, "    \n",
    @pad[2], BottomLeft, Bottom * MAX_VALUE, BottomRight, "\n"
  @io.flush
end

#output_three_newlinesObject

#

output_three_newlines

#


71
72
73
# File 'lib/ascii_paradise/animations/animated_progress_bar.rb', line 71

def output_three_newlines
  puts N+N+N # Make three newlines. Unsure why.
end

#resetObject

#

reset

#


64
65
66
# File 'lib/ascii_paradise/animations/animated_progress_bar.rb', line 64

def reset
  @progress = 0
end

#runObject

#

run

#


110
111
112
113
114
115
116
# File 'lib/ascii_paradise/animations/animated_progress_bar.rb', line 110

def run
  0.step(STEP_TO, STEP_SIZE) { |i|
    update(i)
    sleep(rand * 1)
  }
  finish
end

#update(progress = nil) ⇒ Object

#

update

The main method that will output the bar.

#


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ascii_paradise/animations/animated_progress_bar.rb', line 80

def update(progress = nil)
  @progress = progress if progress
  prog   = @progress
  filled = (0.5 * prog).round
  free   = MAX_VALUE - filled
  # ======================================================================= #
  # Next draw the box.
  # ======================================================================= #
  @io.print BACKTRACKING,
    @pad[0], TopLeft, Top * MAX_VALUE, TopRight, "\n",
    @pad[1], Left, "\e[44m", ' ' * filled, "\e[46m", ' ' * free, 
    "\e[0m", Right, ' ', prog.round, "%\n",
    @pad[2], BottomLeft, Bottom * MAX_VALUE, BottomRight, N
  @io.flush
end