Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize signature of encodeCommand #31

Merged
merged 1 commit into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/PrinterUsbManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export interface PrinterManagerEventMap {
* a printer using the browser's UI. Once paired at least once the browser will rember and reconnect
* automatically.
*
* This class exposes two events, which your code should add handlers for:
* *
* This class exposes events, which your code should add handlers for:
* * connectedPrinter: Fired when a printer is ready to be interacted with.
* * disconnectedPrinter: Fired when a printer is no longer connected.
*
* This class will bind to WebUSB events on the Navigator element, your code should ensure only
* one instance is ever instantiated to avoid conflicts.
Expand Down
6 changes: 3 additions & 3 deletions src/Printers/Languages/EplPrinterCommandSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class EplPrinterCommandSet extends PrinterCommandSet {
get formEndCommand(): Uint8Array {
// There's no formal command for the end of an EPL doc, but just in case
// add a newline.
return this.encodeCommand('');
return this.encodeCommand();
}

protected nonFormCommands: (symbol | Commands.CommandType)[] = [
Expand All @@ -49,7 +49,7 @@ export class EplPrinterCommandSet extends PrinterCommandSet {
[Commands.CommandType.CommandCustomSpecificCommand, this.unprocessedCommand],
[Commands.CommandType.CommandLanguageSpecificCommand, this.unprocessedCommand],
// Actually valid commands to parse
[Commands.CommandType.OffsetCommand, this.modifyOffset.bind(this)],
[Commands.CommandType.OffsetCommand, this.modifyOffset],
[Commands.CommandType.ClearImageBufferCommand, () => this.formStartCommand],
[Commands.CommandType.CutNowCommand, () => this.encodeCommand('C')],
// EPL uses an on/off style for form backup, it'll remain off until reenabled.
Expand Down Expand Up @@ -95,7 +95,7 @@ export class EplPrinterCommandSet extends PrinterCommandSet {
}
}

public encodeCommand(str: string, withNewline = true): Uint8Array {
public encodeCommand(str = '', withNewline = true): Uint8Array {
// Every command in EPL ends with a newline.
return this.encoder.encode(str + (withNewline ? '\r\n' : ''));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Printers/Languages/PrinterCommandSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type RawCommandForm = { commands: Array<Commands.IPrinterCommand>; withinForm: b

export abstract class PrinterCommandSet {
/** Encode a raw string command into a Uint8Array according to the command language rules. */
public abstract encodeCommand(str: string): Uint8Array;
public abstract encodeCommand(str?: string, withNewline?: boolean): Uint8Array;

private readonly _noop = new Uint8Array();
/** Get an empty command to be used as a no-op. */
Expand Down Expand Up @@ -94,7 +94,7 @@ export abstract class PrinterCommandSet {
}
return this.combineCommands(accumulator as Uint8Array, cmd);
// We start with an explicit newline, to avoid possible previous commands partially sent
}, this.encodeCommand(''));
}, this.encodeCommand());

const out = new CompiledDocument(this.commandLanguage, effects, buffer);
return Object.freeze(out);
Expand Down
2 changes: 1 addition & 1 deletion src/Printers/Languages/ZplPrinterCommandSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class ZplPrinterCommandSet extends PrinterCommandSet {
return this.encodeCommand('\n^XZ\n');
}

encodeCommand(str: string, withNewline = true): Uint8Array {
encodeCommand(str = '', withNewline = true): Uint8Array {
// TODO: ZPL supports omitting the newline, figure out a clever way to
// handle situations where newlines are optional to reduce line noise.
return this.encoder.encode(str + (withNewline ? '\n' : ''));
Expand Down