示例#1
0
    def keypress(self, size, key):
        if key == 'esc':
            urwid.emit_signal(self, 'exit_command')

        if key == 'tab':
            autoComplete(self)

        if key == 'enter':
            command = self.edit_text.strip()
            if command:
                self.edit_text = u''
                self.historyList.append(command)
                urwid.emit_signal(self, 'command_entered', command)
            self.historyIndex = len(self.historyList)
            self.edit_text = u''

        if key == 'up':
            self.historyIndex -= 1

            if self.historyIndex < 0:
                self.historyIndex = 0
            else:
                self.edit_text = self.historyList[self.historyIndex]

        if key == 'down':
            self.historyIndex += 1

            if self.historyIndex >= len(self.historyList):
                self.historyIndex = len(self.historyList)
                self.edit_text = u''
            else:
                self.edit_text = self.historyList[self.historyIndex]
        else:
            urwid.Edit.keypress(self, size, key)
示例#2
0
from autocomplete import autoComplete
from createTrie import createDataBase, normalForm

if __name__ == '__main__':
    # init trie
    data = dict()
    trie = createDataBase(data)

    # auto complete sentence
    while 1:
        sentenceToCheck = ""
        while 1:
            sentenceToCheck += input(f"your sentence here: {sentenceToCheck}")
            if sentenceToCheck[-1] == "#" or autoComplete(
                    trie, data, normalForm(sentenceToCheck)) == 0:
                print("-----new search-----")
                break
示例#3
0
def test_CommandBar(test_input, expected):
    uvm = urwidView(True)
    cb = CommandBar(lambda: uvm._update_focus(True), uvm)
    cb.set_edit_text(test_input)
    autoComplete(cb)
    assert cb.get_edit_text() == expected