Skip to content

Commit

Permalink
Merge pull request #316 from gbmhunter/develop
Browse files Browse the repository at this point in the history
Release of v4.15.0.
  • Loading branch information
gbmhunter authored May 14, 2024
2 parents d312903 + dcad6b6 commit 7c5d4bd
Show file tree
Hide file tree
Showing 12 changed files with 486 additions and 338 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

## [4.15.0] - 2024-05-14

### Added

- Added more recommended baud rate options.
- Added the ability to specify a custom baud rate.
- Added a circular progress modal which is shown when the port is opening.
- Added ability to customize what is sent (LF, CR, or CRLF) on enter key press.

### Fixed

- Fixed bug which meant app thought port opened successfully even when it didn't.

## [4.14.0] - 2024-05-12

### Added
Expand Down Expand Up @@ -681,7 +694,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added auto-scroll to TX pane, closes #89.
- Added special delete behaviour for backspace button when in "send on enter" mode, closes #90.

[unreleased]: https://github.com/gbmhunter/NinjaTerm/compare/v4.14.0...HEAD
[unreleased]: https://github.com/gbmhunter/NinjaTerm/compare/v4.15.0...HEAD
[4.15.0]: https://github.com/gbmhunter/NinjaTerm/compare/v4.14.0...v4.15.0
[4.14.0]: https://github.com/gbmhunter/NinjaTerm/compare/v4.13.2...v4.14.0
[4.13.2]: https://github.com/gbmhunter/NinjaTerm/compare/v4.13.1...v4.13.2
[4.13.1]: https://github.com/gbmhunter/NinjaTerm/compare/v4.13.0...v4.13.1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ninjaterm",
"version": "4.14.0",
"version": "4.15.0",
"dependencies": {
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
Expand Down
68 changes: 46 additions & 22 deletions src/model/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import AppStorage from './Storage/AppStorage';
import { PortState } from './Settings/PortConfigurationSettings/PortConfigurationSettings';
import Terminals from './Terminals/Terminals';
import SingleTerminal from './Terminals/SingleTerminal/SingleTerminal';
import { BackspaceKeyPressBehavior, DeleteKeyPressBehaviors } from './Settings/TxSettings/TxSettings';
import { BackspaceKeyPressBehavior, DeleteKeyPressBehavior, EnterKeyPressBehavior } from './Settings/TxSettings/TxSettings';
import { SelectionController, SelectionInfo } from './SelectionController/SelectionController';
import { isRunningOnWindows } from './Util/Util';

Expand Down Expand Up @@ -126,6 +126,8 @@ export class App {

SelectionController = SelectionController;

showCircularProgressModal = false;

constructor(testing = false) {
this.testing = testing;
if (this.testing) {
Expand Down Expand Up @@ -293,30 +295,32 @@ export class App {
});
if (this.settings.portConfiguration.config.connectToSerialPortAsSoonAsItIsSelected) {
await this.openPort();
runInAction(() => {
this.portState = PortState.OPENED;
});
// Goto the terminal pane
this.setShownMainPane(MainPanes.TERMINAL);
// Go to the terminal pane, only if opening was successful
if (this.portState === PortState.OPENED) {
this.setShownMainPane(MainPanes.TERMINAL);
}
}
} else {
console.error('Browser not supported, it does not provide the navigator.serial API.');
this.snackbar.sendToSnackbar('Browser not supported, it does not provide the navigator.serial API.', 'error');
}
}

/**
* Opens the selected serial port.
* Opens the selected serial port using settings from the Port Configuration view.
*
* @param printSuccessMsg If true, a success message will be printed to the snackbar.
*/
async openPort(printSuccessMsg = true) {
if (this.lastSelectedPortType === PortType.REAL) {
// Show the circular progress modal when trying to open the port. If the port opening is going to fail, sometimes it takes
// a few seconds for awaiting open() to complete, so this prevents the user from trying to open the port again while we wait
this.setShowCircularProgressModal(true);
try {
await this.port?.open({
baudRate: this.settings.selectedBaudRate,
dataBits: this.settings.selectedNumDataBits,
parity: this.settings.selectedParity as ParityType,
stopBits: this.settings.selectedStopBits,
baudRate: this.settings.portConfiguration.config.baudRate, // This might be custom
dataBits: this.settings.portConfiguration.config.numDataBits,
parity: this.settings.portConfiguration.config.parity as ParityType,
stopBits: this.settings.portConfiguration.config.stopBits,
bufferSize: 10000,
}); // Default buffer size is only 256 (presumably bytes), which is not enough regularly causes buffer overrun errors
} catch (error) {
Expand All @@ -337,14 +341,20 @@ export class App {
console.log(msg);
}

console.log('Disabling modal');
this.setShowCircularProgressModal(false);

// An error occurred whilst calling port.open(), so DO NOT continue, port
// cannot be considered open
return;
}
console.log('Open success!');
if (printSuccessMsg) {
this.snackbar.sendToSnackbar('Serial port opened.', 'success');
}

this.setShowCircularProgressModal(false);

runInAction(() => {
this.portState = PortState.OPENED;
this.keepReading = true;
Expand Down Expand Up @@ -525,12 +535,14 @@ export class App {
if (this.shownMainPane === MainPanes.SETTINGS && this.settings.activeSettingsCategory === SettingsCategories.PORT_CONFIGURATION && event.key === 'f') {
this.fakePortController.setIsDialogOpen(true);
}
//============================================
// COPY KEYBOARD SHORTCUT
//============================================
else if (event.ctrlKey && event.shiftKey && event.key === 'C') {
// Ctrl-Shift-C is pressed
this.handleCopyToClipboard(event);
}
//============================================
// PASTE KEYBOARD SHORTCUT
//============================================
else if (event.ctrlKey && event.shiftKey && event.key === 'V') {
Expand Down Expand Up @@ -558,6 +570,7 @@ export class App {
const dataAsUint8Array = new TextEncoder().encode(text);
await this.writeBytesToSerialPort(dataAsUint8Array);
}
//=============================================
// TERMINAL DATA
//=============================================
else if (this.terminals.txRxTerminal.isFocused || this.terminals.txTerminal.isFocused) {
Expand Down Expand Up @@ -735,7 +748,7 @@ export class App {
else if (event.ctrlKey) {
// Most presses with the Ctrl key held down should do nothing. One exception is
// if sending 0x01-0x1A when Ctrl-A through Ctrl-Z is pressed is enabled
if (this.settings.txSettings.send0x01Thru0x1AWhenCtrlAThruZPressed && event.key.length === 1 && alphabeticChars.includes(event.key)) {
if (this.settings.txSettings.config.send0x01Thru0x1AWhenCtrlAThruZPressed && event.key.length === 1 && alphabeticChars.includes(event.key)) {
// Ctrl-A through Ctrl-Z is has been pressed
// Send 0x01 through 0x1A, which is easily done by getting the char, converting to
// uppercase if lowercase and then subtracting 64
Expand All @@ -745,7 +758,7 @@ export class App {
return;
}
} else if (event.altKey) {
if (this.settings.txSettings.sendEscCharWhenAltKeyPressed && event.key.length === 1 && alphabeticChars.includes(event.key)) {
if (this.settings.txSettings.config.sendEscCharWhenAltKeyPressed && event.key.length === 1 && alphabeticChars.includes(event.key)) {
// Alt-A through Alt-Z is has been pressed
// Send ESC char (0x1B) followed by the char
bytesToWrite.push(0x1B);
Expand All @@ -755,9 +768,16 @@ export class App {
return;
}
} else if (event.key === 'Enter') {
// TODO: Add support for sending different things on enter
bytesToWrite.push(13);
bytesToWrite.push(10);
if (this.settings.txSettings.config.enterKeyPressBehavior === EnterKeyPressBehavior.SEND_LF) {
bytesToWrite.push(0x0A);
} else if (this.settings.txSettings.config.enterKeyPressBehavior === EnterKeyPressBehavior.SEND_CR) {
bytesToWrite.push(0x0D);
} else if (this.settings.txSettings.config.enterKeyPressBehavior === EnterKeyPressBehavior.SEND_CRLF) {
bytesToWrite.push(0x0D);
bytesToWrite.push(0x0A);
} else {
throw Error('Unsupported enter key press behavior!');
}
} else if (event.key.length === 1 && alphaNumericChars.includes(event.key)) {
// Pressed key is alphanumeric
bytesToWrite.push(event.key.charCodeAt(0));
Expand All @@ -771,20 +791,20 @@ export class App {
//===========================================================
else if (event.key === 'Backspace') {
// Work out whether to send BS (0x08) or DEL (0x7F) based on settings
if (this.settings.txSettings.backspaceKeyPressBehavior === BackspaceKeyPressBehavior.SEND_BACKSPACE) {
if (this.settings.txSettings.config.backspaceKeyPressBehavior === BackspaceKeyPressBehavior.SEND_BACKSPACE) {
bytesToWrite.push(0x08);
} else if (this.settings.txSettings.backspaceKeyPressBehavior === BackspaceKeyPressBehavior.SEND_DELETE) {
} else if (this.settings.txSettings.config.backspaceKeyPressBehavior === BackspaceKeyPressBehavior.SEND_DELETE) {
bytesToWrite.push(0x7F);
} else {
throw Error('Unsupported backspace key press behavior!');
}
} else if (event.key === 'Delete') {
// Delete also has the option of sending [ESC][3~
if (this.settings.txSettings.deleteKeyPressBehavior === DeleteKeyPressBehaviors.SEND_BACKSPACE) {
if (this.settings.txSettings.config.deleteKeyPressBehavior === DeleteKeyPressBehavior.SEND_BACKSPACE) {
bytesToWrite.push(0x08);
} else if (this.settings.txSettings.deleteKeyPressBehavior === DeleteKeyPressBehaviors.SEND_DELETE) {
} else if (this.settings.txSettings.config.deleteKeyPressBehavior === DeleteKeyPressBehavior.SEND_DELETE) {
bytesToWrite.push(0x7F);
} else if (this.settings.txSettings.deleteKeyPressBehavior === DeleteKeyPressBehaviors.SEND_VT_SEQUENCE) {
} else if (this.settings.txSettings.config.deleteKeyPressBehavior === DeleteKeyPressBehavior.SEND_VT_SEQUENCE) {
bytesToWrite.push(0x1B, '['.charCodeAt(0), '3'.charCodeAt(0), '~'.charCodeAt(0));
} else {
throw Error('Unsupported delete key press behavior!');
Expand Down Expand Up @@ -899,4 +919,8 @@ export class App {
console.log('onRegisterError() called.');
console.error(error.message);
}

setShowCircularProgressModal(show: boolean) {
this.showCircularProgressModal = show;
}
}
1 change: 1 addition & 0 deletions src/model/Settings/DisplaySettings/DisplaySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default class DisplaySettings {
}

saveConfig = () => {
// TODO: Update this to match the style used in RX settings (and others)
const config = {
charSizePx: this.charSizePx.dispValue,
verticalRowPadding: this.verticalRowPaddingPx.dispValue,
Expand Down
11 changes: 6 additions & 5 deletions src/model/Settings/GeneralSettings/GeneralSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,19 @@ export default class RxSettings {
_loadConfig = () => {
let deserializedConfig = this.appStorage.getConfig(CONFIG_KEY);

//===============================================
// UPGRADE PATH
//===============================================

if (deserializedConfig === null) {
// No data exists, create
console.log("No rx-settings config found in local storage. Creating...");
console.log(`No config found in local storage for key ${CONFIG_KEY}. Creating...`);
this._saveConfig();
return;
} else if (deserializedConfig.version === 1) {
console.log("Up-to-date config found");
} else if (deserializedConfig.version === this.config.version) {
console.log(`Up-to-date config found for key ${CONFIG_KEY}.`);
} else {
console.error("Unknown config version found: ", deserializedConfig.version);
console.error(`Out-of-date config version ${deserializedConfig.version} found for key ${CONFIG_KEY}.` +
` Updating to version ${this.config.version}.`);
this._saveConfig();
}

Expand Down
Loading

0 comments on commit 7c5d4bd

Please sign in to comment.