-
Notifications
You must be signed in to change notification settings - Fork 0
/
depend.py
189 lines (177 loc) · 6.17 KB
/
depend.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# import dependencies
import curses,time,os
import getpass,sys,signal
import shutil
from distutils.dir_util import copy_tree
from datetime import datetime
# current directory
os.chdir(".")
menu = os.listdir()
menu.sort()
# Some global Strings
file = "It is a File"
copy = " Selected File: "
search = "Ctrl + S to search: "
options = " c : copy, m : move, k : create file, g : create folder, v : paste"
def copy_cut(stdscr,fold,folder,folder_to_be_copied,h,w,path):
"""
This function copies a file or a folder to current folder and updates the screen with current directory contents
stdscr : standard screen
fold : is it folder or file
folder : name of folder/file
folder_to_be_copied : path of folder to be copied
h,w : screen
path : path of current directory
"""
if not fold:
shutil.copy(folder_to_be_copied, os.getcwd()+"/"+folder)
else:
copy_tree(folder_to_be_copied, os.getcwd()+"/"+folder)
option(stdscr,h,w)
stdscr.addstr(h-1,0,copy,curses.color_pair(15))
menu = os.listdir()
menu.sort()
listings = []
for i in menu:
listings.append(os.path.isdir(i))
cur_row = menu.index(folder)+1
print_menu(stdscr,listings,cur_row,folder,menu)
l = len(menu)
stdscr.addstr(0,0," "*w,curses.color_pair(5))
stdscr.addstr(0,w//2-len(path)//2,path,curses.color_pair(5))
a = 0
return menu,listings,l,cur_row,a
def empty_right(stdscr, full_screen_mode=False):
"""
This function creates room in the middle panel
stdscr : standard screen
"""
p, w = stdscr.getmaxyx()
stdscr.attron(curses.color_pair(3))
for i in range(1, p - 2):
if full_screen_mode:
stdscr.addstr(i, 0, " " * w)
stdscr.refresh()
else:
stdscr.addstr(i, w // 5+1, " " * (4 * w // 5 - 37))
stdscr.refresh()
def print_folder(stdscr,row):
"""
print the content of the folder on which the cursor is.
"""
try:
h = list(os.listdir(row))
p,w = stdscr.getmaxyx()
per10screen = w//5
empty_right(stdscr)
for i in range(p-3):
stdscr.attron(curses.color_pair(3))
if len(h[i])<per10screen:
l = h[i]+" "*(per10screen-len(row))
else:
l = h[i][:per10screen]
x = w//5+2
y = i+1
stdscr.addstr(y,x,l)
except:
pass
def print_menu(stdscr,listings,n,this,menu):
"""
print the main menu/current directory content on left panel
this : name of file/folder on which cursor is.
menu : current directory
"""
h,w = stdscr.getmaxyx()
per10screen = w//5
per = " "*(w//5+1)
for i in range(1,h-2):
stdscr.attron(curses.color_pair(2))
stdscr.addstr(i,0,per)
stdscr.attroff(curses.color_pair(2))
curses.init_pair(4, curses.COLOR_WHITE, 34)
curses.init_pair(5, 3,17)
stdscr.attron(curses.color_pair(5))
stdscr.addstr(0,0," "*w)
if listings[0]:
print_folder(stdscr,menu[0])
else:
empty_right(stdscr)
stdscr.addstr(h//2,w//2-len(file)//2,file,curses.color_pair(3))
stdscr.attron(curses.color_pair(4))
stdscr.addstr(h-2,0," "*(w-1))
stdscr.addstr(h-2,w//2-len(menu[0])//2,menu[0])
for idx, row in enumerate(menu):
if (idx==0 and n==0) or this==row:
stdscr.attron(curses.color_pair(1))
if len(row)<per10screen:
i = row+" "*(per10screen-len(row))
else:
i = row[:per10screen]
x = 1
y = idx+1
stdscr.addstr(y,x,i)
stdscr.attroff(curses.color_pair(1))
else:
if idx>=h-3:
break
stdscr.attron(curses.color_pair(2))
if len(row)<per10screen:
i = row+" "*(per10screen-len(row))
else:
i = row[:per10screen]
x = 1
y = idx+1
stdscr.addstr(y,x,i)
stdscr.refresh()
def scrolldown(stdscr,cur_row,menu):
"""
handle scrolling in left panel
"""
h,w = stdscr.getmaxyx()
per10screen = w//5
stdscr.attron(curses.color_pair(2))
for idx in range(cur_row-h+3,cur_row):
if len(menu[idx])<per10screen:
i = menu[idx]+" "*(per10screen-len(menu[idx]))
else:
i = menu[idx][:per10screen]
if idx==cur_row-1:
stdscr.attron(curses.color_pair(1))
if len(menu[idx])<per10screen:
i = menu[idx]+" "*(per10screen-len(menu[idx]))
else:
i = menu[idx][:per10screen]
x = 1
y = idx+1-cur_row+h-3
stdscr.addstr(y,x,i)
stdscr.attroff(curses.color_pair(1))
stdscr.attron(curses.color_pair(4))
stdscr.addstr(h-2,0," "*(w-1))
stdscr.addstr(h-2,w//2-len(menu[cur_row-1])//2,menu[cur_row-1])
else:
x = 1
y = idx+1-cur_row+h-3
stdscr.addstr(y,x,i)
stdscr.refresh()
# relative to bottom left, print options
def option(stdscr,h,w):
if w<100:
return
x = w-76-2*w//5
curses.init_pair(70,curses.COLOR_WHITE,23)
stdscr.addstr(h-1,0," "*(w-1),curses.color_pair(15))
stdscr.addstr(h-1,2*w//5," "*(3*w//5),curses.color_pair(15))
stdscr.addstr(h-1,2*w//5+x," c ",curses.color_pair(70))
stdscr.addstr(h-1,2*w//5+x+3,"Copy",curses.color_pair(5))
stdscr.addstr(h-1,2*w//5+x+7," m ",curses.color_pair(70))
stdscr.addstr(h-1,2*w//5+x+10,"Move",curses.color_pair(5))
stdscr.addstr(h-1,2*w//5+x+14," k ",curses.color_pair(70))
stdscr.addstr(h-1,2*w//5+x+17,"File",curses.color_pair(5))
stdscr.addstr(h-1,2*w//5+x+21," g ",curses.color_pair(70))
stdscr.addstr(h-1,2*w//5+x+24,"Folder",curses.color_pair(5))
stdscr.addstr(h-1,2*w//5+x+30," d+r ",curses.color_pair(70))
stdscr.addstr(h-1,2*w//5+x+35,"Delete",curses.color_pair(5))
stdscr.addstr(h-1,2*w//5+x+41," ctrl+a ",curses.color_pair(70))
stdscr.addstr(h-1,2*w//5+x+49,"Search",curses.color_pair(5))
stdscr.addstr(h-1,2*w//5+x+55," shift+tab ",curses.color_pair(70))
stdscr.addstr(h-1,2*w//5+x+66,"Terminal",curses.color_pair(5))