-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
176 lines (174 loc) · 5.62 KB
/
index.js
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
//Copyright WojtekGame 2023 - npm: code-gui, github: WojtekCodesToday/code-gui
import * as fs from 'fs/promises'
import colors from 'colors';
function __e(err) {
console.error("(err) " + err);
}
/**
* # loadDir
* An code-gui function allowing to display folder contents in the terminal.
*
* Example:
* ```
* import loadDir from "code-gui";
* loadDir("C:/", {"type":"text"})
* ```
* ## History
* Added by [@WojtekCodesToday](github.com/WojtekCodesToday) on [GitHub](github.com)
*/
async function loadDir(dir, set) {
let
gdir = colors.yellow.bold(" " + dir),
rest, name = "";
rest = ""
for (let c = 0; c < gdir.length; c++) {
switch (set.style) {
case "emoji":
rest = `${rest}`;
break;
case "emoji-hacker":
rest = `${rest}`;
break;
case "text-hacker":
rest = `${rest}1`;
break;
case "text":
rest = `${rest}-`;
break;
case "text-2":
rest = `${rest}─`;
break;
case "keyboard":
rest = `${rest}I`;
break;
//default:
// break;
}
} try {
var folder = await fs.opendir(dir);
switch (set.style) {
case "emoji":
console.log(`⏹️⬅️⬅️ 🔍${gdir}`);
break;
case "emoji-hacker":
console.log(`#️⃣0️⃣1️⃣ 🔍${gdir}`);
break;
case "text":
console.log(`#--${gdir}`);
break;
case "text-2":
console.log(`┌──${gdir}`);
break;
case "keyboard":
console.log(`OIII${gdir}`);
break;
case "text-hacker":
console.log(`#0110${gdir}`);
break;
//default:
// break;
}
let dircount = 0,
filecount = 0,
nullcount = 0;
function __frame() {
let about = "";
if (e.isFile() === false) {
dircount = dircount + 1;
about = colors.gray(` // <Directory> Directory count: ${dircount}`);
} else if (e.isDirectory() === true) {
filecount = filecount + 1
about = colors.gray(` // <File> File count: ${filecount}`);
} else {
nullcount = nullcount + 1
about = colors.gray(` // <NULL> Null count: ${nullcount}`);
}
if (set.limitNames === true) {
if (name.length > 20) {
let abc = "";
for (let integr = 0; integr < 20; integr++) {
abc = abc + name[integr];
}
name = `${abc}...`;
}
}
switch (set.style) {
case "emoji":
console.log(`⬇️ ${name}${about}`);
break;
case "emoji-hacker":
var z = Math.floor(Math.random() * 2);
switch (z) {
case 1:
console.log(`0️⃣ ${name}${about}`);
break;
default:
console.log(`1️⃣${name}${about}`);
break;
}
break;
case "text":
console.log(`| ${name}${about}`);
break;
case "text-2":
console.log(`│ ${name}${about}`);
break;
case "keyboard":
console.log(`l ${name}${about}`);
break;
case "text-hacker":
var z = Math.floor(Math.random() * 2);
switch (z) {
case 1:
console.log(`0️ ${name}${about}`);
break;
default:
console.log(`1️ ${name}${about}`);
break;
}
break;
default:
break;
}
}
if (set.showItems === undefined) {
for await (var e of folder) {
name = e.name;
__frame()
}
} else {
var i = 0
for await (var e of folder) {
if (i < set.showItems) {
__frame()
}
i = i + 1
}
}
switch (set.style) {
case "emoji":
console.log(`⏹️➡️➡️${rest}`);
break;
case "emoji-hacker":
console.log(`#️⃣1️⃣0️⃣${rest}`);
break;
case "text":
console.log(`#--${rest}`);
break;
case "text-2":
console.log(`└──${rest}`)
break;
case "keyboard":
console.log(`OII${rest}`)
break;
case "text-hacker":
console.log(`#10${rest}`)
break;
//default:
// break;
}
} catch (err) {
__e(err);
}
}
export default loadDir