├── .editorconfig ├── .eslintignore ├── .eslintrc.json ├── .gitignore ├── JavaScript ├── 0-console.js ├── 1-readline.js ├── 2-await.js ├── 3-prompt.js ├── 4-cli.js ├── 5-table.js ├── 6-group.js ├── 7-login.js ├── 8-utils.js └── 9-raw.js ├── LICENSE └── README.md /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | end_of_line = lf 6 | charset = utf-8 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | 10 | [{*.js,*.mjs,*.ts,*.json,*.yml}] 11 | indent_size = 2 12 | indent_style = space 13 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es6": true, 5 | "node": true 6 | }, 7 | "extends": "eslint:recommended", 8 | "parserOptions": { 9 | "ecmaVersion": "latest" 10 | }, 11 | "globals": { 12 | "BigInt": true 13 | }, 14 | "rules": { 15 | "indent": [ 16 | "error", 17 | 2 18 | ], 19 | "linebreak-style": [ 20 | "error", 21 | "unix" 22 | ], 23 | "quotes": [ 24 | "error", 25 | "single" 26 | ], 27 | "semi": [ 28 | "error", 29 | "always" 30 | ], 31 | "no-loop-func": [ 32 | "error" 33 | ], 34 | "block-spacing": [ 35 | "error", 36 | "always" 37 | ], 38 | "camelcase": [ 39 | "error" 40 | ], 41 | "eqeqeq": [ 42 | "error", 43 | "always" 44 | ], 45 | "strict": [ 46 | "error", 47 | "global" 48 | ], 49 | "brace-style": [ 50 | "error", 51 | "1tbs", 52 | { 53 | "allowSingleLine": true 54 | } 55 | ], 56 | "comma-style": [ 57 | "error", 58 | "last" 59 | ], 60 | "comma-spacing": [ 61 | "error", 62 | { 63 | "before": false, 64 | "after": true 65 | } 66 | ], 67 | "eol-last": [ 68 | "error" 69 | ], 70 | "func-call-spacing": [ 71 | "error", 72 | "never" 73 | ], 74 | "key-spacing": [ 75 | "error", 76 | { 77 | "beforeColon": false, 78 | "afterColon": true, 79 | "mode": "minimum" 80 | } 81 | ], 82 | "keyword-spacing": [ 83 | "error", 84 | { 85 | "before": true, 86 | "after": true, 87 | "overrides": { 88 | "function": { 89 | "after": false 90 | } 91 | } 92 | } 93 | ], 94 | "max-len": [ 95 | "error", 96 | { 97 | "code": 80, 98 | "ignoreUrls": true 99 | } 100 | ], 101 | "max-nested-callbacks": [ 102 | "error", 103 | { 104 | "max": 7 105 | } 106 | ], 107 | "new-cap": [ 108 | "error", 109 | { 110 | "newIsCap": true, 111 | "capIsNew": false, 112 | "properties": true 113 | } 114 | ], 115 | "new-parens": [ 116 | "error" 117 | ], 118 | "no-lonely-if": [ 119 | "error" 120 | ], 121 | "no-trailing-spaces": [ 122 | "error" 123 | ], 124 | "no-unneeded-ternary": [ 125 | "error" 126 | ], 127 | "no-whitespace-before-property": [ 128 | "error" 129 | ], 130 | "object-curly-spacing": [ 131 | "error", 132 | "always" 133 | ], 134 | "operator-assignment": [ 135 | "error", 136 | "always" 137 | ], 138 | "operator-linebreak": [ 139 | "error", 140 | "after" 141 | ], 142 | "semi-spacing": [ 143 | "error", 144 | { 145 | "before": false, 146 | "after": true 147 | } 148 | ], 149 | "space-before-blocks": [ 150 | "error", 151 | "always" 152 | ], 153 | "space-before-function-paren": [ 154 | "error", 155 | { 156 | "anonymous": "never", 157 | "named": "never", 158 | "asyncArrow": "always" 159 | } 160 | ], 161 | "space-in-parens": [ 162 | "error", 163 | "never" 164 | ], 165 | "space-infix-ops": [ 166 | "error" 167 | ], 168 | "space-unary-ops": [ 169 | "error", 170 | { 171 | "words": true, 172 | "nonwords": false, 173 | "overrides": { 174 | "typeof": false 175 | } 176 | } 177 | ], 178 | "no-unreachable": [ 179 | "error" 180 | ], 181 | "no-global-assign": [ 182 | "error" 183 | ], 184 | "no-self-compare": [ 185 | "error" 186 | ], 187 | "no-unmodified-loop-condition": [ 188 | "error" 189 | ], 190 | "no-constant-condition": [ 191 | "error", 192 | { 193 | "checkLoops": false 194 | } 195 | ], 196 | "no-console": [ 197 | "off" 198 | ], 199 | "no-useless-concat": [ 200 | "error" 201 | ], 202 | "no-useless-escape": [ 203 | "error" 204 | ], 205 | "no-shadow-restricted-names": [ 206 | "error" 207 | ], 208 | "no-use-before-define": [ 209 | "error", 210 | { 211 | "functions": false 212 | } 213 | ], 214 | "arrow-parens": [ 215 | "error", 216 | "always" 217 | ], 218 | "arrow-body-style": [ 219 | "error", 220 | "as-needed" 221 | ], 222 | "arrow-spacing": [ 223 | "error" 224 | ], 225 | "no-confusing-arrow": [ 226 | "error", 227 | { 228 | "allowParens": true 229 | } 230 | ], 231 | "no-useless-computed-key": [ 232 | "error" 233 | ], 234 | "no-useless-rename": [ 235 | "error" 236 | ], 237 | "no-var": [ 238 | "error" 239 | ], 240 | "object-shorthand": [ 241 | "error", 242 | "always" 243 | ], 244 | "prefer-arrow-callback": [ 245 | "error" 246 | ], 247 | "prefer-const": [ 248 | "error" 249 | ], 250 | "prefer-numeric-literals": [ 251 | "error" 252 | ], 253 | "prefer-rest-params": [ 254 | "error" 255 | ], 256 | "prefer-spread": [ 257 | "error" 258 | ], 259 | "rest-spread-spacing": [ 260 | "error", 261 | "never" 262 | ], 263 | "template-curly-spacing": [ 264 | "error", 265 | "never" 266 | ], 267 | "consistent-return": [ 268 | "error", 269 | { "treatUndefinedAsUnspecified": true } 270 | ] 271 | } 272 | } 273 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | .DS_Store 4 | -------------------------------------------------------------------------------- /JavaScript/0-console.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | console.clear(); 4 | 5 | console.log('log'); 6 | 7 | const obj = { 8 | name: 'Marcus Aurelius', 9 | city: 'Roma', 10 | born: 121, 11 | children: [ 12 | { 13 | name: 'Vibia Aurelia Sabina', 14 | city: 'Sirmium', 15 | born: 170, 16 | }, 17 | { 18 | name: 'Annia Cornificia Faustina Minor', 19 | city: 'Roma', 20 | born: 160, 21 | } 22 | ] 23 | }; 24 | 25 | Object.defineProperty(obj, 'childCount', { 26 | enumerable: false, 27 | writable: false, 28 | value: 13 29 | }); 30 | 31 | console.log({ obj }); 32 | 33 | console.dir({ obj }); 34 | console.dir({ obj }, { showHidden: true, depth: 20, colors: true }); 35 | 36 | console.error('Error'); 37 | 38 | console.time('Loop time'); 39 | const arr = []; 40 | for (let i = 0; i < 10000; i++) { 41 | arr.push(i); 42 | } 43 | console.timeEnd('Loop time'); 44 | 45 | console.trace('Trace here'); 46 | 47 | console.log('\n' + Object.keys(console).join(', ')); 48 | -------------------------------------------------------------------------------- /JavaScript/1-readline.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const readline = require('node:readline'); 4 | 5 | const rl = readline.createInterface({ 6 | input: process.stdin, 7 | output: process.stdout 8 | }); 9 | 10 | rl.question('Enter your name: ', (name) => { 11 | console.log(`Hello, ${name}!`); 12 | rl.close(); 13 | }); 14 | -------------------------------------------------------------------------------- /JavaScript/2-await.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Node.js v17 4 | 5 | const readline = require('node:readline').promises; 6 | 7 | const rl = readline.createInterface({ 8 | input: process.stdin, 9 | output: process.stdout 10 | }); 11 | 12 | const main = async () => { 13 | const name = await rl.question('Enter your name: '); 14 | console.log(`Hello, ${name}!`); 15 | rl.close(); 16 | }; 17 | 18 | main(); 19 | -------------------------------------------------------------------------------- /JavaScript/3-prompt.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const readline = require('node:readline'); 4 | 5 | const rl = readline.createInterface({ 6 | input: process.stdin, 7 | output: process.stdout, 8 | prompt: '> ', 9 | }); 10 | 11 | rl.prompt(); 12 | 13 | const commands = { 14 | help() { 15 | console.log('Commands:', Object.keys(commands).join(', ')); 16 | }, 17 | hello() { 18 | console.log('Hello there!'); 19 | }, 20 | exit() { 21 | rl.close(); 22 | } 23 | }; 24 | 25 | rl.on('line', (line) => { 26 | line = line.trim(); 27 | const command = commands[line]; 28 | if (command) command(); 29 | else console.log('Unknown command'); 30 | rl.prompt(); 31 | }).on('close', () => { 32 | console.log('Bye!'); 33 | process.exit(0); 34 | }); 35 | -------------------------------------------------------------------------------- /JavaScript/4-cli.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | console.dir({ 4 | currentDirectory: process.cwd(), 5 | processId: process.pid, 6 | platform: process.platform, 7 | release: process.release, 8 | title: process.title, 9 | nodeVersion: process.version, 10 | versions: process.versions, 11 | }); 12 | 13 | console.log('\nCommand line parameters:'); 14 | process.argv.forEach((value, index) => { 15 | console.log(`${index}: ${value}`); 16 | }); 17 | 18 | console.log('\nEnvironment variables:'); 19 | for (const name in process.env) { 20 | const value = process.env[name]; 21 | console.log(`${name}: ${value}`); 22 | } 23 | -------------------------------------------------------------------------------- /JavaScript/5-table.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const persons = [ 4 | { name: 'Marcus Aurelius', city: 'Rome', born: 121 }, 5 | { name: 'Victor Glushkov', city: 'Rostov on Don', born: 1923 }, 6 | { name: 'Ibn Arabi', city: 'Murcia', born: 1165 }, 7 | { name: 'Mao Zedong', city: 'Shaoshan', born: 1893 }, 8 | { name: 'Rene Descartes', city: 'La Haye en Touraine', born: 1596 }, 9 | ]; 10 | 11 | console.table(persons); 12 | -------------------------------------------------------------------------------- /JavaScript/6-group.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | console.log('Level 1'); 4 | console.group(); 5 | console.log('Level 2'); 6 | console.group(); 7 | console.log('Level 3'); 8 | console.groupEnd(); 9 | console.log('Message 1'); 10 | console.groupEnd(); 11 | console.log('Message 2'); 12 | -------------------------------------------------------------------------------- /JavaScript/7-login.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const write = (s) => process.stdout.write(s); 4 | 5 | let login = ''; 6 | let password = ''; 7 | 8 | process.stdin.on('data', (chunk) => { 9 | if (!login) { 10 | login = chunk.toString().trim(); 11 | write('\x1b[13;34H'); 12 | } else { 13 | password = chunk.toString().trim(); 14 | write(`\nHello, ${login}!\n Your password is: ${password}`); 15 | } 16 | }); 17 | 18 | write('\x1Bc'); 19 | write('\x1b[10;10H'); 20 | 21 | setTimeout(() => { 22 | write('\n\n'); 23 | process.exit(0); 24 | }, 10000); 25 | 26 | write(` 27 | ┌───────────────────────────────┐ 28 | │ Login: │ 29 | │ Password: │ 30 | └───────────────────────────────┘ 31 | `); 32 | 33 | write('\x1b[3A\x1b[31C'); 34 | -------------------------------------------------------------------------------- /JavaScript/8-utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Utilities 4 | 5 | const write = (s) => process.stdout.write(s); 6 | const read = (callback) => process.stdin.on('data', (chunk) => { 7 | callback(chunk.toString().trim()); 8 | }); 9 | const clear = () => write('\x1Bc'); 10 | const pos = (row, col) => write(`\x1b[${row};${col}H`); 11 | const box = (row, col, height, width) => { 12 | const h = height - 2; 13 | const w = width - 2; 14 | const border = '┌┐─│└┘'.split(''); 15 | pos(row, col); 16 | write(border[0] + border[2].repeat(w) + border[1]); 17 | for (let i = 1; i < h; i++) { 18 | pos(row + i, col); 19 | write(border[3] + ' '.repeat(w) + border[3]); 20 | } 21 | pos(row + h, col); 22 | write(border[4] + border[2].repeat(w) + border[5]); 23 | }; 24 | 25 | // Usage 26 | 27 | read((s) => { 28 | write(`\nHello, ${s}!\n`); 29 | process.exit(0); 30 | }); 31 | clear(); 32 | 33 | setTimeout(() => { 34 | write('\n\n'); 35 | process.exit(0); 36 | }, 10000); 37 | 38 | box(10, 10, 4, 30); 39 | pos(11, 12); 40 | write('Login: '); 41 | -------------------------------------------------------------------------------- /JavaScript/9-raw.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | process.stdin.setRawMode(true); 4 | 5 | process.stdin.on('data', (data) => { 6 | const key = data[0]; 7 | console.dir(data); 8 | if (key === 3) { 9 | process.exit(0); 10 | } 11 | }); 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016-2023 How.Programming.Works contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Command Line Interface and Console 2 | [![Консоль и командная строка](https://img.youtube.com/vi/5aSZyKi5BmE/0.jpg)](https://www.youtube.com/watch?v=5aSZyKi5BmE) 3 | --------------------------------------------------------------------------------