From 22b54eec9e43aa3ac27c6a29854ecdf1d0bc1dd0 Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Sun, 31 Mar 2024 01:15:08 +0300 Subject: [PATCH] docs: udpate docs --- README.md | 6 +++--- lib/src/message.dart | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 01c7534..e20933e 100644 --- a/README.md +++ b/README.md @@ -112,9 +112,9 @@ inside a message object using the `coloredText` property: ```dart void handleMessage(Message msg) { for (final segment in msg.coloredText) { - print('Uncolored: ${msg.text}'); - print('Foreground: ${msg.fgColor}'); - print('Background: ${msg.bgColor}'); + print('Uncolored: ${segment.text}'); + print('Foreground: ${segment.fgColor}'); + print('Background: ${segment.bgColor}'); print('Colored for terminal: ${segment.formatted}'); } } diff --git a/lib/src/message.dart b/lib/src/message.dart index b2d9cae..7f36e14 100644 --- a/lib/src/message.dart +++ b/lib/src/message.dart @@ -4,9 +4,19 @@ import 'parser.dart'; import 'symbols.dart'; class Message { + /// The raw bytes of the message final List bytes; + + /// The plaintext section of the message late final String text; + + /// The list of command bytes in the message late final List> commands; + + /// The list of color tokens in the message. Each token contains the original text + /// and color information + /// + /// See [ColorToken] for more information late final List coloredText; Message(this.bytes) { @@ -76,10 +86,13 @@ class Message { return toDebugString(); } + /// Used for debugging - returns the message as a string with all commands in a human + /// readable format followed by a newline, then the text String toDebugString() { return '${commands.map((e) => e.map((x) => symbolMap[x] ?? x)).join(' ')}$lf$text'; } + /// Get the index of the first byte that is not part of a command int get firstLiteralByteIndex { if (bytes.isEmpty) { return 0;