# Module: Tgio

# Input

Input provides routines to handle retrieving input from consoles.

# Child modules and classes

Module Tgio::Dates
Module Tgio::Input
Module Tgio::Output

# Public Class Methods

### ansiclear ()

The desired effect is to clear the screen

Show source...

        # File bbs/lib/tgio.rb, line 85
    85:   def Tgio::ansiclear
    86:     JLine::ConsoleReader.new.clearScreen
    87:   end

### ansiprint (text, fgcolor=ANSI_WHITE, bgcolor=ANSI_ON_BLACK)

Print Output in a ANSI color block using Term::ANSIColor (DEPRECATED)

Show source...

        # File bbs/lib/tgio.rb, line 65
    65:   def Tgio::ansiprint(text, fgcolor=ANSI_WHITE, bgcolor=ANSI_ON_BLACK)
    66:       print fgcolor+bgcolor+text+ANSI_RESET
    67:   end

### mainbanner ()

AUDIT CODE: REPLACE WITH NEW TG COLORS Display the program‘s MAIN banner

Show source...

        # File bbs/lib/tgio.rb, line 71
    71:   def Tgio.mainbanner
    72:
    73:     ansiprint("OpenTelegard", ANSI_BRIGHT_CYAN)
    74:     ansiprint(" v", ANSI_CYAN)
    75:     ansiprint(TELEGARD_VERSION, ANSI_BRIGHT_CYAN)
    76:     ansiprint(" :: ", ANSI_BLUE)
    77:     ansiprint("Copyright (c) 2008-2010, Chris Tusa\n", ANSI_BRIGHT_CYAN)
    78:     ansiprint("All rights reserved.\n", ANSI_CYAN)
    79:     ansiprint("Distributed by LeafScale Systems - see the LICENSE file.\n\n", ANSI_DARK_GRAY)
    80:   end

### menu (template)

Displays menu from template and prompts user for inputkey.

Show source...

         # File bbs/lib/tgio.rb, line 175
    175:   def Tgio::menu(template)
    176:     t = Tgtemplate::Template.new(template)
    177:     t.render()
    178:     selection = Tgio::Input.inputkey
    179:     return selection
    180:   end

### printansifile (filename, paging=true, numlines=25)

Print an ANSI graphic file (legacy - see Tgtemplate)

Show source...

        # File bbs/lib/tgio.rb, line 90
    90:   def Tgio.printansifile(filename, paging=true, numlines=25)
    91:     # =>TODO: Add Paging feature to limit number of lines with more prompt
    92:
    93:     if File.exist?(filename)
    94:       File.open(filename, "r").each { |line| puts line }
    95:     else
    96:       return 1
    97:     end
    98:   end

### printreturn (retval)

Print to stdout the result

Show source...

         # File bbs/lib/tgio.rb, line 107
    107:   def Tgio.printreturn(retval)
    108:     ansiprint("[", ANSI_BLUE)
    109:     if retval == 0
    110:       ansiprint("DONE", ANSI_BRIGHT_CYAN)
    111:     elsif retval == 1
    112:       ansiprint("FAIL", ANSI_BRIGHT_RED)
    113:     elsif retval == 2
    114:       ansiprint("WAIT", ANSI_CYAN)
    115:     else
    116:       ansiprint("????", ANSI_BRIGHT_MAGENTA)
    117:     end
    118:     ansiprint("]\n", ANSI_BLUE)
    119:   end

### printstart (txt)

Print to stdout that an item is starting

Show source...

         # File bbs/lib/tgio.rb, line 101
    101:   def Tgio.printstart(txt)
    102:     ansiprint(txt, ANSI_WHITE)
    103:     ansiprint("."*(60-txt.length), ANSI_GRAY)
    104:   end

### question (template, inputsize)

Asks user a question. Wraps display of a template and inputform.

Show source...

         # File bbs/lib/tgio.rb, line 163
    163:   def Tgio::question(template, inputsize)
    164:     t = Tgtemplate::Template.new(template)
    165:     t.render()
    166:     if inputsize > 1
    167:       answer = Tgio::Input.inputform(inputsize)
    168:     elsif inputsize == 1
    169:       answer = Tgio::Input.inputkey
    170:     end
    171:     return answer
    172:   end

### run_pager ()

Paging Function to incorporate scrolling into program adapted from code written by : Nathan Weizenbaum nex-3.com/posts/73-git-style-automatic-paging-in-ruby

- WARN * Allowing execution of an external program is not good security

practices. Audit this for a better method.

Show source...

         # File bbs/lib/tgio.rb, line 126
    126:   def Tgio.run_pager
    127:     return unless STDOUT.tty?
    128:     read, write = IO.pipe
    129:     unless Kernel.fork # Child process
    130:       STDOUT.reopen(write)
    131:       STDERR.reopen(write) if STDERR.tty?
    132:       read.close
    133:       write.close
    134:       return
    135:     end
    136:     # Parent process, become pager
    137:     STDIN.reopen(read)
    138:     read.close
    139:     write.close
    140:     ENV['LESS'] = '-FSRX' # Don't page if the input is short enough
    141:     ENV['LESSSECURE'] = '1' # Turn on secure less (see man page)
    142:     Kernel.select [STDIN] # Wait until we have input before we start the pager
    143:     pager = ENV['PAGER'] || 'less'
    144:     exec pager rescue exec "/bin/sh", "-c", pager
    145:   end

### terminaldetect ()

Terminal detection to determine support, dimensions, etc.

Show source...

         # File bbs/lib/tgio.rb, line 150
    150:   def Tgio::terminaldetect
    151:         term = JLine::Terminal.terminal.new
    152:     terminfo = {
    153:       :supported  => term.is_supported,
    154:       :ansi       => term.is_ansisupported,
    155:       :height     => term.getTerminalHeight,
    156:       :width      => term.getTerminalWidth,
    157:       :echo       => term.is_echo_enabled
    158:     }
    159:     return terminfo
    160:   end