1
# -*- coding: iso-8859-15 -*-
5
This module contains the actions when key pressed.
15
from __init__ import *
23
##################################################
24
##### global variables
25
##################################################
29
##################################################
31
##################################################
34
ord('p'): 'cursor_up',
35
ord('P'): 'cursor_up',
36
curses.KEY_UP: 'cursor_up',
37
ord('d'): 'cursor_down',
38
ord('D'): 'cursor_down',
39
curses.KEY_DOWN: 'cursor_down',
40
curses.KEY_PPAGE: 'page_previous',
41
curses.KEY_BACKSPACE: 'page_previous',
42
0x08: 'page_previous', # BackSpace
43
0x10: 'page_previous', # Ctrl-P
44
curses.KEY_NPAGE: 'page_next',
45
ord(' '): 'page_next',
46
0x0E: 'page_next', # Ctrl-N
47
curses.KEY_HOME: 'home',
50
curses.KEY_END: 'end',
55
curses.KEY_LEFT: 'cursor_left',
56
curses.KEY_RIGHT: 'cursor_right',
61
0x13: 'goto_file', # Ctrl-S
62
0x14: 'tree', # Ctrl-T
63
ord('0'): 'bookmark_0',
64
ord('1'): 'bookmark_1',
65
ord('2'): 'bookmark_2',
66
ord('3'): 'bookmark_3',
67
ord('4'): 'bookmark_4',
68
ord('5'): 'bookmark_5',
69
ord('6'): 'bookmark_6',
70
ord('7'): 'bookmark_7',
71
ord('8'): 'bookmark_8',
72
ord('9'): 'bookmark_9',
73
0x04: 'select_bookmark', # Ctrl-D
74
ord('b'): 'set_bookmark',
75
ord('B'): 'set_bookmark',
78
ord('\t'): 'change_panel', # tab
79
ord('.'): 'toggle_panels',
80
ord(','): 'swap_panels',
81
0x15: 'swap_panels', # Ctrl-U
82
ord('='): 'same_panels',
85
curses.KEY_IC: 'select_item',
86
ord('+'): 'select_group',
87
ord('-'): 'deselect_group',
88
ord('*'): 'invert_select',
91
ord('#'): 'show_size',
94
ord('i'): 'file_info',
95
ord('I'): 'file_info',
96
ord('@'): 'do_something_on_file',
97
0xF1: 'special_regards', # special regards
98
ord('/'): 'find_grep',
99
ord('t'): 'touch_file',
100
ord('T'): 'touch_file',
101
ord('l'): 'create_link',
102
ord('L'): 'create_link',
103
0x0C: 'edit_link', # Ctrl-L
104
0x0F: 'open_shell', # Ctrl-O
107
ord('v'): 'view_file',
108
ord('V'): 'view_file',
109
curses.KEY_F3: 'view_file',
110
ord('e'): 'edit_file',
111
ord('E'): 'edit_file',
112
curses.KEY_F4: 'edit_file',
115
curses.KEY_F5: 'copy',
118
curses.KEY_F6: 'move',
121
curses.KEY_F7: 'make_dir',
124
curses.KEY_DC: 'delete',
125
curses.KEY_F8: 'delete',
128
ord('h'): 'show_help',
129
ord('H'): 'show_help',
130
curses.KEY_F1: 'show_help',
131
ord('f'): 'file_menu',
132
ord('F'): 'file_menu',
133
curses.KEY_F2: 'file_menu',
134
curses.KEY_F9: 'general_menu',
137
curses.KEY_RESIZE: 'resize_window',
142
curses.KEY_F10: 'quit',
148
def do(_app, panel, ch):
152
act = 'ret = %s(panel)' % keytable[ch]
160
##################################################
162
##################################################
165
def cursor_up(panel):
170
def cursor_down(panel):
175
def page_previous(panel):
176
panel.file_i -= panel.dims[0]
177
if panel.pos == 1 or panel.pos == 2:
182
def page_next(panel):
183
panel.file_i += panel.dims[0]
184
if panel.pos == 1 or panel.pos == 2:
195
panel.file_i = panel.nfiles - 1
200
def cursor_left(panel):
202
if panel.path != os.sep:
203
olddir = os.path.basename(panel.path)
204
panel.init_dir(os.path.dirname(panel.path))
205
panel.file_i = panel.sorted.index(olddir)
208
if panel.path == panel.base:
209
olddir = os.path.basename(panel.vbase).replace('#vfs', '')
211
panel.init_dir(os.path.dirname(panel.vbase))
212
panel.file_i = panel.sorted.index(olddir)
215
olddir = os.path.basename(panel.path)
216
pvfs, base, vbase = panel.vfs, panel.base, panel.vbase
217
panel.init_dir(os.path.dirname(panel.path))
218
panel.vfs, panel.base, panel.vbase = pvfs, base, vbase
219
panel.file_i = panel.sorted.index(olddir)
223
def cursor_right(panel):
224
filename = panel.sorted[panel.file_i]
225
vfstype = check_compressed_tarfile(app, filename)
226
if panel.files[filename][files.FT_TYPE] == files.FTYPE_DIR:
228
if filename == os.pardir:
229
olddir = os.path.basename(panel.path)
230
panel.init_dir(os.path.dirname(panel.path))
231
panel.file_i = panel.sorted.index(olddir)
234
panel.init_dir(os.path.join(panel.path, filename))
237
if panel.path == panel.base and filename == os.pardir:
238
olddir = os.path.basename(panel.vbase).replace('#vfs', '')
240
panel.init_dir(os.path.dirname(panel.vbase))
241
panel.file_i = panel.sorted.index(olddir)
244
pvfs, base, vbase = panel.vfs, panel.base, panel.vbase
245
panel.init_dir(os.path.join(panel.path, filename))
246
panel.vfs, panel.base, panel.vbase = pvfs, base, vbase
247
elif panel.files[filename][files.FT_TYPE] == files.FTYPE_LNK2DIR:
248
panel.init_dir(files.get_linkpath(panel.path, filename))
249
elif (panel.files[filename][files.FT_TYPE] == files.FTYPE_REG or \
250
panel.files[filename][files.FT_TYPE] == files.FTYPE_LNK) and \
252
vfs.init(app, panel, filename, vfstype)
258
filename = panel.sorted[panel.file_i]
259
vfstype = check_compressed_tarfile(app, filename)
260
if (panel.files[filename][files.FT_TYPE] == files.FTYPE_REG or \
261
panel.files[filename][files.FT_TYPE] == files.FTYPE_LNK) and \
263
vfs.init(app, panel, filename, vfstype)
264
elif panel.files[filename][files.FT_TYPE] == files.FTYPE_DIR:
266
if filename == os.pardir:
267
olddir = os.path.basename(panel.path)
268
panel.init_dir(os.path.dirname(panel.path))
269
panel.file_i = panel.sorted.index(olddir)
272
panel.init_dir(os.path.join(panel.path, filename))
274
if panel.path == panel.base and filename == os.pardir:
275
olddir = os.path.basename(panel.vbase).replace('#vfs', '')
277
panel.init_dir(os.path.dirname(panel.vbase))
278
panel.file_i = panel.sorted.index(olddir)
281
pvfs, base, vbase = panel.vfs, panel.base, panel.vbase
282
panel.init_dir(os.path.join(panel.path, filename))
283
panel.vfs, panel.base, panel.vbase = pvfs, base, vbase
284
elif panel.files[filename][files.FT_TYPE] == files.FTYPE_LNK2DIR:
285
panel.init_dir(files.get_linkpath(panel.path, filename))
286
elif panel.files[filename][files.FT_TYPE] == files.FTYPE_EXE:
287
do_execute_file(panel)
288
elif panel.files[filename][files.FT_TYPE] == files.FTYPE_REG:
289
do_special_view_file(panel)
295
todir = doEntry('Go to directory', 'Type directory name')
297
if todir == None or todir == "":
299
todir = os.path.join(panel.path, todir)
302
panel.init_dir(todir)
306
def goto_file(panel):
307
tofile = doEntry('Go to file', 'Type how file name begins')
309
if tofile == None or tofile == "":
311
thefiles = panel.sorted[panel.file_i:]
313
if f.find(tofile) == 0:
317
panel.file_i = panel.sorted.index(f)
325
app.panel = not panel_i
327
t = Tree(panel.path, panel.pos)
336
def bookmark_0(panel):
337
goto_bookmark(panel, 0)
340
def bookmark_1(panel):
341
goto_bookmark(panel, 1)
344
def bookmark_2(panel):
345
goto_bookmark(panel, 2)
348
def bookmark_3(panel):
349
goto_bookmark(panel, 3)
352
def bookmark_4(panel):
353
goto_bookmark(panel, 4)
356
def bookmark_5(panel):
357
goto_bookmark(panel, 5)
360
def bookmark_6(panel):
361
goto_bookmark(panel, 6)
364
def bookmark_7(panel):
365
goto_bookmark(panel, 7)
368
def bookmark_8(panel):
369
goto_bookmark(panel, 8)
372
def bookmark_9(panel):
373
goto_bookmark(panel, 9)
376
def select_bookmark(panel):
377
cmd = messages.MenuWin('Select Bookmark', app.prefs.bookmarks).run()
386
def set_bookmark(panel):
388
messages.error('Set bookmark', 'Can\'t bookmark inside vfs')
391
ch = messages.get_a_key('Set bookmark',
392
'Press 0-9 to save the bookmark, Ctrl-C to quit')
393
if 0x30 <= ch <= 0x39: # 0..9
394
app.prefs.bookmarks[ch-0x30] = panel.path[:]
396
elif ch == -1: # Ctrl-C
401
def change_panel(panel):
407
def toggle_panels(panel):
409
# now => 2 panels mode
410
app.panels[0].pos = 1
411
app.panels[1].pos = 2
413
# now => full panel mode
415
app.panels[0].pos = 3
416
app.panels[1].pos = 0
418
app.panels[0].pos = 0
419
app.panels[1].pos = 3
420
app.panels[0].init_curses(app.panels[0].pos)
421
app.panels[1].init_curses(app.panels[1].pos)
423
app.get_otherpanel().fix_limits()
426
def swap_panels(panel):
429
otherpanel = app.get_otherpanel()
430
panel.pos, otherpanel.pos = otherpanel.pos, panel.pos
431
panel.init_curses(panel.pos)
432
otherpanel.init_curses(otherpanel.pos)
435
def same_panels(panel):
436
otherpanel = app.get_otherpanel()
439
vfs.exit(app, otherpanel)
440
otherpanel.init_dir(panel.path)
441
otherpanel.fix_limits()
443
if panel.vfs == 'pan':
444
vfs.pan_copy(app, panel, otherpanel)
446
vfs.copy(app, panel, otherpanel)
447
pvfs, base, vbase = otherpanel.vfs, otherpanel.base, otherpanel.vbase
448
otherpanel.init_dir(base + panel.path.replace(panel.base, ''))
449
otherpanel.fix_limits()
450
otherpanel.vfs, otherpanel.base, otherpanel.vbase = pvfs, base, vbase
454
def select_item(panel):
455
filename = panel.sorted[panel.file_i]
456
if filename == os.pardir:
461
panel.selections.index(filename)
463
panel.selections.append(filename)
465
panel.selections.remove(filename)
470
def select_group(panel):
471
pattern = doEntry('Select group', 'Type pattern', '*')
472
if pattern == None or pattern == '':
474
fullpath = os.path.join(panel.path, pattern)
475
[panel.selections.append(os.path.basename(f)) for f in glob(fullpath)]
478
def deselect_group(panel):
479
pattern = doEntry('Deselect group', 'Type pattern', '*')
480
if pattern == None or pattern == '':
482
fullpath = os.path.join(panel.path, pattern)
483
for f in [os.path.basename(f) for f in glob(fullpath)]:
484
if f in panel.selections:
485
panel.selections.remove(f)
487
def invert_select(panel):
488
selections_old = panel.selections[:]
489
panel.selections = []
490
for f in panel.sorted:
491
if f not in selections_old and f != os.pardir:
492
panel.selections.append(f)
496
def show_size(panel):
497
show_dirs_size(panel)
505
def file_info(panel):
506
do_show_file_info(panel)
509
def do_something_on_file(panel):
510
do_something_on_file(panel)
513
def special_regards(panel):
514
messages.win('Special Regards',
515
' Maite zaitut, Montse\n T\'estimo molt, Montse')
518
def find_grep(panel):
522
def touch_file(panel):
523
newfile = doEntry('Touch file', 'Type file name')
524
if newfile == None or newfile == "":
526
fullfilename = os.path.join(panel.path, newfile)
527
i, err = os.popen4('touch \"%s\"' % fullfilename)
528
err = err.read().split(':')[-1:][0].strip()
531
messages.error('Touch file', '%s: %s' % (newfile, err))
533
panel.refresh_panel(panel)
534
panel.refresh_panel(app.get_otherpanel())
537
def create_link(panel):
538
otherpanel = app.get_otherpanel()
539
if panel.path != otherpanel.path:
540
otherfile = os.path.join(otherpanel.path,
541
otherpanel.sorted[otherpanel.file_i])
543
otherfile = otherpanel.sorted[otherpanel.file_i]
544
newlink, pointto = doDoubleEntry('Create link',
545
'Link name', '', 1, 1,
546
'Pointing to', otherfile, 1, 1)
547
if newlink == None or pointto == None:
551
messages.error('Edit link', 'You must type new link name')
555
messages.error('Edit link', 'You must type pointed file')
557
fullfilename = os.path.join(panel.path, newlink)
558
ans = files.create_link(pointto, fullfilename)
561
messages.error('Edit link', '%s (%s)' % (ans,
562
self.sorted[self.file_i]))
563
panel.refresh_panel(panel)
564
panel.refresh_panel(app.get_otherpanel())
567
def edit_link(panel):
568
fullfilename = os.path.join(panel.path, panel.sorted[panel.file_i])
569
if not os.path.islink(fullfilename):
571
pointto = doEntry('Edit link', 'Link \'%s\' points to' % \
572
panel.sorted[panel.file_i],
573
os.readlink(fullfilename))
574
if pointto == None or pointto == "":
576
if pointto != None and pointto != "" and \
577
pointto != os.readlink(fullfilename):
578
ans = files.modify_link(pointto, fullfilename)
581
messages.error('Edit link', '%s (%s)' % (ans,
582
panel.sorted[self.file_i]))
583
panel.refresh_panel(panel)
584
panel.refresh_panel(app.get_otherpanel())
587
def open_shell(panel):
589
os.system('cd \"%s\"; %s' % (panel.path,
590
app.prefs.progs['shell']))
592
panel.refresh_panel(panel)
593
panel.refresh_panel(app.get_otherpanel())
597
def view_file(panel):
601
def edit_file(panel):
606
otherpanel = app.get_otherpanel()
607
destdir = otherpanel.path + os.sep
608
if len(panel.selections):
609
buf = 'Copy %d items to' % len(panel.selections)
610
destdir = doEntry('Copy', buf, destdir)
613
for f in panel.selections:
614
if not overwrite_all:
615
if app.prefs.confirmations['overwrite']:
616
ans = run_thread(app, 'Copying \'%s\'' % f,
618
panel.path, f, destdir)
619
if type(ans) == type(''):
621
ans2 = messages.confirm_all('Copy', 'Overwrite \'%s\'' % ans, 1)
627
ans = run_thread(app, 'Copying \'%s\'' % f,
634
ans = run_thread(app, 'Copying \'%s\'' % f,
636
panel.path, f, destdir, 0)
638
ans = run_thread(app, 'Copying \'%s\'' % f, files.copy,
639
panel.path, f, destdir, 0)
640
if ans and ans != -100:
643
messages.error('Copy \'%s\'' % f, '%s (%s)' % ans)
644
panel.selections = []
648
filename = panel.sorted[panel.file_i]
649
if filename == os.pardir:
651
buf = 'Copy \'%s\' to' % filename
652
destdir = doEntry('Copy', buf, destdir)
654
if app.prefs.confirmations['overwrite']:
655
ans = run_thread(app, 'Copying \'%s\'' % filename,
657
panel.path, filename, destdir)
658
if type(ans) == type(''):
660
ans2 = messages.confirm('Copy',
663
if ans2 != 0 and ans2 != -1:
664
ans = run_thread(app, 'Copying \'%s\'' % filename,
666
panel.path, filename, destdir, 0)
670
ans = run_thread(app, 'Copying \'%s\'' % filename,
672
panel.path, filename, destdir, 0)
673
if ans and ans != -100:
676
messages.error('Copy \'%s\'' % filename,
680
panel.refresh_panel(panel)
681
panel.refresh_panel(otherpanel)
685
otherpanel = app.get_otherpanel()
686
destdir = otherpanel.path + os.sep
687
if len(panel.selections):
688
buf = 'Move %d items to' % len(panel.selections)
689
destdir = doEntry('Move', buf, destdir)
692
for f in panel.selections:
693
if not overwrite_all:
694
if app.prefs.confirmations['overwrite']:
695
ans = run_thread(app, 'Moving \'%s\'' % f,
697
panel.path, f, destdir)
698
if type(ans) == type(''):
700
ans2 = messages.confirm_all('Move', 'Overwrite \'%s\'' % ans, 1)
706
ans = run_thread(app, 'Moving \'%s\'' % f,
713
ans = run_thread(app, 'Moving \'%s\'' % f,
715
panel.path, f, destdir, 0)
717
ans = run_thread(app, 'Moving \'%s\'' % f, files.move,
718
panel.path, f, destdir, 0)
719
if ans and ans != -100:
722
messages.error('Move \'%s\'' % f, '%s (%s)' % ans)
723
panel.selections = []
727
filename = panel.sorted[panel.file_i]
728
if filename == os.pardir:
730
buf = 'Move \'%s\' to' % filename
731
destdir = doEntry('Move', buf, destdir)
733
if app.prefs.confirmations['overwrite']:
734
ans = run_thread(app, 'Moving \'%s\'' % filename,
736
panel.path, filename, destdir)
737
if type(ans) == type(''):
739
ans2 = messages.confirm('Move',
742
if ans2 != 0 and ans2 != -1:
743
ans = run_thread(app, 'Moving \'%s\'' % filename,
745
panel.path, filename, destdir, 0)
749
ans = run_thread(app, 'Moving \'%s\'' % filename,
751
panel.path, filename, destdir, 0)
752
if ans and ans != -100:
755
messages.error('Move \'%s\'' % filename,
757
ans = files.move(panel.path, filename, destdir, 0)
760
file_i_old = panel.file_i
761
pvfs, base, vbase = panel.vfs, panel.base, panel.vbase
762
panel.init_dir(panel.path)
763
panel.vfs, panel.base, panel.vbase = pvfs, base, vbase
764
if file_i_old > panel.nfiles:
765
panel.file_i = panel.nfiles
767
panel.file_i = file_i_old
769
panel.refresh_panel(panel)
770
panel.refresh_panel(otherpanel)
774
if len(panel.selections):
775
fs = panel.selections[:]
777
fs = [(panel.sorted[panel.file_i])]
780
if filename == os.pardir:
782
buf = 'Rename \'%s\' to' % filename
783
newname = doEntry('Rename', buf, filename)
785
if app.prefs.confirmations['overwrite']:
786
ans = run_thread(app, 'Renaming \'%s\'' % filename,
788
panel.path, filename, newname)
789
if type(ans) == type(''):
791
ans2 = messages.confirm('Rename',
794
if ans2 != 0 and ans2 != -1:
795
ans = run_thread(app, 'Renaming \'%s\'' % filename,
797
panel.path, filename, newname, 0)
801
ans = run_thread(app, 'Renaming \'%s\'' % filename,
803
panel.path, filename, newname, 0)
804
if ans and ans != -100:
807
messages.error('Rename \'%s\'' % filename,
809
ans = files.move(panel.path, filename, newname, 0)
812
file_i_old = panel.file_i
813
pvfs, base, vbase = panel.vfs, panel.base, panel.vbase
814
panel.init_dir(panel.path)
815
panel.vfs, panel.base, panel.vbase = pvfs, base, vbase
816
if file_i_old > panel.nfiles:
817
panel.file_i = panel.nfiles
819
panel.file_i = file_i_old
821
panel.refresh_panel(panel)
822
panel.refresh_panel(app.get_otherpanel())
826
newdir = doEntry('Make directory', 'Type directory name')
827
if newdir == None or newdir == "":
829
ans = files.mkdir(panel.path, newdir)
833
messages.error('Make directory',
834
'%s (%s)' % (ans, newdir))
836
panel.refresh_panel(panel)
837
panel.refresh_panel(app.get_otherpanel())
841
if len(panel.selections):
843
for f in panel.selections:
846
buf = 'Delete \'%s\'' % f
847
if app.prefs.confirmations['delete'] and not delete_all:
848
ans2 = messages.confirm_all('Delete', buf, 1)
854
ans = run_thread(app, 'Deleting \'%s\'' % f,
855
files.delete, panel.path, f)
859
ans = run_thread(app, 'Deleting \'%s\'' % f,
860
files.delete, panel.path, f)
861
if ans and ans != -100:
864
messages.error('Delete \'%s\'' % f, '%s (%s)' % ans)
867
file_i_old = panel.file_i
868
file_old = panel.sorted[panel.file_i]
869
pvfs, base, vbase = panel.vfs, panel.base, panel.vbase
870
panel.init_dir(panel.path)
871
panel.vfs, panel.base, panel.vbase = pvfs, base, vbase
873
panel.file_i = panel.sorted.index(file_old)
875
panel.file_i = file_i_old
877
filename = panel.sorted[panel.file_i]
878
if filename == os.pardir:
880
if app.prefs.confirmations['delete']:
881
ans2 = messages.confirm('Delete', 'Delete \'%s\'' %
883
if ans2 != 0 and ans2 != -1:
884
ans = run_thread(app, 'Deleting \'%s\'' % filename,
885
files.delete, panel.path, filename)
889
ans = run_thread(app, 'Deleting \'%s\'' % filename,
890
files.delete, panel.path, filename)
891
if ans and ans != -100:
894
messages.error('Delete \'%s\'' % filename, '%s (%s)' % ans)
895
file_i_old = panel.file_i
896
pvfs, base, vbase = panel.vfs, panel.base, panel.vbase
897
panel.init_dir(panel.path)
898
panel.vfs, panel.base, panel.vbase = pvfs, base, vbase
899
if file_i_old > panel.nfiles:
900
panel.file_i = panel.nfiles
902
panel.file_i = file_i_old
904
panel.refresh_panel(app.get_otherpanel())
907
def show_help(panel):
914
cmd = messages.MenuWin('Help Menu', menu).run()
919
docdir = os.path.join(sys.exec_prefix, 'share/doc/lfm')
921
fullfilename = os.path.join(docdir, 'README')
923
fullfilename = os.path.join(docdir, 'README.pyview')
925
fullfilename = os.path.join(docdir, 'NEWS')
927
fullfilename = os.path.join(docdir, 'TODO')
929
fullfilename = os.path.join(docdir, 'ChangeLog')
931
fullfilename = os.path.join(docdir, 'COPYING')
932
os.system('%s \"%s\"' % (app.prefs.progs['pager'], fullfilename))
936
def file_menu(panel):
937
menu = [ '@ Do something on file(s)',
939
'p Change file permissions, owner, group',
940
'g Gzip/gunzip file(s)',
941
'b Bzip2/bunzip2 file(s)',
942
'x Uncompress .tar.gz, .tar.bz2, .tar.Z, .zip',
943
'u Uncompress .tar.gz, etc in other panel',
944
'c Compress directory to .tar.gz',
945
'd Compress directory to .tar.bz2',
946
'z Compress directory to .zip' ]
947
cmd = messages.MenuWin('File Menu', menu).run()
953
do_something_on_file(panel)
955
do_show_file_info(panel)
961
for file in panel.selections:
964
ret = messages.ChangePerms(file, panel.files[file],
966
len(panel.selections)).run()
973
filename = os.path.join(panel.path, file)
974
ans = files.set_perms(filename, ret[0])
977
messages.error('Chmod', '%s (%s)' % (ans, filename))
978
ans = files.set_owner_group(filename, ret[1], ret[2])
981
messages.error('Chown', '%s (%s)' % (ans, filename))
982
panel.selections = []
984
file = panel.sorted[panel.file_i]
985
if file == os.pardir:
988
ret = messages.ChangePerms(file, panel.files[file],
992
filename = os.path.join(panel.path, file)
993
ans = files.set_perms(filename, ret[0])
996
messages.error('Chmod', '%s (%s)' % (ans, filename))
997
ans = files.set_owner_group(filename, ret[1], ret[2])
1000
messages.error('Chown', '%s (%s)' % (ans, filename))
1001
panel.refresh_panel(panel)
1002
panel.refresh_panel(app.get_otherpanel())
1004
compress_uncompress_file(app, panel, 'gzip')
1005
old_file = panel.sorted[panel.file_i]
1006
panel.refresh_panel(panel)
1007
panel.file_i = panel.sorted.index(old_file)
1008
old_file = app.get_otherpanel().sorted[app.get_otherpanel().file_i]
1009
panel.refresh_panel(app.get_otherpanel())
1010
app.get_otherpanel().file_i = app.get_otherpanel().sorted.index(old_file)
1012
compress_uncompress_file(app, panel, 'bzip2')
1013
old_file = panel.sorted[panel.file_i]
1014
panel.refresh_panel(panel)
1015
panel.file_i = panel.sorted.index(old_file)
1016
old_file = app.get_otherpanel().sorted[app.get_otherpanel().file_i]
1017
panel.refresh_panel(app.get_otherpanel())
1018
app.get_otherpanel().file_i = app.get_otherpanel().sorted.index(old_file)
1020
uncompress_dir(app, panel, panel.path)
1021
old_file = panel.sorted[panel.file_i]
1022
panel.refresh_panel(panel)
1023
panel.file_i = panel.sorted.index(old_file)
1024
old_file = app.get_otherpanel().sorted[app.get_otherpanel().file_i]
1025
panel.refresh_panel(app.get_otherpanel())
1026
app.get_otherpanel().file_i = app.get_otherpanel().sorted.index(old_file)
1028
otherpath = app.get_otherpanel().path
1029
uncompress_dir(app, panel, otherpath)
1030
old_file = panel.sorted[panel.file_i]
1031
panel.refresh_panel(panel)
1032
panel.file_i = panel.sorted.index(old_file)
1033
old_file = app.get_otherpanel().sorted[app.get_otherpanel().file_i]
1034
panel.refresh_panel(app.get_otherpanel())
1035
app.get_otherpanel().file_i = app.get_otherpanel().sorted.index(old_file)
1037
compress_dir(app, panel, 'gzip')
1038
old_file = panel.sorted[panel.file_i]
1039
panel.refresh_panel(panel)
1040
panel.file_i = panel.sorted.index(old_file)
1041
old_file = app.get_otherpanel().sorted[app.get_otherpanel().file_i]
1042
panel.refresh_panel(app.get_otherpanel())
1043
app.get_otherpanel().file_i = app.get_otherpanel().sorted.index(old_file)
1045
compress_dir(app, panel, 'bzip2')
1046
old_file = panel.sorted[panel.file_i]
1047
panel.refresh_panel(panel)
1048
panel.file_i = panel.sorted.index(old_file)
1049
old_file = app.get_otherpanel().sorted[app.get_otherpanel().file_i]
1050
panel.refresh_panel(app.get_otherpanel())
1051
app.get_otherpanel().file_i = app.get_otherpanel().sorted.index(old_file)
1053
compress_dir(app, panel, 'zip')
1054
old_file = panel.sorted[panel.file_i]
1055
panel.refresh_panel(panel)
1056
panel.file_i = panel.sorted.index(old_file)
1057
old_file = app.get_otherpanel().sorted[app.get_otherpanel().file_i]
1058
panel.refresh_panel(app.get_otherpanel())
1059
app.get_otherpanel().file_i = app.get_otherpanel().sorted.index(old_file)
1062
def general_menu(panel):
1063
menu = [ '/ Find/grep file(s)',
1064
'# Show directories size',
1067
'f Show filesystems info',
1069
'c Edit configuration',
1070
'a Save configuration' ]
1071
cmd = messages.MenuWin('General Menu', menu).run()
1079
show_dirs_size(panel)
1087
app.panel = not panel_i
1089
t = Tree(panel.path, panel.pos)
1100
os.system('cd \"%s\"; %s' % (panel.path,
1101
app.prefs.progs['shell']))
1103
panel.refresh_panel(panel)
1104
panel.refresh_panel(app.get_otherpanel())
1114
def resize_window(panel):
1120
if app.prefs.confirmations['quit']:
1121
ans = messages.confirm('Last File Manager',
1122
'Quit Last File Manager', 1)
1129
if app.prefs.confirmations['quit']:
1130
ans = messages.confirm('Last File Manager',
1131
'Quit Last File Manager', 1)
1138
##################################################
1140
##################################################
1142
def goto_bookmark(panel, num):
1143
todir = app.prefs.bookmarks[num]
1145
vfs.exit(app, panel)
1146
panel.init_dir(todir)
1151
def show_dirs_size(panel):
1152
if panel.selections:
1153
for f in panel.selections:
1154
if panel.files[f][files.FT_TYPE] != files.FTYPE_DIR and \
1155
panel.files[f][files.FT_TYPE] != files.FTYPE_LNK2DIR:
1157
file = os.path.join(panel.path, f)
1158
res = run_thread(app, 'Showing Directories Size',
1159
files.get_fileinfo, file, 0, 1)
1162
panel.files[f] = res
1165
for f in panel.files.keys():
1168
if panel.files[f][files.FT_TYPE] != files.FTYPE_DIR and \
1169
panel.files[f][files.FT_TYPE] != files.FTYPE_LNK2DIR:
1171
file = os.path.join(panel.path, f)
1172
res = run_thread(app, 'Showing Directories Size',
1173
files.get_fileinfo, file, 0, 1)
1176
panel.files[f] = res
1182
ch = messages.get_a_key('Sorting mode',
1183
'N(o), by (n)ame, by (s)ize, by (d)ate,\nuppercase if reversed order, Ctrl-C to quit')
1184
if ch in [ord('o'), ord('O')]:
1185
app.modes['sort'] = files.SORTTYPE_None
1187
elif ch in [ord('n')]:
1188
app.modes['sort'] = files.SORTTYPE_byName
1190
elif ch in [ord('N')]:
1191
app.modes['sort'] = files.SORTTYPE_byName_rev
1193
elif ch in [ord('s')]:
1194
app.modes['sort'] = files.SORTTYPE_bySize
1196
elif ch in [ord('S')]:
1197
app.modes['sort'] = files.SORTTYPE_bySize_rev
1199
elif ch in [ord('d')]:
1200
app.modes['sort'] = files.SORTTYPE_byDate
1202
elif ch in [ord('D')]:
1203
app.modes['sort'] = files.SORTTYPE_byDate_rev
1205
elif ch == -1: # Ctrl-C
1207
old_filename = panel.sorted[panel.file_i]
1208
old_selections = panel.selections[:]
1209
panel.init_dir(panel.path)
1210
panel.file_i = panel.sorted.index(old_filename)
1211
panel.selections = old_selections
1214
# do special view file
1215
def do_special_view_file(panel):
1216
fullfilename = os.path.join(panel.path, panel.sorted[panel.file_i])
1217
ext = os.path.splitext(fullfilename)[1].lower()[1:]
1218
for typ, exts in app.prefs.filetypes.items():
1220
prog = app.prefs.progs[typ]
1222
messages.error('Can\'t run program',
1223
'Can\'t start %s files, defaulting to view' % typ)
1226
sys.stdout = sys.stderr = '/dev/null'
1228
if app.prefs.options['detach_terminal_at_exec']:
1232
sys.stdout = sys.stderr = '/dev/null'
1234
args.append(fullfilename)
1238
# FIXME: catch errors
1240
os.execvp(args[0], args)
1247
sys.stdout = sys.__stdout__
1248
sys.stderr = sys.__stderr__
1251
# programs inside same terminal as lfm should use:
1252
os.system('%s \"%s\"' % (prog, fullfilename))
1254
sys.stdout = sys.__stdout__
1255
sys.stderr = sys.__stderr__
1259
panel.refresh_panel(panel)
1260
panel.refresh_panel(app.get_otherpanel())
1264
def do_view_file(panel):
1265
fullfilename = os.path.join(panel.path, panel.sorted[panel.file_i])
1267
os.system('%s \"%s\"' % (app.prefs.progs['pager'], fullfilename))
1272
def do_edit_file(panel):
1274
fullfilename = os.path.join(panel.path, panel.sorted[panel.file_i])
1275
os.system('%s \"%s\"' % (app.prefs.progs['editor'], fullfilename))
1277
panel.refresh_panel(panel)
1278
panel.refresh_panel(app.get_otherpanel())
1282
def do_do_execute_file(path, cmd):
1283
i, a = os.popen4('cd \"%s\"; \"%s\"; echo ZZENDZZ' % (path, cmd))
1286
buf = a.readline()[:-1]
1287
if buf == 'ZZENDZZ':
1290
output += buf + '\n'
1291
i.close(); a.close()
1295
def do_execute_file(panel):
1296
fullfilename = os.path.join(panel.path, panel.sorted[panel.file_i])
1297
parms = doEntry('Execute file', 'Enter arguments')
1301
cmd = '%s' % fullfilename
1303
cmd = '%s %s' % (fullfilename, parms)
1305
err = run_thread(app, 'Executing \"%s\"' % cmd,
1306
do_do_execute_file, panel.path, cmd)
1307
if err and err != -100:
1308
if app.prefs.options['show_output_after_exec']:
1310
for panel in app.panels:
1312
if messages.confirm('Executing file(s)', 'Show output'):
1313
lst = [(l, 2) for l in err.split('\n')]
1314
pyview.InternalView('Output of \"%s\"' % cmd,
1315
lst, center = 0).run()
1317
panel.refresh_panel(panel)
1318
panel.refresh_panel(app.get_otherpanel())
1321
# do something on file
1322
### do_something_on_file does not have to run inside run_thread, either capture
1323
### the output because it makes not possible to exec commands such as 'less', etc.
1324
# def do_do_something_on_file(panel, cmd, filename):
1325
# i, a = os.popen4('cd \"%s\"; %s \"%s\"; echo ZZENDZZ' %
1326
# (panel.path, cmd, filename))
1329
# buf = a.readline()[:-1]
1330
# if buf == 'ZZENDZZ':
1333
# output += buf + '\n'
1334
# i.close(); a.close()
1338
# def do_something_on_file(panel):
1339
# cmd = doEntry('Do something on file(s)', 'Enter command')
1342
# if len(panel.selections):
1343
# for f in panel.selections:
1344
# err = run_thread('Executing \"%s %s\"' % (cmd, f),
1345
# do_do_something_on_file, panel, cmd, f)
1346
# if err and err != -100:
1347
# if app.prefs.options['show_output_after_exec']:
1348
# curses.curs_set(0)
1349
# for panel in app.panels:
1351
# if messages.confirm('Do something on file(s)',
1353
# lst = [(l, 2) for l in err.split('\n')]
1354
# pyview.InternalView('Output of \"%s %s\"' %
1356
# lst, center = 0).run()
1357
# panel.selections = []
1359
# filename = panel.sorted[panel.file_i]
1360
# err = run_thread('Executing \"%s %s\"' % (cmd, filename),
1361
# do_do_something_on_file, panel, cmd, filename)
1362
# if err and err != -100:
1363
# if app.prefs.options['show_output_after_exec']:
1364
# curses.curs_set(0)
1365
# for panel in app.panels:
1367
# if messages.confirm('Do something on file(s)', 'Show output'):
1368
# lst = [(l, 2) for l in err.split('\n')]
1369
# pyview.InternalView('Output of \"%s %s\"' %
1371
# lst, center = 0).run()
1372
# curses.curs_set(0)
1373
# panel.refresh_panel(panel)
1374
# panel.refresh_panel(app.get_otherpanel())
1376
def do_something_on_file(panel):
1377
cmd = doEntry('Do something on file(s)', 'Enter command')
1380
if len(panel.selections):
1381
for f in panel.selections:
1382
os.system('cd \"%s\"; %s \"%s\"' % (panel.path, cmd, f))
1383
panel.selections = []
1385
os.system('cd \"%s\"; %s \"%s\"' %
1386
(panel.path, cmd, panel.sorted[panel.file_i]))
1388
panel.refresh_panel(panel)
1389
panel.refresh_panel(app.get_otherpanel())
1393
def do_show_file_info(panel):
1394
def show_info(panel, file):
1396
from time import ctime
1398
fullfilename = os.path.join(panel.path, file)
1399
file_data = panel.files[file]
1400
file_data2 = os.lstat(fullfilename)
1402
user = os.environ['USER']
1403
username = files.get_user_fullname(user)
1404
so, host, ver, tmp, arch = os.uname()
1405
buf.append(('%s v%s executed by %s' % (LFM_NAME, VERSION, username), 5))
1406
buf.append(('<%s@%s> on a %s %s [%s]' % (user, host, so, ver, arch), 5))
1408
fileinfo = os.popen('file \"%s\"' % \
1409
fullfilename).read().split(':')[1].strip()
1410
buf.append(('%s: %s (%s)' % (files.FILETYPES[file_data[0]][1], file,
1415
path = vfs.join(app, panel) + ' [%s]' % panel.base
1416
buf.append(('Path: %s' % path[-(curses.COLS-8):], 6))
1417
buf.append(('Size: %s bytes' % file_data[files.FT_SIZE], 6))
1418
buf.append(('Mode: %s (%4.4o)' % \
1419
(files.perms2str(file_data[files.FT_PERMS]),
1420
file_data[files.FT_PERMS]), 6))
1421
buf.append(('Links: %s' % file_data2[stat.ST_NLINK], 6))
1422
buf.append(('User ID: %s (%s) / Group ID: %s (%s)' % \
1423
(file_data[files.FT_OWNER], file_data2[stat.ST_UID],
1424
file_data[files.FT_GROUP], file_data2[stat.ST_GID]), 6))
1425
buf.append(('Last access: %s' % ctime(file_data2[stat.ST_ATIME]), 6))
1426
buf.append(('Last modification: %s' % ctime(file_data2[stat.ST_MTIME]), 6))
1427
buf.append(('Last change: %s' % ctime(file_data2[stat.ST_CTIME]), 6))
1428
buf.append(('Location: %d, %d / Inode: #%X (%Xh:%Xh)' % \
1429
((file_data2[stat.ST_DEV] >> 8) & 0x00FF,
1430
file_data2[stat.ST_DEV] & 0x00FF,
1431
file_data2[stat.ST_INO], file_data2[stat.ST_DEV],
1432
file_data2[stat.ST_INO]), 6))
1433
fss = files.get_fs_info()
1434
fs = ['/dev', '0', '0', '0', '0%', '/', 'unknown']
1436
if fullfilename.find(e[5]) != -1 and (len(e[5]) > len(fs[5]) or e[5] == os.sep):
1438
buf.append(('File system: %s on %s (%s) %d%% free' % \
1439
(fs[0], fs[5], fs[6], 100 - int(fs[4][:-1])), 6))
1440
pyview.InternalView('Information about \'%s\'' % file, buf).run()
1442
if panel.selections:
1443
for f in panel.selections:
1445
panel.selections = []
1447
show_info(panel, panel.sorted[panel.file_i])
1450
# do show filesystems info
1451
def do_show_fs_info():
1452
"""Show file systems info"""
1454
fs = files.get_fs_info()
1455
if type(fs) != type([]):
1457
messages.error('Show filesystems info', fs)
1461
buf.append(('Filesystem FS type Total Mb Used Avail. Use% Mount point', 6))
1464
buf.append(('%-15s %-10s %7s %7s %7s %4s %s' % \
1465
(l[0], l[6], l[1], l[2], l[3], l[4], l[5]), 2))
1466
texts = [l[0] for l in buf]
1467
buf[1] = ('-' * len(max(texts)), 6)
1468
pyview.InternalView('Show filesystems info', buf).run()
1472
def findgrep(panel):
1473
fs, pat = doDoubleEntry('Find files', 'Filename', '*', 1, 1,
1474
'Content', '', 1, 0)
1475
if fs == None or fs == '':
1477
path = os.path.dirname(fs)
1478
fs = os.path.basename(fs)
1479
if path == None or path == '':
1481
if path[0] != os.sep:
1482
path = os.path.join(panel.path, path)
1484
m = run_thread(app, 'Searching for \'%s\' in \"%s\" files' % (pat, fs),
1486
path, fs, pat, app.prefs.progs['find'],
1487
app.prefs.progs['egrep'])
1490
messages.error('Find/Grep', 'No files found')
1496
messages.error('Find/Grep', 'Error while creating pipe')
1499
m = run_thread(app, 'Searching for \"%s\" files' % fs, files.find,
1500
path, fs, app.prefs.progs['find'])
1503
messages.error('Find', 'No files found')
1509
messages.error('Find', 'Error while creating pipe')
1513
while not find_quit:
1514
cmd, par = messages.FindfilesWin(m, par).run()
1518
line = int(par.split(':')[0])
1521
f = os.path.join(path, par)
1523
f = os.path.join(path, par[par.find(':')+1:])
1526
f = os.path.join(path, par)
1527
if os.path.isdir(f):
1531
todir = os.path.dirname(f)
1532
tofile = os.path.basename(f)
1533
if cmd == 0: # goto file
1534
pvfs, base, vbase = panel.vfs, panel.base, panel.vbase
1535
panel.init_dir(todir)
1536
panel.vfs, panel.base, panel.vbase = pvfs, base, vbase
1538
panel.file_i = panel.sorted.index(tofile)
1541
elif cmd == 1: # panelize
1545
f = f[f.find(':')+1:]
1552
vfs.pan_init(app, panel, fs)
1554
elif cmd == 2: # view
1558
os.system('%s +%d \"%s\"' %
1559
(app.prefs.progs['pager'], line, f))
1562
messages.error('View', 'it\'s a directory',
1564
elif cmd == 3: # edit
1568
os.system('%s +%d \"%s\"' %
1569
(app.prefs.progs['editor'], line, f))
1571
os.system('%s \"%s\"' %
1572
(app.prefs.progs['editor'], f))
1574
panel.refresh_panel(panel)
1575
panel.refresh_panel(app.get_otherpanel())
1577
messages.error('Edit', 'it\'s a directory',
1579
elif cmd == 4: # do something on file
1580
cmd2 = doEntry('Do something on file',
1584
os.system('%s \"%s\"' % (cmd2, f))
1586
panel.refresh_panel(panel)
1587
panel.refresh_panel(app.get_otherpanel())
1597
def doEntry(title, help, path = '', with_historic = 1, with_complete = 1):
1598
panelpath = app.panels[app.panel].path
1600
path = messages.Entry(title, help, path, with_historic, with_complete,
1602
if type(path) != type([]):
1609
def doDoubleEntry(title, help1, path1 = '', with_historic1 = 1, with_complete1 = 1,
1610
help2 = '', path2 = '', with_historic2 = 1, with_complete2 = 1):
1612
panelpath1 = app.panels[app.panel].path
1613
panelpath2 = app.panels[app.panel].path
1615
path = messages.DoubleEntry(title, help1, path1, with_historic1,
1616
with_complete1, panelpath1,
1617
help2, path2, with_historic2,
1618
with_complete2, panelpath2,
1620
if type(path) != type([]):
1624
active_entry = path.pop()
1629
##################################################
1631
##################################################
1635
def __init__(self, path = os.sep, panelpos = 0):
1636
if not os.path.exists(path):
1638
self.__init_curses(panelpos)
1639
if path[-1] == os.sep and path != os.sep:
1642
self.tree = self.get_tree()
1643
self.pos = self.__get_curpos()
1646
def __get_dirs(self, path):
1647
"""return a list of dirs in path"""
1651
for d in os.listdir(path):
1652
if os.path.isdir(os.path.join(path, d)):
1660
def __get_graph(self, path):
1661
"""return 2 dicts with tree structure"""
1667
if path == os.sep and tree_dir.has_key(os.sep):
1669
tree_dir[path] = (self.__get_dirs(path), expanded)
1670
expanded = os.path.basename(path)
1671
path = os.path.dirname(path)
1672
dir_keys = tree_dir.keys()
1678
return tree_n, tree_dir
1681
def __get_node(self, i, tn, td, base):
1686
dirs, expanded_node = td[node]
1687
if not expanded_node:
1690
if d == expanded_node:
1691
lst2.append([d, i, os.path.join(base, d)])
1692
lst3 = self.__get_node(i+1, tn, td, os.path.join(base, d))
1696
lst2.append([d, i, os.path.join(base, d)])
1701
"""return list with tree structure"""
1703
tn, td = self.__get_graph(self.path)
1704
tree = [[os.sep, -1, os.sep]]
1705
tree.extend(self.__get_node(0, tn, td, os.sep))
1709
def __get_curpos(self):
1710
"""get position of current dir"""
1712
for i in range(len(self.tree)):
1713
if self.path == self.tree[i][2]:
1719
def regenerate_tree(self, newpos):
1720
"""regenerate tree when changing to a new directory"""
1722
self.path = self.tree[newpos][2]
1723
self.tree = self.get_tree()
1724
self.pos = self.__get_curpos()
1727
def show_tree(self, a = 0, z = -1):
1728
"""show an ascii representation of the tree. Not used in lfm"""
1730
if z > len(self.tree) or z == -1:
1732
for i in range(a, z):
1733
name, depth, fullname = self.tree[i]
1734
if fullname == self.path:
1739
print ' | ' * depth + ' +- ' + name
1743
def __init_curses(self, pos):
1744
"""initialize curses stuff"""
1746
if pos == 0: # not visible panel
1747
self.dims = (curses.LINES-2, 0, 0, 0) # h, w, y, x
1749
elif pos == 1: # left panel -> right
1750
self.dims = (curses.LINES-2, int(curses.COLS/2), 1, int(curses.COLS/2))
1751
elif pos == 2: # right panel -> left
1752
self.dims = (curses.LINES-2, int(curses.COLS/2), 1, 0)
1753
else: # full panel -> right
1754
self.dims = (curses.LINES-2, int(curses.COLS/2), 1, int(curses.COLS/2))
1756
self.win_tree = curses.newwin(self.dims[0], self.dims[1], self.dims[2], self.dims[3])
1757
except curses.error:
1758
print 'Can\'t create tree window'
1760
self.win_tree.keypad(1)
1761
if curses.has_colors():
1762
self.win_tree.attrset(curses.color_pair(2))
1763
self.win_tree.bkgdset(curses.color_pair(2))
1767
"""show tree panel"""
1769
self.win_tree.erase()
1770
h = curses.LINES - 4
1773
self.win_tree.attrset(curses.color_pair(5))
1775
self.win_tree.addstr(0, 2, ' Tree ', curses.color_pair(6) | curses.A_BOLD)
1777
self.win_tree.attrset(curses.color_pair(2))
1779
a, z = int(self.pos/h) * h, (int(self.pos/h) + 1) * h
1785
for i in range(a, z):
1787
name, depth, fullname = self.tree[i]
1789
self.win_tree.addstr(j, 1, ' ')
1791
self.win_tree.move(j, 1)
1792
for kk in range(depth):
1793
self.win_tree.addstr(' ')
1794
self.win_tree.addch(curses.ACS_VLINE)
1795
self.win_tree.addstr(' ')
1796
self.win_tree.addstr(' ')
1798
self.win_tree.addch(curses.ACS_LLCORNER)
1799
elif depth > self.tree[i+1][1]:
1800
self.win_tree.addch(curses.ACS_LLCORNER)
1802
self.win_tree.addch(curses.ACS_LTEE)
1803
self.win_tree.addch(curses.ACS_HLINE)
1804
self.win_tree.addstr(' ')
1805
w = int(curses.COLS / 2) - 2
1807
if fullname == self.path:
1808
self.win_tree.addstr(name[:w-wd-3], curses.color_pair(3))
1809
child_dirs = self.__get_dirs(self.path)
1810
if len(child_dirs) > 0:
1811
self.win_tree.addstr(' ')
1812
self.win_tree.addch(curses.ACS_HLINE)
1813
self.win_tree.addch(curses.ACS_RARROW)
1815
self.win_tree.addstr(name[:w-wd])
1821
aa = int(self.pos / h) * h
1822
y0 = int(aa * h / n)
1830
self.win_tree.attrset(curses.color_pair(5))
1831
self.win_tree.vline(y0 + 2, int(curses.COLS/2) - 1, curses.ACS_CKBOARD, nn)
1833
self.win_tree.vline(1, int(curses.COLS/2) - 1, '^', 1)
1834
if nn == 1 and (y0 + 2 == 2):
1835
self.win_tree.vline(3, int(curses.COLS/2) - 1, curses.ACS_CKBOARD, nn)
1836
if n - 1 > a + h - 1:
1837
self.win_tree.vline(h, int(curses.COLS/2) - 1, 'v', 1)
1838
if nn == 1 and (y0 + 2 == h + 1):
1839
self.win_tree.vline(h, int(curses.COLS/2) - 1, curses.ACS_CKBOARD, nn)
1841
app.win_status.erase()
1842
wp = curses.COLS - 8
1843
if len(self.path) > wp:
1844
path = self.path[:int(wp/2) -1] + '~' + self.path[-int(wp/2):]
1847
app.win_status.addstr(' Path: %s' % path)
1848
app.win_status.refresh()
1857
ch = self.win_tree.getch()
1859
# to avoid extra chars input
1862
ch = self.win_tree.getch()
1863
ch = self.win_tree.getch()
1866
if ch in [ord('p'), ord('P'), curses.KEY_UP]:
1869
if self.tree[self.pos][1] != self.tree[self.pos-1][1]:
1871
newpos = self.pos - 1
1873
elif ch in [ord('n'), ord('N'), curses.KEY_DOWN]:
1874
if self.pos == len(self.tree) - 1:
1876
if self.tree[self.pos][1] != self.tree[self.pos+1][1]:
1878
newpos = self.pos + 1
1880
elif ch in [curses.KEY_PPAGE, curses.KEY_BACKSPACE,
1881
0x08, 0x10]: # BackSpace, Ctrl-P
1882
depth = self.tree[self.pos][1]
1883
if self.pos - (curses.LINES-4) >= 0:
1884
if depth == self.tree[self.pos - (curses.LINES-4)][1]:
1885
newpos = self.pos - (curses.LINES-4)
1891
if self.tree[newpos-1][1] != depth:
1899
if self.tree[newpos-1][1] != depth:
1903
elif ch in [curses.KEY_NPAGE, ord(' '), 0x0E]: # Ctrl-N
1904
depth = self.tree[self.pos][1]
1905
if self.pos + (curses.LINES-4) <= len(self.tree) - 1:
1906
if depth == self.tree[self.pos + (curses.LINES-4)][1]:
1907
newpos = self.pos + (curses.LINES-4)
1911
if newpos + 1 == len(self.tree):
1913
if self.tree[newpos+1][1] != depth:
1919
if newpos + 1 == len(self.tree):
1921
if self.tree[newpos+1][1] != depth:
1925
elif (ch in [curses.KEY_HOME, 0x001,0x16A ]) or \
1926
(chext == 1) and (ch == 72): # home
1929
elif (ch in [curses.KEY_END, 0x005, 0x181]) or \
1930
(chext == 1) and (ch == 70): # end
1931
newpos = len(self.tree) - 1
1933
elif ch in [curses.KEY_LEFT]:
1936
newdepth = self.tree[self.pos][1] - 1
1937
for i in range(self.pos-1, -1, -1):
1938
if self.tree[i][1] == newdepth:
1942
elif ch in [curses.KEY_RIGHT]:
1943
child_dirs = self.__get_dirs(self.path)
1944
if len(child_dirs) > 0:
1945
self.path = os.path.join(self.path, child_dirs[0])
1946
self.tree = self.get_tree()
1947
self.pos = self.__get_curpos()
1950
elif ch in [10, 13]:
1953
elif ch in [ord('q'), ord('Q'), curses.KEY_F10, 0x03]: # Ctrl-C
1961
self.regenerate_tree(newpos)