class UserIO

Inappropriately named, this class currently containes exclusively static methods which generate informative messages or alerts in case of errors.

TODO: include the translating-module and provide internationalization. TODO: include non-blocking input for Y/N questions and the like. For the time, UserIO contains only static methods.

Public Class Methods

compose(msg) click to toggle source
# File lib/userio.rb, line 171
def self::compose(msg)
        lines = msg.split("\n")       
        rule = rule(lines)
        puts vsp << rule
        puts hsp << lines.join("\n" << hsp)
        puts hsp << rule
        puts
end
hline() click to toggle source
# File lib/userio.rb, line 159
def self::hline
        '—'
end
hsp() click to toggle source
# File lib/userio.rb, line 156
def self::hsp
        "\t"
end
msg_all_sections_eliminated() click to toggle source
# File lib/userio.rb, line 34
def self::msg_all_sections_eliminated
        msg = "No section remain to be copied."
        msg << "\nThis means that there is no difference between the sought sections"
        msg << "\nin the source and those in the target file"
        compose msg
end
msg_available_information() click to toggle source
# File lib/userio.rb, line 90
def self::msg_available_information
        msg = 'Listing available configuration-files, short names and versions'
        compose msg
end
msg_cannot_copy(info = nil, err = nil) click to toggle source
# File lib/userio.rb, line 59
def self::msg_cannot_copy(info = nil, err = nil)
        msg = (info ? info : '')
        msg << "\nError! You must name two valid configuration files for source and target.\n"
        msg << err.message if err
        compose msg
end
msg_cannot_read_dir(dir, ex) click to toggle source
# File lib/userio.rb, line 124
def self::msg_cannot_read_dir(dir, ex)
        msg = 'Error! Cannot read directory ' << dir << ': ' << ex.message
        compose msg
end
msg_conf_dir_empty(info = nil) click to toggle source
# File lib/userio.rb, line 112
def self::msg_conf_dir_empty(info = nil)
        msg = "The given directory does not contain any useable configuration files!"
        msg << "\n" << info if info
        msg << "\nAborting. Bye."
        compose msg
end
msg_config_written() click to toggle source

unused

# File lib/userio.rb, line 100
def self::msg_config_written
        msg = 'The list of configuration-files has been written to ' << $CONFIG
        compose msg
end
msg_doing_nothing() click to toggle source
# File lib/userio.rb, line 128
def self::msg_doing_nothing
        msg = "Okay, doing nothing. Bye."
        compose msg
end
msg_done() click to toggle source
# File lib/userio.rb, line 139
def self::msg_done
        msg = "Done. Bye."
        compose msg
end
msg_files_or_dir_for_sn() click to toggle source
# File lib/userio.rb, line 48
def self::msg_files_or_dir_for_sn
        msg = "Error! For source and target either name complete file-paths or use short-names"
        msg << "\nIn the latter case you must also name the configuration-directory with -c,"
        msg << "\nif #{$DEF_CONF_DIR} does not apply!"
        compose msg
end
msg_info_conf_dir(dir) click to toggle source
# File lib/userio.rb, line 75
def self::msg_info_conf_dir(dir)               
        msg = 'Using configuration files from: ' << dir << " (default)"
        compose msg
end
msg_list_configs() click to toggle source
# File lib/userio.rb, line 95
def self::msg_list_configs
        msg = 'Listing available configuration-files'
        compose msg
end
msg_method_undefined(cname, method) click to toggle source
# File lib/userio.rb, line 70
def self::msg_method_undefined(cname, method)
        msg = "Error! Undefined method called (" << cname << "." << method << ")."
        msg << "\nAborting. Bye."
        compose msg
end
msg_missing_option() click to toggle source
# File lib/userio.rb, line 65
def self::msg_missing_option
        msg = "Error! You must call " << $0 << " with a program option."
        msg << "\nTry the option ‘-h’ or ‘--help’ for an option-summary."
        compose msg
end
msg_no_config(info = nil) click to toggle source
# File lib/userio.rb, line 79
def self::msg_no_config(info = nil)
        msg = 'ATTN! Cannot read the expected list of configuration-files.'
        msg << "\n" << info if info
        msg << "\nAborting. Bye."
        compose msg
end
msg_no_section_given(info = nil) click to toggle source
# File lib/userio.rb, line 54
def self::msg_no_section_given(info = nil)
        msg = "ERROR! No section has been specified, cannot procede."
        msg << "\n" << info if info
        compose msg
end
msg_option_parse_error(err) click to toggle source
# File lib/userio.rb, line 119
def self::msg_option_parse_error(err)
        msg = "Error! Option(s) " << err.args.join(', ') << ': ' << err.reason
        msg << "\nCall " << $0 << " with option ‘-h’ or ‘--help’ for an option summary"
        compose msg
end
msg_short_progs() click to toggle source
# File lib/userio.rb, line 85
def self::msg_short_progs
        msg = 'Listing the available program short-names'
        compose msg
end
msg_version() click to toggle source
# File lib/userio.rb, line 132
def self::msg_version
        msg = "#{$APP_NAME}\n"
        msg << rule($APP_NAME) << "\n"
        msg << "This program is free software. Use, modify and distribute it\nunder the terms of the Gnu General Public License, version 3\nor later."
        msg << "\n© 2016 Michael Uplawski <michael.uplawski@uplawski.eu>"
        compose msg
end
msg_will_copy(source_sections, originally, now) click to toggle source
# File lib/userio.rb, line 41
def self::msg_will_copy(source_sections, originally, now)
        msg="I am about to copy #{now} sections from the source- to the target file"
        msg << "\n#{originally-now} sections had to be eliminated (probably dupes)." if now < originally
        msg << "\n\nShall we procede (Y/N) or do you want to verify the sections to be copied, first (v)?"
        compose msg
end
msg_win_bailout() click to toggle source
# File lib/userio.rb, line 105
def self::msg_win_bailout
        msg = "“WE ARE SORRY FOR THE INCONVENIENCE”"
        msg << "\n... but this program does not (yet) run on MS-Windows® systems."
        msg << "\n... Aborting, bye."
        compose msg
end
rule(lines) click to toggle source
# File lib/userio.rb, line 163
def self::rule(lines)
        if(lines.respond_to?(:to_ary))
                hline * lines.max{|a,b| a.length <=> b.length}.length
        else
                hline * lines.length
        end
end
show_sections_prior_copy(sections) click to toggle source
# File lib/userio.rb, line 143
def self::show_sections_prior_copy(sections)
        msg = "The following section(s) are waiting to be copied:"
        msg << "\n" << rule(msg) << "\n"
        msg << sections.join("\n\n")
        msg << "\n\n Procede (Y) or Abort (N)?"
        compose msg
        wait_for_user
end
vsp() click to toggle source

The remainder just looks cool

# File lib/userio.rb, line 153
def self::vsp
        "\n\t"
end
wait_for_user() click to toggle source
# File lib/userio.rb, line 180
def self::wait_for_user()
        char = nil
        STDIN.raw do 
                STDIN.noecho do
                        until (STDIN.ready?)
                                sleep(0.1)
                        end

                        char = (STDIN.read_nonblock(1).ord rescue nil)
                end
        end
        return char
end