summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/pirate.py16
-rw-r--r--examples/transcripts/exampleSession.txt (renamed from examples/exampleSession.txt)0
-rw-r--r--examples/transcripts/pirate.transcript10
-rw-r--r--examples/transcripts/transcript_regex.txt (renamed from examples/transcript_regex.txt)0
4 files changed, 18 insertions, 8 deletions
diff --git a/examples/pirate.py b/examples/pirate.py
index dd9fd98c..06fdb61b 100755
--- a/examples/pirate.py
+++ b/examples/pirate.py
@@ -25,13 +25,13 @@ class Pirate(Cmd):
"""Initialize the base class as well as this one"""
Cmd.__init__(self)
# prompts and defaults
- self.gold = 3
+ self.gold = 0
self.initial_gold = self.gold
self.prompt = 'arrr> '
def default(self, line):
"""This handles unknown commands."""
- print('What mean ye by "{0}"?'.format(line))
+ self.poutput('What mean ye by "{0}"?'.format(line))
def precmd(self, line):
"""Runs just before a command line is parsed, but after the prompt is presented."""
@@ -41,10 +41,10 @@ class Pirate(Cmd):
def postcmd(self, stop, line):
"""Runs right before a command is about to return."""
if self.gold != self.initial_gold:
- print('Now we gots {0} doubloons'
+ self.poutput('Now we gots {0} doubloons'
.format(self.gold))
if self.gold < 0:
- print("Off to debtorrr's prison.")
+ self.poutput("Off to debtorrr's prison.")
stop = True
return stop
@@ -61,17 +61,17 @@ class Pirate(Cmd):
self.gold -= int(arg)
except ValueError:
if arg:
- print('''What's "{0}"? I'll take rrrum.'''.format(arg))
+ self.poutput('''What's "{0}"? I'll take rrrum.'''.format(arg))
self.gold -= 1
def do_quit(self, arg):
"""Quit the application gracefully."""
- print("Quiterrr!")
+ self.poutput("Quiterrr!")
return True
def do_sing(self, arg):
"""Sing a colorful song."""
- print(self.colorize(arg, self.songcolor))
+ self.poutput(self.colorize(arg, self.songcolor))
yo_parser = argparse.ArgumentParser()
yo_parser.add_argument('--ho', type=int, default=2, help="How often to chant 'ho'")
@@ -84,7 +84,7 @@ class Pirate(Cmd):
chant = ['yo'] + ['ho'] * args.ho
separator = ', ' if args.commas else ' '
chant = separator.join(chant)
- print('{0} and a bottle of {1}'.format(chant, args.beverage))
+ self.poutput('{0} and a bottle of {1}'.format(chant, args.beverage))
if __name__ == '__main__':
diff --git a/examples/exampleSession.txt b/examples/transcripts/exampleSession.txt
index 840bee60..840bee60 100644
--- a/examples/exampleSession.txt
+++ b/examples/transcripts/exampleSession.txt
diff --git a/examples/transcripts/pirate.transcript b/examples/transcripts/pirate.transcript
new file mode 100644
index 00000000..570f0cd7
--- /dev/null
+++ b/examples/transcripts/pirate.transcript
@@ -0,0 +1,10 @@
+arrr> loot
+Now we gots 1 doubloons
+arrr> loot
+Now we gots 2 doubloons
+arrr> loot
+Now we gots 3 doubloons
+arrr> drink 3
+Now we gots 0 doubloons
+arrr> yo --ho 3 rum
+yo ho ho ho and a bottle of rum
diff --git a/examples/transcript_regex.txt b/examples/transcripts/transcript_regex.txt
index 7d017dee..7d017dee 100644
--- a/examples/transcript_regex.txt
+++ b/examples/transcripts/transcript_regex.txt