Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/services/console/lib/purk/scripts/history.py
blob: 379ad5e3eb5c26d0ecbac70ef2c6736f4a14c9bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def onKeyPress(e):
    if not hasattr(e.window, 'history'):
        e.window.history = [], -1
        
    if e.key in ('Up', 'Down'):
        h, i = e.window.history
        
        if i == -1 and e.window.input.text:
            h.insert(0, e.window.input.text)
            i = 0
            
        if e.key == 'Up':
            i += 1
            
            if i < len(h):                
                e.window.history = h, i

                e.window.input.text = h[i]
                e.window.input.cursor = -1

        else: # e.key == 'Up'
            i -= 1
        
            if i > -1:
                e.window.history = h, i

                e.window.input.text = h[i]
                e.window.input.cursor = -1
                
            elif i == -1:
                e.window.history = h, i
            
                e.window.input.text = ''
                e.window.input.cursor = -1

def onInput(e):
    if not hasattr(e.window, 'history'):
        e.window.history = [], -1

    if e.text:
        h, i = e.window.history
    
        h.insert(0, e.text)
        
        e.window.history = h, -1