Created
June 4, 2016 16:37
-
-
Save thomasjslone/3a91175c8d2fe6a98fec7c6275bf3983 to your computer and use it in GitHub Desktop.
Windows Shell io loop class is portable and can be used by multiple classes to make consol apps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## this is a Handy Dandy shell class, it controls stdin/out flow allowing your programs | |
## to pass this class around and start and stop it with ease, I lost my elaborate version of this class so I just wipped this | |
## one up with haste. Feel free to offer suggestions. | |
## | |
## The object that becomes parent here usually has a @api variable, which processes the input to the app, i sometimes call it the | |
## application input firewall. | |
## | |
class Windows_Shell | |
def initialize(parent) | |
@parent = parent | |
@run = false | |
start | |
end | |
def start | |
@run = true | |
main_loop | |
exit | |
end | |
def stop | |
@run = false | |
end | |
def main_loop | |
while @run | |
print "<" + $shell_label.to_s + ": " | |
inp = gets.chomp.to_s | |
puts ">" + $shell_label.to_s + ": " + @parent.shell_in(inp).to_s | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment