Updated konsole
This commit is contained in:
		
							
								
								
									
										14
									
								
								src/modules/konsole/commands/cat.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/modules/konsole/commands/cat.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
window.cli.exec['cat'] = {
 | 
			
		||||
	autocomplete: () => {
 | 
			
		||||
		return [];
 | 
			
		||||
	},
 | 
			
		||||
	help: () => {
 | 
			
		||||
		return 'Display file contents';
 | 
			
		||||
	},
 | 
			
		||||
	run: args => {
 | 
			
		||||
		if(!args[0]) throw new Error('cat: missing operand');
 | 
			
		||||
		const file = window.cli.fs(args[0]);
 | 
			
		||||
		if(file == null) throw new Error('cat: File does not exist');
 | 
			
		||||
		return file;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -3,11 +3,12 @@ window.cli.exec['cd'] = {
 | 
			
		||||
		return [];
 | 
			
		||||
	},
 | 
			
		||||
	help: () => {
 | 
			
		||||
		return 'Clear console output';
 | 
			
		||||
		return 'Change present working directory';
 | 
			
		||||
	},
 | 
			
		||||
	run: args => {
 | 
			
		||||
		const path = window.cli.fs(args[0]);
 | 
			
		||||
		if(!path) throw new Error(`cd: \'${args[0]}\': No such file or directory`)
 | 
			
		||||
		if(!path) throw new Error(`cd: \'${args[0]}\': No such file or directory`);
 | 
			
		||||
		if(typeof path != 'object') throw new Error(`cd: \'${args[0]}\': Not a directory`);
 | 
			
		||||
 | 
			
		||||
		window.cli.pwd = window.cli.path(args[0]);
 | 
			
		||||
		window.cli._prompt.innerText = window.cli._buildPrompt();
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,14 @@ window.cli.exec['ls'] = {
 | 
			
		||||
	},
 | 
			
		||||
	run: args => {
 | 
			
		||||
		const target = window.cli.fs(args[0]);
 | 
			
		||||
		if(!target) throw new Error(`ls: cannot access \'${args[0]}\': No such file or directory`)
 | 
			
		||||
		return Object.keys(target).reduce((acc, p) => acc + `${p}\n`, '');
 | 
			
		||||
		if(!target || typeof target != 'object') throw new Error(`ls: cannot access \'${args[0]}\': No such file or directory`)
 | 
			
		||||
		return Object.keys(target)
 | 
			
		||||
			.sort((a, b) => {
 | 
			
		||||
				if(a > b) return 1;
 | 
			
		||||
				if(b > a) return -1;
 | 
			
		||||
				return 0;
 | 
			
		||||
			})
 | 
			
		||||
			.map(p => `-rwxrw---- 1 root root ${typeof target[p] =='object' ? '-' : target[p].length} ${p}`)
 | 
			
		||||
			.join('\n');
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,7 @@ window.cli.exec['mkdir'] = {
 | 
			
		||||
	},
 | 
			
		||||
	run: args => {
 | 
			
		||||
		if(!args[0]) throw new Error('mkdir: missing operand');
 | 
			
		||||
		if(window.cli.fs(args[0]) != null) throw new Error('mkdir: File or directory already exists');
 | 
			
		||||
		window.cli.fs(args[0], {});
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ window.cli.exec['rm'] = {
 | 
			
		||||
		return 'Delete file or directory';
 | 
			
		||||
	},
 | 
			
		||||
	run: args => {
 | 
			
		||||
		if(!args[0]) throw new Error('rm: missing operand');
 | 
			
		||||
		window.cli.fs(args[0], null);
 | 
			
		||||
		if(!args.length) throw new Error('rm: missing operand');
 | 
			
		||||
		args.forEach(a => window.cli.fs(a, null));
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								src/modules/konsole/commands/touch.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/modules/konsole/commands/touch.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
window.cli.exec['touch'] = {
 | 
			
		||||
	autocomplete: () => {
 | 
			
		||||
		return [];
 | 
			
		||||
	},
 | 
			
		||||
	help: () => {
 | 
			
		||||
		return 'Change file timestamps & create file if missing';
 | 
			
		||||
	},
 | 
			
		||||
	run: args => {
 | 
			
		||||
		if(!args[0]) throw new Error('touch: missing operand');
 | 
			
		||||
		if(!window.cli.fs(args[0])) window.cli.fs(args[0], '');
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -3,6 +3,7 @@ import './konsole.css';
 | 
			
		||||
 | 
			
		||||
// CLI Commands
 | 
			
		||||
import './commands/banner.js';
 | 
			
		||||
import './commands/cat.js';
 | 
			
		||||
import './commands/cd.js'
 | 
			
		||||
import './commands/clear.js';
 | 
			
		||||
import './commands/date.js';
 | 
			
		||||
@@ -15,5 +16,6 @@ import './commands/man.js';
 | 
			
		||||
import './commands/mkdir.js';
 | 
			
		||||
import './commands/pwd.js';
 | 
			
		||||
import './commands/rm.js';
 | 
			
		||||
import './commands/shower-thoughts.js';
 | 
			
		||||
import './commands/shower-thought.js';
 | 
			
		||||
import './commands/touch.js';
 | 
			
		||||
import './commands/whoami.js';
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@
 | 
			
		||||
	overflow-y: auto;
 | 
			
		||||
	min-height: 150px;
 | 
			
		||||
	max-height: 300px;
 | 
			
		||||
	tab-size: 4;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.cli-stdout {
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,7 @@ window.cli = {
 | 
			
		||||
                <div class="cli-stdout"></div>
 | 
			
		||||
                <div class="cli-stdin" onclick="window.cli._input.focus()">
 | 
			
		||||
                    <label for="${elementId}-cli-stdin-input" class="cli-stdin-prompt">${window.cli._buildPrompt()}</label>
 | 
			
		||||
                    <input id="${elementId}-cli-stdin-input" class="cli-stdin-input" type="text" />
 | 
			
		||||
                    <input id="${elementId}-cli-stdin-input" class="cli-stdin-input" type="text" autocomplete="off"/>
 | 
			
		||||
                </div>
 | 
			
		||||
            </div>`;
 | 
			
		||||
 | 
			
		||||
@@ -119,11 +119,10 @@ window.cli = {
 | 
			
		||||
				try {
 | 
			
		||||
					const args = parts.slice(1).map(a => (a[0] == '"' || a[0] == "'") ? a.slice(1, -1) : a);
 | 
			
		||||
					const out = exec.run(args);
 | 
			
		||||
					if(!suppress) window.cli.stdOut(`${window.cli._buildPrompt()} ${command}${out ? '\n' + out : ''}`);
 | 
			
		||||
					if(!suppress) window.cli.stdOut(`${window.cli._buildPrompt()} ${command}${out != null ? '\n' + (out || '\n') : ''}`);
 | 
			
		||||
				} catch(err) {
 | 
			
		||||
					console.error(err);
 | 
			
		||||
					if(!suppress) {
 | 
			
		||||
						window.cli._output.removeChild(window.cli._output.children[window.cli._output.children.length - 1]);
 | 
			
		||||
						window.cli.stdErr(`${window.cli._buildPrompt()} ${command}\n${err.message || `${parts[0]}: exited with a non-zero status`}`);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										45
									
								
								src/modules/konsole/models/file.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								src/modules/konsole/models/file.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,45 @@
 | 
			
		||||
export class CliFile {
 | 
			
		||||
	owner = window.cli.user;
 | 
			
		||||
	group = window.cli.user;
 | 
			
		||||
	permissions = 750;
 | 
			
		||||
	created = new Date();
 | 
			
		||||
	modified = new Date();
 | 
			
		||||
 | 
			
		||||
	#data;
 | 
			
		||||
	get date() { return this.#data; }
 | 
			
		||||
	set date(d) {
 | 
			
		||||
		this.modified = new Date();
 | 
			
		||||
		this.#data = d;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	static instanceOf(f) {
 | 
			
		||||
		return f.hasOwnProperty('data');
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	size() {
 | 
			
		||||
		return this.#data.toString().length;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	permsString() {
 | 
			
		||||
		return '-' + this.permissions.toString().split('').map(p => {
 | 
			
		||||
			switch (p) {
 | 
			
		||||
				case 0:
 | 
			
		||||
					return '---';
 | 
			
		||||
				case 1:
 | 
			
		||||
					return '--x';
 | 
			
		||||
				case 2:
 | 
			
		||||
					return '-w-';
 | 
			
		||||
				case 3:
 | 
			
		||||
					return '-wx';
 | 
			
		||||
				case 4:
 | 
			
		||||
					return 'r--';
 | 
			
		||||
				case 5:
 | 
			
		||||
					return 'r-x';
 | 
			
		||||
				case 6:
 | 
			
		||||
					return 'rw-';
 | 
			
		||||
				case 7:
 | 
			
		||||
					return 'rwx';
 | 
			
		||||
			}
 | 
			
		||||
		}).join('');
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user