starlight-cli 1.0.14 → 1.0.16

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 +46 -23501
  2. package/package.json +1 -1
  3. package/src/starlight.js +23 -76
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
package/src/starlight.js CHANGED
@@ -4,12 +4,12 @@ const os = require('os');
4
4
  const { exec } = require('child_process');
5
5
  const readline = require('readline');
6
6
  const readlineSync = require('readline-sync');
7
- const blessed = require('blessed');
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.14';
12
+ const VERSION = '1.0.16';
13
13
 
14
14
  const COLOR = {
15
15
  reset: '\x1b[0m',
@@ -75,7 +75,7 @@ if (args[0] === '-v' || args[0] === '--version') {
75
75
  if (args[0] === '--help') {
76
76
  console.log(`
77
77
  starlight <file.sl> Run file
78
- starlight --writedirectly Interactive editor
78
+ starlight --writedirectly Interactive editor (Notepad and VS Code are recommended!)
79
79
  starlight --learn Learning guide
80
80
  `);
81
81
  process.exit(0);
@@ -88,87 +88,34 @@ if (args[0] === '--learn') {
88
88
 
89
89
 
90
90
  if (args[0] === '--writedirectly') {
91
- const blessed = require('blessed');
92
91
  const tempFile = path.join(os.tmpdir(), `starlight-${Date.now()}.sl`);
92
+ const lines = [];
93
93
 
94
- const screen = blessed.screen({
95
- smartCSR: true,
96
- title: 'Starlight Editor'
97
- });
98
-
99
- const statusBar = blessed.box({
100
- top: 0,
101
- left: 0,
102
- height: 1,
103
- width: '100%',
104
- content: 'Starlight Editor | Ctrl+S Save | Ctrl+R Run | Ctrl+Q Quit',
105
- style: { fg: 'black', bg: 'green' }
106
- });
107
-
108
- const editor = blessed.textarea({
109
- top: 1,
110
- left: 0,
111
- width: '100%',
112
- height: '100%-2',
113
- keys: true,
114
- mouse: true,
115
- scrollbar: { bg: 'gray' },
116
- style: { fg: 'white', bg: 'black' },
117
- inputOnFocus: true
118
- });
94
+ console.log(COLOR.green + 'Interactive Starlight Editor' + COLOR.reset);
95
+ console.log(COLOR.gray + 'Type code. Use :run to execute.\n' + COLOR.reset);
119
96
 
120
- const output = blessed.box({
121
- bottom: 0,
122
- left: 0,
123
- height: 1,
124
- width: '100%',
125
- content: ' Ready ',
126
- style: { fg: 'white', bg: 'blue' }
97
+ const rl = readline.createInterface({
98
+ input: process.stdin,
99
+ output: process.stdout,
100
+ terminal: false
127
101
  });
128
102
 
129
- screen.append(statusBar);
130
- screen.append(editor);
131
- screen.append(output);
132
-
133
- if (fs.existsSync(tempFile)) {
134
- editor.setValue(fs.readFileSync(tempFile, 'utf8'));
135
- }
103
+ process.stdout.write(COLOR.cyan + '> ' + COLOR.reset);
136
104
 
137
- editor.focus();
138
- screen.render();
105
+ rl.on('line', (line) => {
106
+ if (line.trim() === ':run') {
107
+ rl.close();
108
+ fs.writeFileSync(tempFile, lines.join('\n'), 'utf8');
109
+ runFile(tempFile, true, () => savePrompt(lines));
110
+ return;
111
+ }
139
112
 
140
- function highlightCode(text) {
141
- return text
142
- .replace(/"(.*?)"/g, '{yellow-fg}"$1"{/}')
143
- .replace(/\b\d+(\.\d+)?\b/g, '{magenta-fg}$&{/}')
144
- .replace(/\b(sldeploy|import|from|const|let|var|if|else|for|while|func|return|break|continue|define|ask)\b/g, '{blue-fg}$1{/}');
145
- }
146
-
147
- screen.key(['C-q'], () => screen.destroy());
148
- screen.key(['C-s'], () => {
149
- fs.writeFileSync(tempFile, editor.getValue());
150
- output.setContent(' Saved ');
151
- screen.render();
152
- });
153
- screen.key(['C-r'], () => {
154
- fs.writeFileSync(tempFile, editor.getValue());
155
- output.setContent(' Running... ');
156
- screen.render();
157
-
158
- runFile(tempFile, true, () => {
159
- output.setContent(' Program finished ');
160
- screen.render();
161
- });
162
- });
163
-
164
- editor.on('keypress', () => {
165
- const cursor = editor.getCursor();
166
- editor.setValue(highlightCode(editor.getValue()));
167
- editor.move(cursor.y, cursor.x);
168
- screen.render();
113
+ lines.push(line);
114
+ process.stdout.write(
115
+ COLOR.cyan + '> ' + COLOR.reset + highlightCode(line) + '\n'
116
+ );
169
117
  });
170
118
 
171
- screen.render();
172
119
  return;
173
120
  }
174
121
 
@@ -226,4 +173,4 @@ function runFile(filePath, isTemp = false, callback) {
226
173
 
227
174
  if (!args[0].startsWith('--')) {
228
175
  runFile(path.resolve(args[0]));
229
- }
176
+ }