~chromakode/boots/nodes-async

« back to all changes in this revision

Viewing changes to src/boots/lib/ui/plain.py

  • Committer: Max Goodman
  • Date: 2010-02-07 09:29:31 UTC
  • mfrom: (19.1.6 boots)
  • Revision ID: chromakode@gmail.com-20100207092931-cr8c0ovic2l0f97g
Merge Victoria's help system module and command history persistence.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
from boots.lib.ui.generic import StdinDriver, StdoutPresenter
36
36
 
37
37
class PlainUI(StdinDriver, StdoutPresenter):
38
 
    def __init__(self, console, prompt1, prompt2, lingo):
 
38
    def __init__(self, console, prompt1, prompt2, hist_length, hist_file, lingo):
39
39
        self.metacommands = MetaCommands({
40
40
            '\lingo': self.switchlingo})
41
41
        self.console = console
42
42
        self.prompt1 = prompt1
43
43
        self.prompt2 = prompt2
 
44
        self.hist_file = hist_file
44
45
        self.lingo = lingo
45
46
        self.current_widths = None
46
47
        self.buffer = []
47
 
                    
 
48
        
 
49
        # FIXME: This should go in an initialization function
 
50
        readline.set_history_length(hist_length)
 
51
        self.read_history()
 
52
 
 
53
    def read_history(self):
 
54
        try:
 
55
            readline.read_history_file(self.hist_file)
 
56
        except IOError:
 
57
            pass
 
58
 
 
59
    def save_history(self):
 
60
        readline.write_history_file(self.hist_file)
 
61
        
 
62
    def unload(self):
 
63
        self.save_history()
 
64
 
48
65
    def get_input(self):
49
66
        """Gets user input from stdin via a prompt."""
50
67
        while True:
105
122
    #interface: Register the lingo used in main(), and register lingos
106
123
    #switched to here.
107
124
    def switchlingo(self, lingo):
108
 
        self.lingo = lingo
 
 
b'\\ No newline at end of file'
 
125
        self.lingo = lingo