cli-browser 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +309 -0
- package/bin/cli-browser.js +8 -0
- package/package.json +50 -0
- package/src/bangs.js +53 -0
- package/src/bookmarks.js +45 -0
- package/src/browser.js +1277 -0
- package/src/config.js +51 -0
- package/src/developer.js +246 -0
- package/src/download.js +80 -0
- package/src/history.js +58 -0
- package/src/index.js +45 -0
- package/src/network.js +56 -0
- package/src/plugins.js +74 -0
- package/src/renderer.js +259 -0
- package/src/search.js +113 -0
- package/src/sessions.js +37 -0
- package/src/stats.js +66 -0
- package/src/tabs.js +147 -0
- package/src/themes.js +137 -0
- package/src/ui.js +202 -0
package/src/themes.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import config from './config.js';
|
|
3
|
+
|
|
4
|
+
const THEMES = {
|
|
5
|
+
dark: {
|
|
6
|
+
primary: 'cyan',
|
|
7
|
+
secondary: 'white',
|
|
8
|
+
accent: 'yellow',
|
|
9
|
+
success: 'green',
|
|
10
|
+
error: 'red',
|
|
11
|
+
warning: 'yellow',
|
|
12
|
+
info: 'blue',
|
|
13
|
+
muted: 'gray',
|
|
14
|
+
link: 'cyan',
|
|
15
|
+
title: 'greenBright',
|
|
16
|
+
url: 'gray',
|
|
17
|
+
border: 'white',
|
|
18
|
+
highlight: 'yellowBright',
|
|
19
|
+
bg: null,
|
|
20
|
+
headerBg: 'bgBlue',
|
|
21
|
+
},
|
|
22
|
+
hacker: {
|
|
23
|
+
primary: 'green',
|
|
24
|
+
secondary: 'greenBright',
|
|
25
|
+
accent: 'green',
|
|
26
|
+
success: 'greenBright',
|
|
27
|
+
error: 'red',
|
|
28
|
+
warning: 'yellow',
|
|
29
|
+
info: 'green',
|
|
30
|
+
muted: 'green',
|
|
31
|
+
link: 'greenBright',
|
|
32
|
+
title: 'greenBright',
|
|
33
|
+
url: 'green',
|
|
34
|
+
border: 'green',
|
|
35
|
+
highlight: 'greenBright',
|
|
36
|
+
bg: null,
|
|
37
|
+
headerBg: 'bgGreen',
|
|
38
|
+
},
|
|
39
|
+
minimal: {
|
|
40
|
+
primary: 'white',
|
|
41
|
+
secondary: 'gray',
|
|
42
|
+
accent: 'white',
|
|
43
|
+
success: 'white',
|
|
44
|
+
error: 'red',
|
|
45
|
+
warning: 'yellow',
|
|
46
|
+
info: 'white',
|
|
47
|
+
muted: 'gray',
|
|
48
|
+
link: 'white',
|
|
49
|
+
title: 'white',
|
|
50
|
+
url: 'gray',
|
|
51
|
+
border: 'gray',
|
|
52
|
+
highlight: 'whiteBright',
|
|
53
|
+
bg: null,
|
|
54
|
+
headerBg: 'bgGray',
|
|
55
|
+
},
|
|
56
|
+
ocean: {
|
|
57
|
+
primary: 'blueBright',
|
|
58
|
+
secondary: 'cyanBright',
|
|
59
|
+
accent: 'magentaBright',
|
|
60
|
+
success: 'greenBright',
|
|
61
|
+
error: 'redBright',
|
|
62
|
+
warning: 'yellowBright',
|
|
63
|
+
info: 'blueBright',
|
|
64
|
+
muted: 'gray',
|
|
65
|
+
link: 'cyanBright',
|
|
66
|
+
title: 'blueBright',
|
|
67
|
+
url: 'cyan',
|
|
68
|
+
border: 'blue',
|
|
69
|
+
highlight: 'magentaBright',
|
|
70
|
+
bg: null,
|
|
71
|
+
headerBg: 'bgBlue',
|
|
72
|
+
},
|
|
73
|
+
sunset: {
|
|
74
|
+
primary: 'redBright',
|
|
75
|
+
secondary: 'yellowBright',
|
|
76
|
+
accent: 'magenta',
|
|
77
|
+
success: 'green',
|
|
78
|
+
error: 'red',
|
|
79
|
+
warning: 'yellow',
|
|
80
|
+
info: 'magenta',
|
|
81
|
+
muted: 'gray',
|
|
82
|
+
link: 'yellowBright',
|
|
83
|
+
title: 'redBright',
|
|
84
|
+
url: 'yellow',
|
|
85
|
+
border: 'red',
|
|
86
|
+
highlight: 'magentaBright',
|
|
87
|
+
bg: null,
|
|
88
|
+
headerBg: 'bgRed',
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
class ThemeManager {
|
|
93
|
+
constructor() {
|
|
94
|
+
this.currentTheme = config.get('theme') || 'dark';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
getTheme() {
|
|
98
|
+
return THEMES[this.currentTheme] || THEMES.dark;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
setTheme(name) {
|
|
102
|
+
if (THEMES[name]) {
|
|
103
|
+
this.currentTheme = name;
|
|
104
|
+
config.set('theme', name);
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
listThemes() {
|
|
111
|
+
return Object.keys(THEMES);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
c(colorName) {
|
|
115
|
+
const theme = this.getTheme();
|
|
116
|
+
const color = theme[colorName] || colorName;
|
|
117
|
+
return chalk[color] || chalk.white;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Shorthand color methods
|
|
121
|
+
primary(text) { return this.c('primary')(text); }
|
|
122
|
+
secondary(text) { return this.c('secondary')(text); }
|
|
123
|
+
accent(text) { return this.c('accent')(text); }
|
|
124
|
+
success(text) { return this.c('success')(text); }
|
|
125
|
+
error(text) { return this.c('error')(text); }
|
|
126
|
+
warning(text) { return this.c('warning')(text); }
|
|
127
|
+
info(text) { return this.c('info')(text); }
|
|
128
|
+
muted(text) { return this.c('muted')(text); }
|
|
129
|
+
link(text) { return this.c('link')(text); }
|
|
130
|
+
title(text) { return chalk.bold(this.c('title')(text)); }
|
|
131
|
+
url(text) { return this.c('url')(text); }
|
|
132
|
+
border(text) { return this.c('border')(text); }
|
|
133
|
+
highlight(text) { return this.c('highlight')(text); }
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export const theme = new ThemeManager();
|
|
137
|
+
export { THEMES };
|
package/src/ui.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import boxen from 'boxen';
|
|
3
|
+
import Table from 'cli-table3';
|
|
4
|
+
import figures from 'figures';
|
|
5
|
+
import { theme } from './themes.js';
|
|
6
|
+
|
|
7
|
+
export function banner() {
|
|
8
|
+
const t = theme.getTheme();
|
|
9
|
+
const logo = `
|
|
10
|
+
██████╗██╗ ██╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗███████╗███████╗██████╗
|
|
11
|
+
██╔════╝██║ ██║ ██╔══██╗██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔════╝██╔══██╗
|
|
12
|
+
██║ ██║ ██║ ██████╔╝██████╔╝██║ ██║██║ █╗ ██║█████╗ █████╗ ██████╔╝
|
|
13
|
+
██║ ██║ ██║ ██╔══██╗██╔══██╗██║ ██║██║███╗██║██╔══╝ ██╔══╝ ██╔══██╗
|
|
14
|
+
╚██████╗███████╗██║ ██████╔╝██║ ██║╚██████╔╝╚███╔███╔╝███████╗███████╗██║ ██║
|
|
15
|
+
╚═════╝╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚══════╝╚═╝ ╚═╝`;
|
|
16
|
+
|
|
17
|
+
console.log(theme.primary(logo));
|
|
18
|
+
console.log();
|
|
19
|
+
console.log(
|
|
20
|
+
boxen(
|
|
21
|
+
theme.accent(' Terminal Internet ') + '\n' +
|
|
22
|
+
theme.muted(' Browse the web from your terminal '),
|
|
23
|
+
{
|
|
24
|
+
padding: { top: 0, bottom: 0, left: 1, right: 1 },
|
|
25
|
+
borderStyle: 'round',
|
|
26
|
+
borderColor: t.primary,
|
|
27
|
+
textAlignment: 'center',
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
);
|
|
31
|
+
console.log();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function divider(char = '─', width = process.stdout.columns || 80) {
|
|
35
|
+
console.log(theme.muted(char.repeat(Math.min(width, 120))));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function header(text) {
|
|
39
|
+
console.log();
|
|
40
|
+
divider();
|
|
41
|
+
console.log(theme.title(` ${figures.pointer} ${text}`));
|
|
42
|
+
divider();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function subheader(text) {
|
|
46
|
+
console.log(theme.accent(`\n ${text}`));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function success(text) {
|
|
50
|
+
console.log(theme.success(` ${figures.tick} ${text}`));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function error(text) {
|
|
54
|
+
console.log(theme.error(` ${figures.cross} ${text}`));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function warn(text) {
|
|
58
|
+
console.log(theme.warning(` ${figures.warning} ${text}`));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function info(text) {
|
|
62
|
+
console.log(theme.info(` ${figures.info} ${text}`));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function bullet(text, indent = 2) {
|
|
66
|
+
console.log(' '.repeat(indent) + theme.muted(figures.pointer) + ' ' + text);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function numberedList(items, startIdx = 1) {
|
|
70
|
+
items.forEach((item, i) => {
|
|
71
|
+
const num = theme.accent(` [${startIdx + i}] `);
|
|
72
|
+
if (typeof item === 'string') {
|
|
73
|
+
console.log(num + item);
|
|
74
|
+
} else {
|
|
75
|
+
// item has .title, .url, .description
|
|
76
|
+
console.log(num + theme.title(item.title || ''));
|
|
77
|
+
if (item.url) {
|
|
78
|
+
console.log(' ' + theme.url(item.url));
|
|
79
|
+
}
|
|
80
|
+
if (item.description) {
|
|
81
|
+
console.log(' ' + theme.muted(truncate(item.description, 100)));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function keyValue(key, value, indent = 4) {
|
|
88
|
+
console.log(
|
|
89
|
+
' '.repeat(indent) +
|
|
90
|
+
theme.accent(key.padEnd(18)) +
|
|
91
|
+
theme.secondary(value)
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function createTable(headers, rows, options = {}) {
|
|
96
|
+
const t = theme.getTheme();
|
|
97
|
+
const table = new Table({
|
|
98
|
+
head: headers.map(h => theme.accent(h)),
|
|
99
|
+
style: {
|
|
100
|
+
head: [],
|
|
101
|
+
border: [t.border],
|
|
102
|
+
},
|
|
103
|
+
chars: {
|
|
104
|
+
'top': '─', 'top-mid': '┬', 'top-left': '┌', 'top-right': '┐',
|
|
105
|
+
'bottom': '─', 'bottom-mid': '┴', 'bottom-left': '└', 'bottom-right': '┘',
|
|
106
|
+
'left': '│', 'left-mid': '├', 'mid': '─', 'mid-mid': '┼',
|
|
107
|
+
'right': '│', 'right-mid': '┤', 'middle': '│',
|
|
108
|
+
},
|
|
109
|
+
...options,
|
|
110
|
+
});
|
|
111
|
+
rows.forEach(row => table.push(row));
|
|
112
|
+
console.log(table.toString());
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function searchResult(idx, result) {
|
|
116
|
+
const num = theme.accent(` [${idx}] `);
|
|
117
|
+
console.log(num + theme.title(result.title || 'Untitled'));
|
|
118
|
+
if (result.url) {
|
|
119
|
+
console.log(' ' + theme.url(result.url));
|
|
120
|
+
}
|
|
121
|
+
if (result.content || result.description) {
|
|
122
|
+
const desc = result.content || result.description;
|
|
123
|
+
console.log(' ' + theme.muted(truncate(desc, 120)));
|
|
124
|
+
}
|
|
125
|
+
if (result.engine) {
|
|
126
|
+
console.log(' ' + theme.muted(`via ${result.engine}`));
|
|
127
|
+
}
|
|
128
|
+
console.log();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function pageView(title, content, links = []) {
|
|
132
|
+
console.log();
|
|
133
|
+
divider('═');
|
|
134
|
+
console.log(theme.title(` ${title}`));
|
|
135
|
+
divider('═');
|
|
136
|
+
console.log();
|
|
137
|
+
console.log(content);
|
|
138
|
+
|
|
139
|
+
if (links.length > 0) {
|
|
140
|
+
console.log();
|
|
141
|
+
divider();
|
|
142
|
+
console.log(theme.accent(' Links:'));
|
|
143
|
+
links.forEach((link, i) => {
|
|
144
|
+
console.log(
|
|
145
|
+
theme.accent(` [${i + 1}] `) +
|
|
146
|
+
theme.link(link.text || link.url) +
|
|
147
|
+
(link.url !== link.text ? ' ' + theme.url(link.url) : '')
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function statusBar(tabs, currentTab, url) {
|
|
154
|
+
const t = theme.getTheme();
|
|
155
|
+
const tabStr = tabs.map((tab, i) => {
|
|
156
|
+
const label = ` ${i + 1}:${truncate(tab.title || 'New Tab', 12)} `;
|
|
157
|
+
return i === currentTab
|
|
158
|
+
? chalk.inverse(theme.accent(label))
|
|
159
|
+
: theme.muted(label);
|
|
160
|
+
}).join(theme.muted('│'));
|
|
161
|
+
|
|
162
|
+
const bar = theme.muted('┌') + theme.muted('─'.repeat(Math.min(process.stdout.columns - 2, 118) || 78)) + theme.muted('┐');
|
|
163
|
+
const bottom = theme.muted('└') + theme.muted('─'.repeat(Math.min(process.stdout.columns - 2, 118) || 78)) + theme.muted('┘');
|
|
164
|
+
|
|
165
|
+
console.log(bar);
|
|
166
|
+
console.log(theme.muted('│') + ' ' + tabStr);
|
|
167
|
+
if (url) {
|
|
168
|
+
console.log(theme.muted('│') + ' ' + theme.url(figures.arrowRight + ' ' + url));
|
|
169
|
+
}
|
|
170
|
+
console.log(bottom);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function prompt() {
|
|
174
|
+
const t = theme.getTheme();
|
|
175
|
+
return theme.accent(`${figures.pointer} `) + theme.primary('cli-browser') + theme.muted(' > ');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function helpBox(title, commands) {
|
|
179
|
+
console.log();
|
|
180
|
+
console.log(theme.title(` ${figures.pointer} ${title}`));
|
|
181
|
+
divider();
|
|
182
|
+
commands.forEach(([cmd, desc]) => {
|
|
183
|
+
console.log(
|
|
184
|
+
' ' + theme.accent(cmd.padEnd(35)) + theme.muted(desc)
|
|
185
|
+
);
|
|
186
|
+
});
|
|
187
|
+
console.log();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function truncate(str, max) {
|
|
191
|
+
if (!str) return '';
|
|
192
|
+
str = str.replace(/\n/g, ' ').trim();
|
|
193
|
+
return str.length > max ? str.slice(0, max - 3) + '...' : str;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function progressBar(current, total, width = 30) {
|
|
197
|
+
const pct = Math.round((current / total) * 100);
|
|
198
|
+
const filled = Math.round((current / total) * width);
|
|
199
|
+
const empty = width - filled;
|
|
200
|
+
const bar = theme.accent('█'.repeat(filled)) + theme.muted('░'.repeat(empty));
|
|
201
|
+
return `${bar} ${theme.secondary(pct + '%')}`;
|
|
202
|
+
}
|