Commit c4025e03 authored by Andrey's avatar Andrey

Added emptyLines function. Updated example.

parent fcfd5f77
...@@ -2,7 +2,13 @@ import 'package:esc_pos_printer/esc_pos_printer.dart'; ...@@ -2,7 +2,13 @@ import 'package:esc_pos_printer/esc_pos_printer.dart';
main() { main() {
Printer.connect('192.168.0.123').then((printer) { Printer.connect('192.168.0.123').then((printer) {
printer.println('hello world :)'); printer.println('Normal text');
printer.println('Bold text', bold: true);
printer.println('Reverse text', reverse: true);
printer.println('Underlined text', underline: true);
printer.println('Align left', align: TextAlign.left);
printer.println('Align center', align: TextAlign.center);
printer.println('Align right', align: TextAlign.right);
printer.cut(); printer.cut();
......
...@@ -40,30 +40,15 @@ class Printer { ...@@ -40,30 +40,15 @@ class Printer {
_socket.destroy(); _socket.destroy();
} }
// void writeAll(Iterable objects, [String separator = '']) {
// socket.writeAll(objects, separator);
// }
// void writeLine([Object obj = '']) {
// socket.writeln(obj);
// }
// void write(Object obj) {
// socket.write(obj);
// }
// TODO charHeight, charWidth range ?
// TODO should be ended by \n
void println( void println(
Object text, { String text, {
bool bold = false, bool bold = false,
bool reverse = false, bool reverse = false,
bool underline = false, bool underline = false,
TextAlign align = TextAlign.left, TextAlign align = TextAlign.left,
int charHeight = -1, int charHeight = -1, // TODO replace by font size
int charWidth = -1, int charWidth = -1,
int linesAfter = -1, int linesAfter = 0,
}) { }) {
_socket.write(bold ? cBoldOn : cBoldOff); _socket.write(bold ? cBoldOn : cBoldOff);
_socket.write(reverse ? cReverseOn : cReverseOff); _socket.write(reverse ? cReverseOn : cReverseOff);
...@@ -78,10 +63,7 @@ class Printer { ...@@ -78,10 +63,7 @@ class Printer {
} }
_socket.writeln(text); _socket.writeln(text);
emptyLines(linesAfter);
feed(linesAfter);
// reset all to default
reset(); reset();
} }
...@@ -89,6 +71,12 @@ class Printer { ...@@ -89,6 +71,12 @@ class Printer {
_socket.write(cInit); _socket.write(cInit);
} }
void emptyLines(int n) {
if (n > 0) {
_socket.write(List.filled(n, '\n').join());
}
}
void feed(int n) { void feed(int n) {
if (n >= 0 && n <= 255) { if (n >= 0 && n <= 255) {
_socket.writeAll([cFeedN, n.toString()]); _socket.writeAll([cFeedN, n.toString()]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment