starlight-cli 1.0.15 → 1.0.17

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.
Files changed (3) hide show
  1. package/dist/index.js +89 -23491
  2. package/package.json +1 -1
  3. package/src/starlight.js +66 -75
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
package/src/starlight.js CHANGED
@@ -2,14 +2,14 @@ const fs = require('fs');
2
2
  const path = require('path');
3
3
  const os = require('os');
4
4
  const { exec } = require('child_process');
5
+ const readline = require('readline');
5
6
  const readlineSync = require('readline-sync');
6
- const blessed = require('blessed');
7
7
 
8
8
  const Lexer = require('./lexer');
9
9
  const Parser = require('./parser');
10
10
  const Evaluator = require('./evaluator');
11
11
 
12
- const VERSION = '1.0.15';
12
+ const VERSION = '1.0.17';
13
13
 
14
14
  const COLOR = {
15
15
  reset: '\x1b[0m',
@@ -35,117 +35,108 @@ function fatal(msg) {
35
35
  waitAndExit(1);
36
36
  }
37
37
 
38
- function highlightCode(text) {
39
- return text
38
+ function highlightCode(line) {
39
+ return line
40
40
  .replace(/"(?:\\.|[^"])*"/g, m => COLOR.yellow + m + COLOR.reset)
41
41
  .replace(/\b\d+(\.\d+)?\b/g, m => COLOR.magenta + m + COLOR.reset)
42
- .replace(/\b(sldeploy|import|from|const|let|var|if|else|for|while|func|return|break|continue|define|ask)\b/g, m => COLOR.blue + m + COLOR.reset);
42
+ .replace(
43
+ /\b(sldeploy|import|from|let|if|else|for|while|func|return|break|continue|define|ask)\b/g,
44
+ m => COLOR.blue + m + COLOR.reset
45
+ );
46
+ }
47
+
48
+ function openURL(url) {
49
+ const platform = process.platform;
50
+ let command;
51
+
52
+ if (platform === 'win32') command = `start "" "${url}"`;
53
+ else if (platform === 'darwin') command = `open "${url}"`;
54
+ else command = `xdg-open "${url}"`;
55
+
56
+ exec(command);
43
57
  }
44
58
 
45
59
  const args = process.argv.slice(2);
46
60
 
47
61
  if (args.length === 0) {
48
62
  console.log(`
49
- Starlight Programming Language
63
+ ${COLOR.bold}Starlight Programming Language${COLOR.reset}
64
+ ${COLOR.magenta}Developed by Macedon${COLOR.reset}
50
65
 
51
66
  Usage:
52
- starlight <file.sl>
53
- starlight -v
54
- starlight --help
55
- starlight --learn
56
- starlight --writedirectly
67
+ starlight <file.sl> Run a Starlight file
68
+ starlight -v Show version
69
+ starlight --help Show help
70
+ starlight --learn Open learning guide
71
+ starlight --writedirectly Interactive editor
57
72
  `);
58
73
  process.exit(0);
59
74
  }
60
75
 
61
76
  if (args[0] === '-v' || args[0] === '--version') {
62
- console.log(`Starlight CLI v${VERSION}`);
77
+ console.log(`${COLOR.bold}Starlight CLI v${VERSION}${COLOR.reset}`);
78
+ console.log(`${COLOR.magenta}Developed by Macedon${COLOR.reset}`);
63
79
  process.exit(0);
64
80
  }
65
81
 
66
82
  if (args[0] === '--help') {
67
83
  console.log(`
68
- starlight <file.sl> Run file
69
- starlight --writedirectly Interactive editor
70
- starlight --learn Learning guide
84
+ ${COLOR.bold}Starlight CLI v${VERSION}${COLOR.reset}
85
+ ${COLOR.magenta}Developed by Macedon${COLOR.reset}
86
+
87
+ Commands:
88
+ ${COLOR.green}starlight <file.sl>${COLOR.reset}
89
+ Run a Starlight source file
90
+
91
+ ${COLOR.green}starlight -v${COLOR.reset}
92
+ Show CLI version
93
+
94
+ ${COLOR.green}starlight --help${COLOR.reset}
95
+ Show this help message
96
+
97
+ ${COLOR.green}starlight --learn${COLOR.reset}
98
+ Open the official learning guide
99
+
100
+ ${COLOR.green}starlight --writedirectly${COLOR.reset}
101
+ Interactive editor mode
71
102
  `);
72
103
  process.exit(0);
73
104
  }
74
105
 
75
106
  if (args[0] === '--learn') {
76
- exec('start https://programming-lang.pages.dev/learning-guide');
107
+ openURL('https://programming-lang.pages.dev/learning-guide');
77
108
  process.exit(0);
78
109
  }
79
110
 
80
111
  if (args[0] === '--writedirectly') {
81
112
  const tempFile = path.join(os.tmpdir(), `starlight-${Date.now()}.sl`);
113
+ const lines = [];
82
114
 
83
- const screen = blessed.screen({
84
- smartCSR: true,
85
- title: 'Starlight Editor'
86
- });
87
-
88
- const statusBar = blessed.box({
89
- top: 0,
90
- left: 0,
91
- height: 1,
92
- width: '100%',
93
- content: 'Starlight Editor | Ctrl+S Save | Ctrl+R Run | Ctrl+Q Quit',
94
- style: { fg: 'black', bg: 'green' }
95
- });
115
+ console.log(COLOR.green + 'Interactive Starlight Editor' + COLOR.reset);
116
+ console.log(COLOR.gray + 'Type code. Use :run to execute.\n' + COLOR.reset);
96
117
 
97
- const editor = blessed.textarea({
98
- top: 1,
99
- left: 0,
100
- width: '100%',
101
- height: '100%-2',
102
- keys: true,
103
- mouse: true,
104
- scrollbar: { bg: 'gray' },
105
- style: { fg: 'white', bg: 'black' },
106
- inputOnFocus: true
118
+ const rl = readline.createInterface({
119
+ input: process.stdin,
120
+ output: process.stdout,
121
+ terminal: false
107
122
  });
108
123
 
109
- const output = blessed.box({
110
- bottom: 0,
111
- left: 0,
112
- height: 1,
113
- width: '100%',
114
- content: ' Ready ',
115
- style: { fg: 'white', bg: 'blue' }
116
- });
117
-
118
- screen.append(statusBar);
119
- screen.append(editor);
120
- screen.append(output);
121
-
122
- if (fs.existsSync(tempFile)) {
123
- editor.setValue(fs.readFileSync(tempFile, 'utf8'));
124
- }
125
-
126
- editor.focus();
127
- screen.render();
128
-
129
- screen.key(['C-q'], () => screen.destroy());
130
-
131
- screen.key(['C-s'], () => {
132
- fs.writeFileSync(tempFile, editor.getValue());
133
- output.setContent(' Saved ');
134
- screen.render();
135
- });
124
+ process.stdout.write(COLOR.cyan + '> ' + COLOR.reset);
136
125
 
137
- screen.key(['C-r'], () => {
138
- fs.writeFileSync(tempFile, editor.getValue());
139
- output.setContent(' Running... ');
140
- screen.render();
126
+ rl.on('line', (line) => {
127
+ if (line.trim() === ':run') {
128
+ rl.close();
129
+ fs.writeFileSync(tempFile, lines.join('\n'), 'utf8');
130
+ runFile(tempFile, true, () => savePrompt(lines));
131
+ return;
132
+ }
141
133
 
142
- runFile(tempFile, true, () => {
143
- output.setContent(' Program finished ');
144
- screen.render();
145
- });
134
+ lines.push(line);
135
+ process.stdout.write(
136
+ COLOR.cyan + '> ' + COLOR.reset + highlightCode(line) + '\n'
137
+ );
146
138
  });
147
139
 
148
- screen.render();
149
140
  return;
150
141
  }
151
142