Vendor pristine xterm.dart 4.0.0 under app/third_party/xterm
Unmodified copy of lib/, LICENSE (MIT), pubspec.yaml and CHANGELOG.md from pub.dev xterm 4.0.0; the upstream README is kept as UPSTREAM_README.md. Committed on its own so later patches are reviewable as diffs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+403
@@ -0,0 +1,403 @@
|
||||
// ignore_for_file: constant_identifier_names
|
||||
|
||||
abstract class Ascii {
|
||||
/*
|
||||
* Helper functions
|
||||
*/
|
||||
|
||||
static bool isNonPrintable(int c) {
|
||||
return c < 32 || c == 127;
|
||||
}
|
||||
|
||||
/*
|
||||
* Non-printable ASCII characters
|
||||
*/
|
||||
|
||||
/// Null character
|
||||
static const NULL = 00;
|
||||
|
||||
/// Start of Header
|
||||
static const SOH = 01;
|
||||
|
||||
/// Start of Text
|
||||
static const STX = 02;
|
||||
|
||||
/// End of Text, hearts card suit
|
||||
static const ETX = 03;
|
||||
|
||||
/// End of Transmission, diamonds card suit
|
||||
static const EOT = 04;
|
||||
|
||||
/// Enquiry, clubs card suit
|
||||
static const ENQ = 05;
|
||||
|
||||
/// Acknowledgement, spade card suit
|
||||
static const ACK = 06;
|
||||
|
||||
/// Bell
|
||||
static const BEL = 07;
|
||||
|
||||
/// Backspace
|
||||
static const BS = 08;
|
||||
|
||||
/// Horizontal Tab
|
||||
static const HT = 09;
|
||||
|
||||
/// Line feed
|
||||
static const LF = 10;
|
||||
|
||||
/// Vertical Tab, male symbol, symbol for Mars
|
||||
static const VT = 11;
|
||||
|
||||
/// Form feed, female symbol, symbol for Venus
|
||||
static const FF = 12;
|
||||
|
||||
/// Carriage return
|
||||
static const CR = 13;
|
||||
|
||||
/// Shift Out
|
||||
static const SO = 14;
|
||||
|
||||
/// Shift In
|
||||
static const SI = 15;
|
||||
|
||||
/// Data link escape
|
||||
static const DLE = 16;
|
||||
|
||||
/// Device control 1
|
||||
static const DC1 = 17;
|
||||
|
||||
/// Device control 2
|
||||
static const DC2 = 18;
|
||||
|
||||
/// Device control 3
|
||||
static const DC3 = 19;
|
||||
|
||||
/// Device control 4
|
||||
static const DC4 = 20;
|
||||
|
||||
/// NAK Negative-acknowledge
|
||||
static const NAK = 21;
|
||||
|
||||
/// Synchronous idle
|
||||
static const SYN = 22;
|
||||
|
||||
/// End of trans. block
|
||||
static const ETB = 23;
|
||||
|
||||
/// Cancel
|
||||
static const CAN = 24;
|
||||
|
||||
/// End of medium
|
||||
static const EM = 25;
|
||||
|
||||
/// Substitute
|
||||
static const SUB = 26;
|
||||
|
||||
/// Escape
|
||||
static const ESC = 27;
|
||||
|
||||
/// File separator
|
||||
static const FS = 28;
|
||||
|
||||
/// Group separator
|
||||
static const GS = 29;
|
||||
|
||||
/// Record separator
|
||||
static const RS = 30;
|
||||
|
||||
/// Unit separator
|
||||
static const US = 31;
|
||||
|
||||
/// Delete
|
||||
static const DEL = 127;
|
||||
|
||||
/*
|
||||
* Printable ASCII characters
|
||||
*/
|
||||
|
||||
/// Space " "
|
||||
static const space = 32;
|
||||
|
||||
/// Exclamation mark "!"
|
||||
static const exclamationMark = 33;
|
||||
|
||||
/// Double quotes '"'
|
||||
static const doubleQuotes = 34;
|
||||
|
||||
/// Number sign '#'
|
||||
static const numberSign = 35;
|
||||
|
||||
/// Dollar sign '$'
|
||||
static const dollarSign = 36;
|
||||
|
||||
/// Percent sign '%'
|
||||
static const percentSign = 37;
|
||||
|
||||
/// Ampersand '&'
|
||||
static const ampersand = 38;
|
||||
|
||||
/// Single quote "'"
|
||||
static const singleQuote = 39;
|
||||
|
||||
/// round brackets or parentheses, opening round bracket '('
|
||||
static const openParentheses = 40;
|
||||
|
||||
/// parentheses or round brackets, closing parentheses ')'
|
||||
static const closeParentheses = 41;
|
||||
|
||||
/// Asterisk '*'
|
||||
static const asterisk = 42;
|
||||
|
||||
/// Plus sign '+'
|
||||
static const plus = 43;
|
||||
|
||||
/// Comma ","
|
||||
static const comma = 44;
|
||||
|
||||
/// Hyphen , minus sign '-'
|
||||
static const minus = 45;
|
||||
|
||||
/// Dot, full stop '.'
|
||||
static const dot = 46;
|
||||
|
||||
/// Slash , forward slash , fraction bar , division slash '/'
|
||||
static const slash = 47;
|
||||
|
||||
/// number zero
|
||||
static const num0 = 48;
|
||||
|
||||
/// number one
|
||||
static const num1 = 49;
|
||||
|
||||
/// number two
|
||||
static const num2 = 50;
|
||||
|
||||
/// number three
|
||||
static const num3 = 51;
|
||||
|
||||
/// number four
|
||||
static const num4 = 52;
|
||||
|
||||
/// number five
|
||||
static const num5 = 53;
|
||||
|
||||
/// number six
|
||||
static const num6 = 54;
|
||||
|
||||
/// number seven
|
||||
static const num7 = 55;
|
||||
|
||||
/// number eight
|
||||
static const num8 = 56;
|
||||
|
||||
/// number nine
|
||||
static const num9 = 57;
|
||||
|
||||
/// Colon ':'
|
||||
static const colon = 58;
|
||||
|
||||
/// Semicolon ';'
|
||||
static const semicolon = 59;
|
||||
|
||||
/// Less-than sign '<'
|
||||
static const lessThan = 60;
|
||||
|
||||
/// Equals sign '='
|
||||
static const equal = 61;
|
||||
|
||||
/// Greater-than sign ; Inequality sign '>'
|
||||
static const greaterThan = 62;
|
||||
|
||||
/// Question mark '?'
|
||||
static const questionMark = 63;
|
||||
|
||||
/// At sign '@'
|
||||
static const atSign = 64;
|
||||
|
||||
/// Capital letter A
|
||||
static const A = 65;
|
||||
|
||||
/// Capital letter B
|
||||
static const B = 66;
|
||||
|
||||
/// Capital letter C
|
||||
static const C = 67;
|
||||
|
||||
/// Capital letter D
|
||||
static const D = 68;
|
||||
|
||||
/// Capital letter E
|
||||
static const E = 69;
|
||||
|
||||
/// Capital letter F
|
||||
static const F = 70;
|
||||
|
||||
/// Capital letter G
|
||||
static const G = 71;
|
||||
|
||||
/// Capital letter H
|
||||
static const H = 72;
|
||||
|
||||
/// Capital letter I
|
||||
static const I = 73;
|
||||
|
||||
/// Capital letter J
|
||||
static const J = 74;
|
||||
|
||||
/// Capital letter K
|
||||
static const K = 75;
|
||||
|
||||
/// Capital letter L
|
||||
static const L = 76;
|
||||
|
||||
/// Capital letter M
|
||||
static const M = 77;
|
||||
|
||||
/// Capital letter N
|
||||
static const N = 78;
|
||||
|
||||
/// Capital letter O
|
||||
static const O = 79;
|
||||
|
||||
/// Capital letter P
|
||||
static const P = 80;
|
||||
|
||||
/// Capital letter Q
|
||||
static const Q = 81;
|
||||
|
||||
/// Capital letter R
|
||||
static const R = 82;
|
||||
|
||||
/// Capital letter S
|
||||
static const S = 83;
|
||||
|
||||
/// Capital letter T
|
||||
static const T = 84;
|
||||
|
||||
/// Capital letter U
|
||||
static const U = 85;
|
||||
|
||||
/// Capital letter V
|
||||
static const V = 86;
|
||||
|
||||
/// Capital letter W
|
||||
static const W = 87;
|
||||
|
||||
/// Capital letter X
|
||||
static const X = 88;
|
||||
|
||||
/// Capital letter Y
|
||||
static const Y = 89;
|
||||
|
||||
/// Capital letter Z
|
||||
static const Z = 90;
|
||||
|
||||
/// square brackets or box brackets, opening bracket '['
|
||||
static const openBracket = 91;
|
||||
|
||||
/// Backslash , reverse slash '\\'
|
||||
static const backslash = 92;
|
||||
|
||||
/// box brackets or square brackets, closing bracket ']'
|
||||
static const closeBracket = 93;
|
||||
|
||||
/// Circumflex accent or Caret '^'
|
||||
static const caret = 94;
|
||||
|
||||
/// underscore , understrike , underbar or low line '_'
|
||||
static const underscore = 95;
|
||||
|
||||
/// Grave accent '`'
|
||||
static const graveAccent = 96;
|
||||
|
||||
/// Lowercase letter a , minuscule a
|
||||
static const a = 97;
|
||||
|
||||
/// Lowercase letter b , minuscule b
|
||||
static const b = 98;
|
||||
|
||||
/// Lowercase letter c , minuscule c
|
||||
static const c = 99;
|
||||
|
||||
/// Lowercase letter d , minuscule d
|
||||
static const d = 100;
|
||||
|
||||
/// Lowercase letter e , minuscule e
|
||||
static const e = 101;
|
||||
|
||||
/// Lowercase letter f , minuscule f
|
||||
static const f = 102;
|
||||
|
||||
/// Lowercase letter g , minuscule g
|
||||
static const g = 103;
|
||||
|
||||
/// Lowercase letter h , minuscule h
|
||||
static const h = 104;
|
||||
|
||||
/// Lowercase letter i , minuscule i
|
||||
static const i = 105;
|
||||
|
||||
/// Lowercase letter j , minuscule j
|
||||
static const j = 106;
|
||||
|
||||
/// Lowercase letter k , minuscule k
|
||||
static const k = 107;
|
||||
|
||||
/// Lowercase letter l , minuscule l
|
||||
static const l = 108;
|
||||
|
||||
/// Lowercase letter m , minuscule m
|
||||
static const m = 109;
|
||||
|
||||
/// Lowercase letter n , minuscule n
|
||||
static const n = 110;
|
||||
|
||||
/// Lowercase letter o , minuscule o
|
||||
static const o = 111;
|
||||
|
||||
/// Lowercase letter p , minuscule p
|
||||
static const p = 112;
|
||||
|
||||
/// Lowercase letter q , minuscule q
|
||||
static const q = 113;
|
||||
|
||||
/// Lowercase letter r , minuscule r
|
||||
static const r = 114;
|
||||
|
||||
/// Lowercase letter s , minuscule s
|
||||
static const s = 115;
|
||||
|
||||
/// Lowercase letter t , minuscule t
|
||||
static const t = 116;
|
||||
|
||||
/// Lowercase letter u , minuscule u
|
||||
static const u = 117;
|
||||
|
||||
/// Lowercase letter v , minuscule v
|
||||
static const v = 118;
|
||||
|
||||
/// Lowercase letter w , minuscule w
|
||||
static const w = 119;
|
||||
|
||||
/// Lowercase letter x , minuscule x
|
||||
static const x = 120;
|
||||
|
||||
/// Lowercase letter y , minuscule y
|
||||
static const y = 121;
|
||||
|
||||
/// Lowercase letter z , minuscule z
|
||||
static const z = 122;
|
||||
|
||||
/// braces or curly brackets, opening braces '{'
|
||||
static const openBrace = 123;
|
||||
|
||||
/// vertical-bar, vbar, vertical line or vertical slash '|'
|
||||
static const verticalBar = 124;
|
||||
|
||||
/// curly brackets or braces, closing curly brackets '}'
|
||||
static const closeBrace = 125;
|
||||
|
||||
/// Tilde ; swung dash '~'
|
||||
static const tilde = 126;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
import 'dart:collection';
|
||||
|
||||
class ByteConsumer {
|
||||
final _queue = ListQueue<List<int>>();
|
||||
|
||||
final _consumed = ListQueue<List<int>>();
|
||||
|
||||
var _currentOffset = 0;
|
||||
|
||||
var _length = 0;
|
||||
|
||||
var _totalConsumed = 0;
|
||||
|
||||
void add(String data) {
|
||||
if (data.isEmpty) return;
|
||||
final runes = data.runes.toList(growable: false);
|
||||
_queue.addLast(runes);
|
||||
_length += runes.length;
|
||||
}
|
||||
|
||||
int peek() {
|
||||
final data = _queue.first;
|
||||
if (_currentOffset < data.length) {
|
||||
return data[_currentOffset];
|
||||
} else {
|
||||
final result = consume();
|
||||
rollback();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
int consume() {
|
||||
final data = _queue.first;
|
||||
|
||||
if (_currentOffset >= data.length) {
|
||||
_consumed.add(_queue.removeFirst());
|
||||
_currentOffset -= data.length;
|
||||
return consume();
|
||||
}
|
||||
|
||||
_length--;
|
||||
_totalConsumed++;
|
||||
return data[_currentOffset++];
|
||||
}
|
||||
|
||||
/// Rolls back the last [n] call.
|
||||
void rollback([int n = 1]) {
|
||||
_currentOffset -= n;
|
||||
_totalConsumed -= n;
|
||||
_length += n;
|
||||
while (_currentOffset < 0) {
|
||||
final rollback = _consumed.removeLast();
|
||||
_queue.addFirst(rollback);
|
||||
_currentOffset += rollback.length;
|
||||
}
|
||||
}
|
||||
|
||||
/// Rolls back to the state when this consumer had [length] bytes.
|
||||
void rollbackTo(int length) {
|
||||
rollback(length - _length);
|
||||
}
|
||||
|
||||
int get length => _length;
|
||||
|
||||
int get totalConsumed => _totalConsumed;
|
||||
|
||||
bool get isEmpty => _length == 0;
|
||||
|
||||
bool get isNotEmpty => _length != 0;
|
||||
|
||||
/// Unreferences data blocks that have been consumed. After calling this
|
||||
/// method, the consumer will not be able to roll back to consumed blocks.
|
||||
void unrefConsumedBlocks() {
|
||||
_consumed.clear();
|
||||
}
|
||||
|
||||
/// Resets the consumer to its initial state.
|
||||
void reset() {
|
||||
_queue.clear();
|
||||
_consumed.clear();
|
||||
_currentOffset = 0;
|
||||
_totalConsumed = 0;
|
||||
_length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// void main() {
|
||||
// final consumer = ByteConsumer();
|
||||
// consumer.add(Uint8List.fromList([1, 2, 3]));
|
||||
// consumer.add(Uint8List.fromList([4, 5, 6]));
|
||||
|
||||
// while (consumer.isNotEmpty) {
|
||||
// print(consumer.consume());
|
||||
// }
|
||||
|
||||
// consumer.rollback(5);
|
||||
|
||||
// while (consumer.isNotEmpty) {
|
||||
// print(consumer.consume());
|
||||
// }
|
||||
|
||||
// consumer.rollbackTo(3);
|
||||
|
||||
// while (consumer.isNotEmpty) {
|
||||
// print(consumer.consume());
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,5 @@
|
||||
extension StringCharCode on String {
|
||||
int get charCode {
|
||||
return codeUnitAt(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
/// A circular buffer in which elements know their index in the buffer.
|
||||
class IndexAwareCircularBuffer<T extends IndexedItem> {
|
||||
/// Creates a new circular list with the specified [maxLength].
|
||||
IndexAwareCircularBuffer(int maxLength)
|
||||
: _array = List<T?>.filled(maxLength, null);
|
||||
|
||||
/// The backing array for this list. Length is always equal to [maxLength].
|
||||
late List<T?> _array;
|
||||
|
||||
/// The number of elements in the list. This is always less than or equal to
|
||||
/// [maxLength].
|
||||
var _length = 0;
|
||||
|
||||
/// The index of the first element in [_array].
|
||||
var _startIndex = 0;
|
||||
|
||||
/// The start index of this list, including items that has been dropped in
|
||||
/// overflow
|
||||
var _absoluteStartIndex = 0;
|
||||
|
||||
/// Gets the cyclic index for the specified regular index. The cyclic index
|
||||
/// can then be used on the backing array to get the element associated with
|
||||
/// the regular index.
|
||||
@pragma('vm:prefer-inline')
|
||||
int _getCyclicIndex(int index) {
|
||||
return (_startIndex + index) % _array.length;
|
||||
}
|
||||
|
||||
/// Removes the element at [index] from the list.
|
||||
@pragma('vm:prefer-inline')
|
||||
void _dropChild(int index) {
|
||||
final cyclicIndex = _getCyclicIndex(index);
|
||||
_array[cyclicIndex]?._detach();
|
||||
_array[cyclicIndex] = null;
|
||||
}
|
||||
|
||||
/// Adds the specified [child] to the list at the specified [index].
|
||||
@pragma('vm:prefer-inline')
|
||||
void _adoptChild(int index, T child) {
|
||||
final cyclicIndex = _getCyclicIndex(index);
|
||||
_array[cyclicIndex]?._detach();
|
||||
_array[cyclicIndex] = child.._attach(this, index);
|
||||
}
|
||||
|
||||
/// Moves the element at [fromIndex] to [toIndex]. Both indexes should be
|
||||
/// less than [maxLength].
|
||||
@pragma('vm:prefer-inline')
|
||||
void _moveChild(int fromIndex, int toIndex) {
|
||||
final fromCyclicIndex = _getCyclicIndex(fromIndex);
|
||||
final toCyclicIndex = _getCyclicIndex(toIndex);
|
||||
_array[toCyclicIndex]?._detach();
|
||||
_array[toCyclicIndex] = _array[fromCyclicIndex]?.._move(toIndex);
|
||||
_array[fromCyclicIndex] = null;
|
||||
}
|
||||
|
||||
/// Gets the element at the specified [index] in the list.
|
||||
@pragma('vm:prefer-inline')
|
||||
T? _getChild(int index) {
|
||||
return _array[_getCyclicIndex(index)];
|
||||
}
|
||||
|
||||
/// The number of elements that can be stored in the list.
|
||||
int get maxLength {
|
||||
return _array.length;
|
||||
}
|
||||
|
||||
/// Sets the number of elements that can be stored in the list. This operation
|
||||
/// is relatively expensive, as it requires the backing array to be
|
||||
/// reallocated.
|
||||
set maxLength(int value) {
|
||||
if (value <= 0) {
|
||||
throw ArgumentError.value(value, 'value', "maxLength can't be negative!");
|
||||
}
|
||||
|
||||
if (value == _array.length) return;
|
||||
|
||||
// Reconstruct array, starting at index 0. Only transfer values from the
|
||||
// indexes 0 to length.
|
||||
final newArray = List<T?>.generate(
|
||||
value,
|
||||
(index) => index < _length ? _getChild(index) : null,
|
||||
);
|
||||
|
||||
_startIndex = 0;
|
||||
_array = newArray;
|
||||
}
|
||||
|
||||
/// Number of elements in the list.
|
||||
int get length {
|
||||
return _length;
|
||||
}
|
||||
|
||||
/// Iterates over the list and calls [callback] for each element.
|
||||
void forEach(void Function(T item) callback) {
|
||||
final length = _length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
callback(_getChild(i)!);
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the element at the specified [index] in the list. Throws if the
|
||||
/// index is out of bounds.
|
||||
T operator [](int index) {
|
||||
RangeError.checkValueInInterval(index, 0, length - 1, 'index');
|
||||
return _getChild(index)!;
|
||||
}
|
||||
|
||||
/// Sets the element at the specified [index] in the list. Throws if the
|
||||
/// index is out of bounds.
|
||||
operator []=(int index, T value) {
|
||||
RangeError.checkValueInInterval(index, 0, length - 1, 'index');
|
||||
_adoptChild(index, value);
|
||||
}
|
||||
|
||||
/// Removes all elements from the list.
|
||||
void clear() {
|
||||
for (var i = 0; i < _length; i++) {
|
||||
_dropChild(i);
|
||||
}
|
||||
_startIndex = 0;
|
||||
_length = 0;
|
||||
}
|
||||
|
||||
/// Adds all elements in [items] to the list.
|
||||
void pushAll(Iterable<T> items) {
|
||||
for (var element in items) {
|
||||
push(element);
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds [value] to the end of the list. May cause the first element to be
|
||||
/// trimmed if the list is full.
|
||||
void push(T value) {
|
||||
_adoptChild(_length, value);
|
||||
|
||||
if (_length == _array.length) {
|
||||
// When the list is full, we trim the first element
|
||||
_startIndex++;
|
||||
_absoluteStartIndex++;
|
||||
if (_startIndex == _array.length) {
|
||||
_startIndex = 0;
|
||||
}
|
||||
} else {
|
||||
// When the list is not full, we just increase the length
|
||||
_length++;
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes and returns the last value on the list, throws if the list is
|
||||
/// empty.
|
||||
T pop() {
|
||||
assert(_length > 0, 'Cannot pop from an empty list');
|
||||
final result = _getChild(_length - 1);
|
||||
_dropChild(_length - 1);
|
||||
_length--;
|
||||
return result!;
|
||||
}
|
||||
|
||||
/// Deletes [count] elements starting at [index], shifting all elements after
|
||||
/// [index] to the left.
|
||||
void remove(int index, [int count = 1]) {
|
||||
if (count > 0) {
|
||||
if (index + count >= _length) {
|
||||
count = _length - index;
|
||||
}
|
||||
for (var i = index; i < _length - count; i++) {
|
||||
_moveChild(i + count, i);
|
||||
}
|
||||
for (var i = _length - count; i < _length; i++) {
|
||||
_dropChild(i);
|
||||
}
|
||||
_length -= count;
|
||||
}
|
||||
}
|
||||
|
||||
/// Inserts [item] at [index], shifting all elements after [index] to the
|
||||
/// right. May cause the first element to be trimmed if the list is full.
|
||||
void insert(int index, T item) {
|
||||
RangeError.checkValueInInterval(index, 0, _length, 'index');
|
||||
|
||||
if (index == _length) {
|
||||
return push(item);
|
||||
}
|
||||
|
||||
if (index == 0 && _length >= _array.length) {
|
||||
// when something is inserted at index 0 and the list is full then
|
||||
// the new value immediately gets removed => nothing changes
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = _length - 1; i >= index; i--) {
|
||||
_moveChild(i, i + 1);
|
||||
}
|
||||
|
||||
_adoptChild(index, item);
|
||||
|
||||
if (_length >= _array.length) {
|
||||
_startIndex += 1;
|
||||
_absoluteStartIndex += 1;
|
||||
} else {
|
||||
_length++;
|
||||
}
|
||||
}
|
||||
|
||||
/// Inserts [items] at [index] in order.
|
||||
void insertAll(int index, List<T> items) {
|
||||
for (var i = items.length - 1; i >= 0; i--) {
|
||||
insert(index, items[i]);
|
||||
// when the list is full then we have to move the index down
|
||||
// as newly inserted values remove values with a lower index
|
||||
if (_length >= _array.length) {
|
||||
index--;
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes [count] elements starting at [index], shifting all elements after
|
||||
/// [index] to the left.
|
||||
///
|
||||
/// This method is cheap since it does not actually modify the list, but
|
||||
/// instead just adjusts the start index and length.
|
||||
void trimStart(int count) {
|
||||
if (count > _length) count = _length;
|
||||
_startIndex += count;
|
||||
_startIndex %= _array.length;
|
||||
_length -= count;
|
||||
}
|
||||
|
||||
/// Replaces all elements in the list with [replacement].
|
||||
void replaceWith(List<T> replacement) {
|
||||
for (var i = 0; i < _length; i++) {
|
||||
_dropChild(i);
|
||||
}
|
||||
|
||||
var copyStart = 0;
|
||||
if (replacement.length > maxLength) {
|
||||
copyStart = replacement.length - maxLength;
|
||||
}
|
||||
|
||||
for (var i = 0; i < copyStart; i++) {
|
||||
_dropChild(i);
|
||||
}
|
||||
|
||||
final copyLength = replacement.length - copyStart;
|
||||
for (var i = 0; i < copyLength; i++) {
|
||||
_adoptChild(i, replacement[copyStart + i]);
|
||||
}
|
||||
|
||||
_startIndex = 0;
|
||||
_length = copyLength;
|
||||
}
|
||||
|
||||
/// Replaces the element at [index] with [value] and returns the replaced
|
||||
/// item.
|
||||
T swap(int index, T value) {
|
||||
final result = _getChild(index);
|
||||
_adoptChild(index, value);
|
||||
return result!;
|
||||
}
|
||||
|
||||
/// Whether adding another element would cause the first element to be
|
||||
/// trimmed.
|
||||
bool get isFull => length == maxLength;
|
||||
|
||||
/// Returns a list containing all elements in the list.
|
||||
List<T> toList() {
|
||||
return List<T>.generate(length, (index) => this[index]);
|
||||
}
|
||||
|
||||
String debugDump() {
|
||||
final buffer = StringBuffer();
|
||||
buffer.writeln('CircularList:');
|
||||
for (var i = 0; i < _length; i++) {
|
||||
final child = _getChild(i);
|
||||
buffer.writeln(' $i: $child');
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
mixin IndexedItem {
|
||||
IndexAwareCircularBuffer? _owner;
|
||||
|
||||
int? _absoluteIndex;
|
||||
|
||||
/// The index of this item in the buffer. Must only be accessed when
|
||||
/// [attached] is true.
|
||||
int get index => _absoluteIndex! - _owner!._absoluteStartIndex;
|
||||
|
||||
/// Whether this item is currently stored in a buffer.
|
||||
bool get attached => _owner != null;
|
||||
|
||||
/// Sets the owner and index of this item. This is called by the buffer when
|
||||
/// the item is adopted.
|
||||
void _attach(IndexAwareCircularBuffer owner, int index) {
|
||||
_owner = owner;
|
||||
_absoluteIndex = owner._absoluteStartIndex + index;
|
||||
}
|
||||
|
||||
/// Marks this item as detached from a buffer. This is called after the item
|
||||
/// has been removed from the buffer.
|
||||
void _detach() {
|
||||
_owner = null;
|
||||
_absoluteIndex = null;
|
||||
}
|
||||
|
||||
/// Moves this item to [newIndex] in the buffer.
|
||||
void _move(int newIndex) {
|
||||
assert(attached);
|
||||
_absoluteIndex = _owner!._absoluteStartIndex + newIndex;
|
||||
}
|
||||
}
|
||||
+595
@@ -0,0 +1,595 @@
|
||||
import 'package:xterm/src/core/escape/handler.dart';
|
||||
import 'package:xterm/src/core/escape/parser.dart';
|
||||
import 'package:xterm/src/core/mouse/mode.dart';
|
||||
import 'package:xterm/src/base/observable.dart';
|
||||
|
||||
class TerminalCommand {
|
||||
TerminalCommand(
|
||||
this.start,
|
||||
this.end,
|
||||
this.chars,
|
||||
this.escapedChars,
|
||||
this.explanation,
|
||||
this.error,
|
||||
);
|
||||
|
||||
final int start;
|
||||
|
||||
final int end;
|
||||
|
||||
final String chars;
|
||||
|
||||
final String escapedChars;
|
||||
|
||||
final List<String> explanation;
|
||||
|
||||
final bool error;
|
||||
}
|
||||
|
||||
class TerminalDebugger with Observable {
|
||||
late final _parser = EscapeParser(_handler);
|
||||
|
||||
late final _handler = _TerminalDebuggerHandler(recordCommand);
|
||||
|
||||
final recorded = <int>[];
|
||||
|
||||
final commands = <TerminalCommand>[];
|
||||
|
||||
void write(String chunk) {
|
||||
recorded.addAll(chunk.runes);
|
||||
_parser.write(chunk);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void recordCommand(String explanation, {bool error = false}) {
|
||||
final start = _parser.tokenBegin;
|
||||
final end = _parser.tokenEnd;
|
||||
|
||||
if (commands.isNotEmpty && commands.last.end == end) {
|
||||
commands.last.explanation.add(explanation);
|
||||
} else {
|
||||
final charCodes = recorded.sublist(start, end);
|
||||
final chars = String.fromCharCodes(charCodes);
|
||||
final escapedChars = _escape(chars);
|
||||
commands.add(
|
||||
TerminalCommand(start, end, chars, escapedChars, [explanation], error),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String getRecord(TerminalCommand command) {
|
||||
final charCodes = recorded.sublist(0, command.end);
|
||||
return String.fromCharCodes(charCodes);
|
||||
}
|
||||
|
||||
static String _escape(String chars) {
|
||||
final escaped = StringBuffer();
|
||||
for (final char in chars.runes) {
|
||||
if (char == 0x1b) {
|
||||
escaped.write('ESC');
|
||||
} else if (char < 32) {
|
||||
escaped.write('^0x${char.toRadixString(16)}');
|
||||
} else if (char == 127) {
|
||||
escaped.write('^?');
|
||||
} else {
|
||||
escaped.writeCharCode(char);
|
||||
}
|
||||
}
|
||||
return escaped.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class _TerminalDebuggerHandler implements EscapeHandler {
|
||||
_TerminalDebuggerHandler(this.onCommand);
|
||||
|
||||
final void Function(String explanation, {bool error}) onCommand;
|
||||
|
||||
@override
|
||||
void writeChar(int char) {
|
||||
onCommand('writeChar(${String.fromCharCode(char)})');
|
||||
}
|
||||
|
||||
/* SBC */
|
||||
|
||||
@override
|
||||
void bell() {
|
||||
onCommand('bell');
|
||||
}
|
||||
|
||||
@override
|
||||
void backspaceReturn() {
|
||||
onCommand('backspaceReturn');
|
||||
}
|
||||
|
||||
@override
|
||||
void tab() {
|
||||
onCommand('tab');
|
||||
}
|
||||
|
||||
@override
|
||||
void lineFeed() {
|
||||
onCommand('lineFeed');
|
||||
}
|
||||
|
||||
@override
|
||||
void carriageReturn() {
|
||||
onCommand('carriageReturn');
|
||||
}
|
||||
|
||||
@override
|
||||
void shiftOut() {
|
||||
onCommand('shiftOut');
|
||||
}
|
||||
|
||||
@override
|
||||
void shiftIn() {
|
||||
onCommand('shiftIn');
|
||||
}
|
||||
|
||||
@override
|
||||
void unknownSBC(int char) {
|
||||
onCommand('unkownSBC(${String.fromCharCode(char)})', error: true);
|
||||
}
|
||||
|
||||
/* ANSI sequence */
|
||||
|
||||
@override
|
||||
void saveCursor() {
|
||||
onCommand('saveCursor');
|
||||
}
|
||||
|
||||
@override
|
||||
void restoreCursor() {
|
||||
onCommand('restoreCursor');
|
||||
}
|
||||
|
||||
@override
|
||||
void index() {
|
||||
onCommand('index');
|
||||
}
|
||||
|
||||
@override
|
||||
void nextLine() {
|
||||
onCommand('nextLine');
|
||||
}
|
||||
|
||||
@override
|
||||
void setTapStop() {
|
||||
onCommand('setTapStop');
|
||||
}
|
||||
|
||||
@override
|
||||
void reverseIndex() {
|
||||
onCommand('reverseIndex');
|
||||
}
|
||||
|
||||
@override
|
||||
void designateCharset(int charset, int name) {
|
||||
onCommand('designateCharset($charset, $name)');
|
||||
}
|
||||
|
||||
@override
|
||||
void unkownEscape(int char) {
|
||||
onCommand('unkownEscape(${String.fromCharCode(char)})', error: true);
|
||||
}
|
||||
|
||||
/* CSI */
|
||||
|
||||
@override
|
||||
void repeatPreviousCharacter(int count) {
|
||||
onCommand('repeatPreviousCharacter($count)');
|
||||
}
|
||||
|
||||
@override
|
||||
void unknownCSI(int finalByte) {
|
||||
onCommand('unkownCSI(${String.fromCharCode(finalByte)})', error: true);
|
||||
}
|
||||
|
||||
@override
|
||||
void setCursor(int x, int y) {
|
||||
onCommand('setCursor($x, $y)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setCursorX(int x) {
|
||||
onCommand('setCursorX($x)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setCursorY(int y) {
|
||||
onCommand('setCursorY($y)');
|
||||
}
|
||||
|
||||
@override
|
||||
void sendPrimaryDeviceAttributes() {
|
||||
onCommand('sendPrimaryDeviceAttributes');
|
||||
}
|
||||
|
||||
@override
|
||||
void clearTabStopUnderCursor() {
|
||||
onCommand('clearTabStopUnderCursor');
|
||||
}
|
||||
|
||||
@override
|
||||
void clearAllTabStops() {
|
||||
onCommand('clearAllTabStops');
|
||||
}
|
||||
|
||||
@override
|
||||
void moveCursorX(int offset) {
|
||||
onCommand('moveCursorX($offset)');
|
||||
}
|
||||
|
||||
@override
|
||||
void moveCursorY(int n) {
|
||||
onCommand('moveCursorY($n)');
|
||||
}
|
||||
|
||||
@override
|
||||
void sendSecondaryDeviceAttributes() {
|
||||
onCommand('sendSecondaryDeviceAttributes');
|
||||
}
|
||||
|
||||
@override
|
||||
void sendTertiaryDeviceAttributes() {
|
||||
onCommand('sendTertiaryDeviceAttributes');
|
||||
}
|
||||
|
||||
@override
|
||||
void sendOperatingStatus() {
|
||||
onCommand('sendOperatingStatus');
|
||||
}
|
||||
|
||||
@override
|
||||
void sendCursorPosition() {
|
||||
onCommand('sendCursorPosition');
|
||||
}
|
||||
|
||||
@override
|
||||
void setMargins(int i, [int? bottom]) {
|
||||
onCommand('setMargins($i, $bottom)');
|
||||
}
|
||||
|
||||
@override
|
||||
void cursorNextLine(int amount) {
|
||||
onCommand('cursorNextLine($amount)');
|
||||
}
|
||||
|
||||
@override
|
||||
void cursorPrecedingLine(int amount) {
|
||||
onCommand('cursorPrecedingLine($amount)');
|
||||
}
|
||||
|
||||
@override
|
||||
void eraseDisplayBelow() {
|
||||
onCommand('eraseDisplayBelow');
|
||||
}
|
||||
|
||||
@override
|
||||
void eraseDisplayAbove() {
|
||||
onCommand('eraseDisplayAbove');
|
||||
}
|
||||
|
||||
@override
|
||||
void eraseDisplay() {
|
||||
onCommand('eraseDisplay');
|
||||
}
|
||||
|
||||
@override
|
||||
void eraseScrollbackOnly() {
|
||||
onCommand('eraseScrollbackOnly');
|
||||
}
|
||||
|
||||
@override
|
||||
void eraseLineRight() {
|
||||
onCommand('eraseLineRight');
|
||||
}
|
||||
|
||||
@override
|
||||
void eraseLineLeft() {
|
||||
onCommand('eraseLineLeft');
|
||||
}
|
||||
|
||||
@override
|
||||
void eraseLine() {
|
||||
onCommand('eraseLine');
|
||||
}
|
||||
|
||||
@override
|
||||
void insertLines(int amount) {
|
||||
onCommand('insertLines($amount)');
|
||||
}
|
||||
|
||||
@override
|
||||
void deleteLines(int amount) {
|
||||
onCommand('deleteLines($amount)');
|
||||
}
|
||||
|
||||
@override
|
||||
void deleteChars(int amount) {
|
||||
onCommand('deleteChars($amount)');
|
||||
}
|
||||
|
||||
@override
|
||||
void scrollUp(int amount) {
|
||||
onCommand('scrollUp($amount)');
|
||||
}
|
||||
|
||||
@override
|
||||
void scrollDown(int amount) {
|
||||
onCommand('scrollDown($amount)');
|
||||
}
|
||||
|
||||
@override
|
||||
void eraseChars(int amount) {
|
||||
onCommand('eraseChars($amount)');
|
||||
}
|
||||
|
||||
@override
|
||||
void insertBlankChars(int amount) {
|
||||
onCommand('insertBlankChars($amount)');
|
||||
}
|
||||
|
||||
@override
|
||||
void resize(int cols, int rows) {
|
||||
onCommand('resize($cols, $rows)');
|
||||
}
|
||||
|
||||
@override
|
||||
void sendSize() {
|
||||
onCommand('sendSize');
|
||||
}
|
||||
|
||||
/* Modes */
|
||||
|
||||
@override
|
||||
void setInsertMode(bool enabled) {
|
||||
onCommand('setInsertMode($enabled)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setLineFeedMode(bool enabled) {
|
||||
onCommand('setLineFeedMode($enabled)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setUnknownMode(int mode, bool enabled) {
|
||||
onCommand('setUnknownMode($mode, $enabled)', error: true);
|
||||
}
|
||||
|
||||
/* DEC Private modes */
|
||||
|
||||
@override
|
||||
void setCursorKeysMode(bool enabled) {
|
||||
onCommand('setCursorKeysMode($enabled)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setReverseDisplayMode(bool enabled) {
|
||||
onCommand('setReverseDisplayMode($enabled)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setOriginMode(bool enabled) {
|
||||
onCommand('setOriginMode($enabled)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setColumnMode(bool enabled) {
|
||||
onCommand('setColumnMode($enabled)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setAutoWrapMode(bool enabled) {
|
||||
onCommand('setAutoWrapMode($enabled)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setMouseMode(MouseMode mode) {
|
||||
onCommand('setMouseMode($mode)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setCursorBlinkMode(bool enabled) {
|
||||
onCommand('setCursorBlinkMode($enabled)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setCursorVisibleMode(bool enabled) {
|
||||
onCommand('setCursorVisibleMode($enabled)');
|
||||
}
|
||||
|
||||
@override
|
||||
void useAltBuffer() {
|
||||
onCommand('useAltBuffer');
|
||||
}
|
||||
|
||||
@override
|
||||
void useMainBuffer() {
|
||||
onCommand('useMainBuffer');
|
||||
}
|
||||
|
||||
@override
|
||||
void clearAltBuffer() {
|
||||
onCommand('clearAltBuffer');
|
||||
}
|
||||
|
||||
@override
|
||||
void setAppKeypadMode(bool enabled) {
|
||||
onCommand('setAppKeypadMode($enabled)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setReportFocusMode(bool enabled) {
|
||||
onCommand('setReportFocusMode($enabled)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setMouseReportMode(MouseReportMode mode) {
|
||||
onCommand('setMouseReportMode($mode)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setAltBufferMouseScrollMode(bool enabled) {
|
||||
onCommand('setAltBufferMouseScrollMode($enabled)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setBracketedPasteMode(bool enabled) {
|
||||
onCommand('setBracketedPasteMode($enabled)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setUnknownDecMode(int mode, bool enabled) {
|
||||
onCommand('setUnknownDecMode($mode, $enabled)', error: true);
|
||||
}
|
||||
|
||||
/* Select Graphic Rendition (SGR) */
|
||||
|
||||
@override
|
||||
void resetCursorStyle() {
|
||||
onCommand('resetCursorStyle');
|
||||
}
|
||||
|
||||
@override
|
||||
void setCursorBold() {
|
||||
onCommand('setCursorBold');
|
||||
}
|
||||
|
||||
@override
|
||||
void setCursorFaint() {
|
||||
onCommand('setCursorFaint');
|
||||
}
|
||||
|
||||
@override
|
||||
void setCursorItalic() {
|
||||
onCommand('setCursorItalic');
|
||||
}
|
||||
|
||||
@override
|
||||
void setCursorUnderline() {
|
||||
onCommand('setCursorUnderline');
|
||||
}
|
||||
|
||||
@override
|
||||
void setCursorBlink() {
|
||||
onCommand('setCursorBlink');
|
||||
}
|
||||
|
||||
@override
|
||||
void setCursorInverse() {
|
||||
onCommand('setCursorInverse');
|
||||
}
|
||||
|
||||
@override
|
||||
void setCursorInvisible() {
|
||||
onCommand('setCursorInvisible');
|
||||
}
|
||||
|
||||
@override
|
||||
void setCursorStrikethrough() {
|
||||
onCommand('setCursorStrikethrough');
|
||||
}
|
||||
|
||||
@override
|
||||
void unsetCursorBold() {
|
||||
onCommand('unsetCursorBold');
|
||||
}
|
||||
|
||||
@override
|
||||
void unsetCursorFaint() {
|
||||
onCommand('unsetCursorFaint');
|
||||
}
|
||||
|
||||
@override
|
||||
void unsetCursorItalic() {
|
||||
onCommand('unsetCursorItalic');
|
||||
}
|
||||
|
||||
@override
|
||||
void unsetCursorUnderline() {
|
||||
onCommand('unsetCursorUnderline');
|
||||
}
|
||||
|
||||
@override
|
||||
void unsetCursorBlink() {
|
||||
onCommand('unsetCursorBlink');
|
||||
}
|
||||
|
||||
@override
|
||||
void unsetCursorInverse() {
|
||||
onCommand('unsetCursorInverse');
|
||||
}
|
||||
|
||||
@override
|
||||
void unsetCursorInvisible() {
|
||||
onCommand('unsetCursorInvisible');
|
||||
}
|
||||
|
||||
@override
|
||||
void unsetCursorStrikethrough() {
|
||||
onCommand('unsetCursorStrikethrough');
|
||||
}
|
||||
|
||||
@override
|
||||
void setForegroundColor16(int color) {
|
||||
onCommand('setForegroundColor16($color)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setForegroundColor256(int index) {
|
||||
onCommand('setForegroundColor256($index)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setForegroundColorRgb(int r, int g, int b) {
|
||||
onCommand('setForegroundColorRgb($r, $g, $b)');
|
||||
}
|
||||
|
||||
@override
|
||||
void resetForeground() {
|
||||
onCommand('resetForeground');
|
||||
}
|
||||
|
||||
@override
|
||||
void setBackgroundColor16(int color) {
|
||||
onCommand('setBackgroundColor16($color)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setBackgroundColor256(int index) {
|
||||
onCommand('setBackgroundColor256($index)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setBackgroundColorRgb(int r, int g, int b) {
|
||||
onCommand('setBackgroundColorRgb($r, $g, $b)');
|
||||
}
|
||||
|
||||
@override
|
||||
void resetBackground() {
|
||||
onCommand('resetBackground');
|
||||
}
|
||||
|
||||
@override
|
||||
void unsupportedStyle(int param) {
|
||||
onCommand('unsupportedStyle($param)', error: true);
|
||||
}
|
||||
|
||||
/* OSC */
|
||||
|
||||
@override
|
||||
void setTitle(String name) {
|
||||
onCommand('setTitle($name)');
|
||||
}
|
||||
|
||||
@override
|
||||
void setIconName(String name) {
|
||||
onCommand('setIconName($name)');
|
||||
}
|
||||
|
||||
@override
|
||||
void unknownOSC(String code, List<String> args) {
|
||||
onCommand('unknownOSC($code, $args)', error: true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:xterm/src/utils/debugger.dart';
|
||||
|
||||
class TerminalDebuggerView extends StatefulWidget {
|
||||
const TerminalDebuggerView(
|
||||
this.debugger, {
|
||||
super.key,
|
||||
this.scrollController,
|
||||
this.onSeek,
|
||||
});
|
||||
|
||||
final TerminalDebugger debugger;
|
||||
|
||||
final ScrollController? scrollController;
|
||||
|
||||
final void Function(int?)? onSeek;
|
||||
|
||||
@override
|
||||
State<TerminalDebuggerView> createState() => _TerminalDebuggerViewState();
|
||||
}
|
||||
|
||||
class _TerminalDebuggerViewState extends State<TerminalDebuggerView> {
|
||||
int? selectedCommand;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
widget.debugger.addListener(_onDebuggerChanged);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant TerminalDebuggerView oldWidget) {
|
||||
if (oldWidget.debugger != widget.debugger) {
|
||||
oldWidget.debugger.removeListener(_onDebuggerChanged);
|
||||
widget.debugger.addListener(_onDebuggerChanged);
|
||||
}
|
||||
super.didUpdateWidget(oldWidget);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.debugger.removeListener(_onDebuggerChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onDebuggerChanged() {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final commands = widget.debugger.commands;
|
||||
return ListView.builder(
|
||||
itemExtent: 20,
|
||||
controller: widget.scrollController,
|
||||
itemCount: commands.length,
|
||||
itemBuilder: (context, index) {
|
||||
final command = commands[index];
|
||||
return _CommandItem(
|
||||
index,
|
||||
command,
|
||||
selected: selectedCommand == index,
|
||||
onTap: () {
|
||||
if (selectedCommand == index) {
|
||||
selectedCommand = null;
|
||||
} else {
|
||||
setState(() => selectedCommand = index);
|
||||
}
|
||||
widget.onSeek?.call(selectedCommand);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CommandItem extends StatelessWidget {
|
||||
const _CommandItem(
|
||||
this.index,
|
||||
this.command, {
|
||||
this.onTap,
|
||||
this.selected = false,
|
||||
});
|
||||
|
||||
final int index;
|
||||
|
||||
final TerminalCommand command;
|
||||
|
||||
final bool selected;
|
||||
|
||||
final void Function()? onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
onEnter: (event) {
|
||||
if (event.down) {
|
||||
onTap?.call();
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: selected ? Colors.blue : Colors.transparent,
|
||||
width: 2,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 50,
|
||||
child: Text(
|
||||
'${index + 1}',
|
||||
style: TextStyle(
|
||||
color: selected ? Colors.blue : Colors.black,
|
||||
fontSize: 14,
|
||||
fontFamily: 'monospace',
|
||||
fontFamilyFallback: [
|
||||
'Menlo',
|
||||
'Monaco',
|
||||
'Consolas',
|
||||
'Liberation Mono',
|
||||
'Courier New',
|
||||
'Noto Sans Mono CJK SC',
|
||||
'Noto Sans Mono CJK TC',
|
||||
'Noto Sans Mono CJK KR',
|
||||
'Noto Sans Mono CJK JP',
|
||||
'Noto Sans Mono CJK HK',
|
||||
'Noto Color Emoji',
|
||||
'Noto Sans Symbols',
|
||||
'monospace',
|
||||
'sans-serif',
|
||||
],
|
||||
),
|
||||
textAlign: TextAlign.right,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 20),
|
||||
Container(
|
||||
width: 400,
|
||||
child: Text(
|
||||
command.escapedChars,
|
||||
style: TextStyle(
|
||||
color: command.error ? Colors.red : null,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
child: Text(
|
||||
command.explanation.join(','),
|
||||
style: TextStyle(
|
||||
color: command.error ? Colors.red : null,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
class _HashEnd {
|
||||
const _HashEnd();
|
||||
}
|
||||
|
||||
const _HashEnd _hashEnd = _HashEnd();
|
||||
|
||||
class _Jenkins {
|
||||
static int combine(int hash, Object? o) {
|
||||
assert(o is! Iterable);
|
||||
hash = 0x1fffffff & (hash + o.hashCode);
|
||||
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
|
||||
return hash ^ (hash >> 6);
|
||||
}
|
||||
|
||||
static int finish(int hash) {
|
||||
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
|
||||
hash = hash ^ (hash >> 11);
|
||||
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
|
||||
}
|
||||
}
|
||||
|
||||
int hashValues(
|
||||
Object? arg01,
|
||||
Object? arg02, [
|
||||
Object? arg03 = _hashEnd,
|
||||
Object? arg04 = _hashEnd,
|
||||
Object? arg05 = _hashEnd,
|
||||
Object? arg06 = _hashEnd,
|
||||
Object? arg07 = _hashEnd,
|
||||
Object? arg08 = _hashEnd,
|
||||
Object? arg09 = _hashEnd,
|
||||
Object? arg10 = _hashEnd,
|
||||
Object? arg11 = _hashEnd,
|
||||
Object? arg12 = _hashEnd,
|
||||
Object? arg13 = _hashEnd,
|
||||
Object? arg14 = _hashEnd,
|
||||
Object? arg15 = _hashEnd,
|
||||
Object? arg16 = _hashEnd,
|
||||
Object? arg17 = _hashEnd,
|
||||
Object? arg18 = _hashEnd,
|
||||
Object? arg19 = _hashEnd,
|
||||
Object? arg20 = _hashEnd,
|
||||
]) {
|
||||
int result = 0;
|
||||
result = _Jenkins.combine(result, arg01);
|
||||
result = _Jenkins.combine(result, arg02);
|
||||
if (!identical(arg03, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg03);
|
||||
if (!identical(arg04, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg04);
|
||||
if (!identical(arg05, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg05);
|
||||
if (!identical(arg06, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg06);
|
||||
if (!identical(arg07, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg07);
|
||||
if (!identical(arg08, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg08);
|
||||
if (!identical(arg09, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg09);
|
||||
if (!identical(arg10, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg10);
|
||||
if (!identical(arg11, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg11);
|
||||
if (!identical(arg12, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg12);
|
||||
if (!identical(arg13, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg13);
|
||||
if (!identical(arg14, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg14);
|
||||
if (!identical(arg15, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg15);
|
||||
if (!identical(arg16, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg16);
|
||||
if (!identical(arg17, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg17);
|
||||
if (!identical(arg18, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg18);
|
||||
if (!identical(arg19, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg19);
|
||||
if (!identical(arg20, _hashEnd)) {
|
||||
result = _Jenkins.combine(result, arg20);
|
||||
// I can see my house from here!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return _Jenkins.finish(result);
|
||||
}
|
||||
|
||||
int hashList(Iterable<Object> arguments) {
|
||||
int result = 0;
|
||||
for (Object argument in arguments) {
|
||||
result = _Jenkins.combine(result, argument);
|
||||
}
|
||||
return _Jenkins.finish(result);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/// Fixed-size list based lookup table, optimized for small positive integer
|
||||
/// keys.
|
||||
class FastLookupTable<T> {
|
||||
FastLookupTable(Map<int, T> data) {
|
||||
var maxIndex = data.keys.first;
|
||||
|
||||
for (var key in data.keys) {
|
||||
if (key > maxIndex) {
|
||||
maxIndex = key;
|
||||
}
|
||||
}
|
||||
|
||||
_maxIndex = maxIndex;
|
||||
|
||||
_table = List<T?>.filled(maxIndex + 1, null);
|
||||
|
||||
for (var entry in data.entries) {
|
||||
_table[entry.key] = entry.value;
|
||||
}
|
||||
}
|
||||
|
||||
late final List<T?> _table;
|
||||
late final int _maxIndex;
|
||||
|
||||
T? operator [](int index) {
|
||||
if (index > _maxIndex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return _table[index];
|
||||
}
|
||||
|
||||
int get maxIndex => _maxIndex;
|
||||
}
|
||||
@@ -0,0 +1,512 @@
|
||||
// ignore_for_file: constant_identifier_names
|
||||
|
||||
import 'dart:typed_data';
|
||||
|
||||
const BMP_COMBINING = [
|
||||
[0x0300, 0x036F],
|
||||
[0x0483, 0x0489],
|
||||
[0x0591, 0x05BD],
|
||||
[0x05BF, 0x05BF],
|
||||
[0x05C1, 0x05C2],
|
||||
[0x05C4, 0x05C5],
|
||||
[0x05C7, 0x05C7],
|
||||
[0x0600, 0x0605],
|
||||
[0x0610, 0x061A],
|
||||
[0x061C, 0x061C],
|
||||
[0x064B, 0x065F],
|
||||
[0x0670, 0x0670],
|
||||
[0x06D6, 0x06DD],
|
||||
[0x06DF, 0x06E4],
|
||||
[0x06E7, 0x06E8],
|
||||
[0x06EA, 0x06ED],
|
||||
[0x070F, 0x070F],
|
||||
[0x0711, 0x0711],
|
||||
[0x0730, 0x074A],
|
||||
[0x07A6, 0x07B0],
|
||||
[0x07EB, 0x07F3],
|
||||
[0x07FD, 0x07FD],
|
||||
[0x0816, 0x0819],
|
||||
[0x081B, 0x0823],
|
||||
[0x0825, 0x0827],
|
||||
[0x0829, 0x082D],
|
||||
[0x0859, 0x085B],
|
||||
[0x08D3, 0x0902],
|
||||
[0x093A, 0x093A],
|
||||
[0x093C, 0x093C],
|
||||
[0x0941, 0x0948],
|
||||
[0x094D, 0x094D],
|
||||
[0x0951, 0x0957],
|
||||
[0x0962, 0x0963],
|
||||
[0x0981, 0x0981],
|
||||
[0x09BC, 0x09BC],
|
||||
[0x09C1, 0x09C4],
|
||||
[0x09CD, 0x09CD],
|
||||
[0x09E2, 0x09E3],
|
||||
[0x09FE, 0x09FE],
|
||||
[0x0A01, 0x0A02],
|
||||
[0x0A3C, 0x0A3C],
|
||||
[0x0A41, 0x0A42],
|
||||
[0x0A47, 0x0A48],
|
||||
[0x0A4B, 0x0A4D],
|
||||
[0x0A51, 0x0A51],
|
||||
[0x0A70, 0x0A71],
|
||||
[0x0A75, 0x0A75],
|
||||
[0x0A81, 0x0A82],
|
||||
[0x0ABC, 0x0ABC],
|
||||
[0x0AC1, 0x0AC5],
|
||||
[0x0AC7, 0x0AC8],
|
||||
[0x0ACD, 0x0ACD],
|
||||
[0x0AE2, 0x0AE3],
|
||||
[0x0AFA, 0x0AFF],
|
||||
[0x0B01, 0x0B01],
|
||||
[0x0B3C, 0x0B3C],
|
||||
[0x0B3F, 0x0B3F],
|
||||
[0x0B41, 0x0B44],
|
||||
[0x0B4D, 0x0B4D],
|
||||
[0x0B56, 0x0B56],
|
||||
[0x0B62, 0x0B63],
|
||||
[0x0B82, 0x0B82],
|
||||
[0x0BC0, 0x0BC0],
|
||||
[0x0BCD, 0x0BCD],
|
||||
[0x0C00, 0x0C00],
|
||||
[0x0C04, 0x0C04],
|
||||
[0x0C3E, 0x0C40],
|
||||
[0x0C46, 0x0C48],
|
||||
[0x0C4A, 0x0C4D],
|
||||
[0x0C55, 0x0C56],
|
||||
[0x0C62, 0x0C63],
|
||||
[0x0C81, 0x0C81],
|
||||
[0x0CBC, 0x0CBC],
|
||||
[0x0CBF, 0x0CBF],
|
||||
[0x0CC6, 0x0CC6],
|
||||
[0x0CCC, 0x0CCD],
|
||||
[0x0CE2, 0x0CE3],
|
||||
[0x0D00, 0x0D01],
|
||||
[0x0D3B, 0x0D3C],
|
||||
[0x0D41, 0x0D44],
|
||||
[0x0D4D, 0x0D4D],
|
||||
[0x0D62, 0x0D63],
|
||||
[0x0DCA, 0x0DCA],
|
||||
[0x0DD2, 0x0DD4],
|
||||
[0x0DD6, 0x0DD6],
|
||||
[0x0E31, 0x0E31],
|
||||
[0x0E34, 0x0E3A],
|
||||
[0x0E47, 0x0E4E],
|
||||
[0x0EB1, 0x0EB1],
|
||||
[0x0EB4, 0x0EBC],
|
||||
[0x0EC8, 0x0ECD],
|
||||
[0x0F18, 0x0F19],
|
||||
[0x0F35, 0x0F35],
|
||||
[0x0F37, 0x0F37],
|
||||
[0x0F39, 0x0F39],
|
||||
[0x0F71, 0x0F7E],
|
||||
[0x0F80, 0x0F84],
|
||||
[0x0F86, 0x0F87],
|
||||
[0x0F8D, 0x0F97],
|
||||
[0x0F99, 0x0FBC],
|
||||
[0x0FC6, 0x0FC6],
|
||||
[0x102D, 0x1030],
|
||||
[0x1032, 0x1037],
|
||||
[0x1039, 0x103A],
|
||||
[0x103D, 0x103E],
|
||||
[0x1058, 0x1059],
|
||||
[0x105E, 0x1060],
|
||||
[0x1071, 0x1074],
|
||||
[0x1082, 0x1082],
|
||||
[0x1085, 0x1086],
|
||||
[0x108D, 0x108D],
|
||||
[0x109D, 0x109D],
|
||||
[0x1160, 0x11FF],
|
||||
[0x135D, 0x135F],
|
||||
[0x1712, 0x1714],
|
||||
[0x1732, 0x1734],
|
||||
[0x1752, 0x1753],
|
||||
[0x1772, 0x1773],
|
||||
[0x17B4, 0x17B5],
|
||||
[0x17B7, 0x17BD],
|
||||
[0x17C6, 0x17C6],
|
||||
[0x17C9, 0x17D3],
|
||||
[0x17DD, 0x17DD],
|
||||
[0x180B, 0x180E],
|
||||
[0x1885, 0x1886],
|
||||
[0x18A9, 0x18A9],
|
||||
[0x1920, 0x1922],
|
||||
[0x1927, 0x1928],
|
||||
[0x1932, 0x1932],
|
||||
[0x1939, 0x193B],
|
||||
[0x1A17, 0x1A18],
|
||||
[0x1A1B, 0x1A1B],
|
||||
[0x1A56, 0x1A56],
|
||||
[0x1A58, 0x1A5E],
|
||||
[0x1A60, 0x1A60],
|
||||
[0x1A62, 0x1A62],
|
||||
[0x1A65, 0x1A6C],
|
||||
[0x1A73, 0x1A7C],
|
||||
[0x1A7F, 0x1A7F],
|
||||
[0x1AB0, 0x1ABE],
|
||||
[0x1B00, 0x1B03],
|
||||
[0x1B34, 0x1B34],
|
||||
[0x1B36, 0x1B3A],
|
||||
[0x1B3C, 0x1B3C],
|
||||
[0x1B42, 0x1B42],
|
||||
[0x1B6B, 0x1B73],
|
||||
[0x1B80, 0x1B81],
|
||||
[0x1BA2, 0x1BA5],
|
||||
[0x1BA8, 0x1BA9],
|
||||
[0x1BAB, 0x1BAD],
|
||||
[0x1BE6, 0x1BE6],
|
||||
[0x1BE8, 0x1BE9],
|
||||
[0x1BED, 0x1BED],
|
||||
[0x1BEF, 0x1BF1],
|
||||
[0x1C2C, 0x1C33],
|
||||
[0x1C36, 0x1C37],
|
||||
[0x1CD0, 0x1CD2],
|
||||
[0x1CD4, 0x1CE0],
|
||||
[0x1CE2, 0x1CE8],
|
||||
[0x1CED, 0x1CED],
|
||||
[0x1CF4, 0x1CF4],
|
||||
[0x1CF8, 0x1CF9],
|
||||
[0x1DC0, 0x1DF9],
|
||||
[0x1DFB, 0x1DFF],
|
||||
[0x200B, 0x200F],
|
||||
[0x202A, 0x202E],
|
||||
[0x2060, 0x2064],
|
||||
[0x2066, 0x206F],
|
||||
[0x20D0, 0x20F0],
|
||||
[0x2CEF, 0x2CF1],
|
||||
[0x2D7F, 0x2D7F],
|
||||
[0x2DE0, 0x2DFF],
|
||||
[0x302A, 0x302D],
|
||||
[0x3099, 0x309A],
|
||||
[0xA66F, 0xA672],
|
||||
[0xA674, 0xA67D],
|
||||
[0xA69E, 0xA69F],
|
||||
[0xA6F0, 0xA6F1],
|
||||
[0xA802, 0xA802],
|
||||
[0xA806, 0xA806],
|
||||
[0xA80B, 0xA80B],
|
||||
[0xA825, 0xA826],
|
||||
[0xA8C4, 0xA8C5],
|
||||
[0xA8E0, 0xA8F1],
|
||||
[0xA8FF, 0xA8FF],
|
||||
[0xA926, 0xA92D],
|
||||
[0xA947, 0xA951],
|
||||
[0xA980, 0xA982],
|
||||
[0xA9B3, 0xA9B3],
|
||||
[0xA9B6, 0xA9B9],
|
||||
[0xA9BC, 0xA9BD],
|
||||
[0xA9E5, 0xA9E5],
|
||||
[0xAA29, 0xAA2E],
|
||||
[0xAA31, 0xAA32],
|
||||
[0xAA35, 0xAA36],
|
||||
[0xAA43, 0xAA43],
|
||||
[0xAA4C, 0xAA4C],
|
||||
[0xAA7C, 0xAA7C],
|
||||
[0xAAB0, 0xAAB0],
|
||||
[0xAAB2, 0xAAB4],
|
||||
[0xAAB7, 0xAAB8],
|
||||
[0xAABE, 0xAABF],
|
||||
[0xAAC1, 0xAAC1],
|
||||
[0xAAEC, 0xAAED],
|
||||
[0xAAF6, 0xAAF6],
|
||||
[0xABE5, 0xABE5],
|
||||
[0xABE8, 0xABE8],
|
||||
[0xABED, 0xABED],
|
||||
[0xFB1E, 0xFB1E],
|
||||
[0xFE00, 0xFE0F],
|
||||
[0xFE20, 0xFE2F],
|
||||
[0xFEFF, 0xFEFF],
|
||||
[0xFFF9, 0xFFFB],
|
||||
];
|
||||
|
||||
const HIGH_COMBINING = [
|
||||
[0x101FD, 0x101FD],
|
||||
[0x102E0, 0x102E0],
|
||||
[0x10376, 0x1037A],
|
||||
[0x10A01, 0x10A03],
|
||||
[0x10A05, 0x10A06],
|
||||
[0x10A0C, 0x10A0F],
|
||||
[0x10A38, 0x10A3A],
|
||||
[0x10A3F, 0x10A3F],
|
||||
[0x10AE5, 0x10AE6],
|
||||
[0x10D24, 0x10D27],
|
||||
[0x10F46, 0x10F50],
|
||||
[0x11001, 0x11001],
|
||||
[0x11038, 0x11046],
|
||||
[0x1107F, 0x11081],
|
||||
[0x110B3, 0x110B6],
|
||||
[0x110B9, 0x110BA],
|
||||
[0x110BD, 0x110BD],
|
||||
[0x110CD, 0x110CD],
|
||||
[0x11100, 0x11102],
|
||||
[0x11127, 0x1112B],
|
||||
[0x1112D, 0x11134],
|
||||
[0x11173, 0x11173],
|
||||
[0x11180, 0x11181],
|
||||
[0x111B6, 0x111BE],
|
||||
[0x111C9, 0x111CC],
|
||||
[0x1122F, 0x11231],
|
||||
[0x11234, 0x11234],
|
||||
[0x11236, 0x11237],
|
||||
[0x1123E, 0x1123E],
|
||||
[0x112DF, 0x112DF],
|
||||
[0x112E3, 0x112EA],
|
||||
[0x11300, 0x11301],
|
||||
[0x1133B, 0x1133C],
|
||||
[0x11340, 0x11340],
|
||||
[0x11366, 0x1136C],
|
||||
[0x11370, 0x11374],
|
||||
[0x11438, 0x1143F],
|
||||
[0x11442, 0x11444],
|
||||
[0x11446, 0x11446],
|
||||
[0x1145E, 0x1145E],
|
||||
[0x114B3, 0x114B8],
|
||||
[0x114BA, 0x114BA],
|
||||
[0x114BF, 0x114C0],
|
||||
[0x114C2, 0x114C3],
|
||||
[0x115B2, 0x115B5],
|
||||
[0x115BC, 0x115BD],
|
||||
[0x115BF, 0x115C0],
|
||||
[0x115DC, 0x115DD],
|
||||
[0x11633, 0x1163A],
|
||||
[0x1163D, 0x1163D],
|
||||
[0x1163F, 0x11640],
|
||||
[0x116AB, 0x116AB],
|
||||
[0x116AD, 0x116AD],
|
||||
[0x116B0, 0x116B5],
|
||||
[0x116B7, 0x116B7],
|
||||
[0x1171D, 0x1171F],
|
||||
[0x11722, 0x11725],
|
||||
[0x11727, 0x1172B],
|
||||
[0x1182F, 0x11837],
|
||||
[0x11839, 0x1183A],
|
||||
[0x119D4, 0x119D7],
|
||||
[0x119DA, 0x119DB],
|
||||
[0x119E0, 0x119E0],
|
||||
[0x11A01, 0x11A0A],
|
||||
[0x11A33, 0x11A38],
|
||||
[0x11A3B, 0x11A3E],
|
||||
[0x11A47, 0x11A47],
|
||||
[0x11A51, 0x11A56],
|
||||
[0x11A59, 0x11A5B],
|
||||
[0x11A8A, 0x11A96],
|
||||
[0x11A98, 0x11A99],
|
||||
[0x11C30, 0x11C36],
|
||||
[0x11C38, 0x11C3D],
|
||||
[0x11C3F, 0x11C3F],
|
||||
[0x11C92, 0x11CA7],
|
||||
[0x11CAA, 0x11CB0],
|
||||
[0x11CB2, 0x11CB3],
|
||||
[0x11CB5, 0x11CB6],
|
||||
[0x11D31, 0x11D36],
|
||||
[0x11D3A, 0x11D3A],
|
||||
[0x11D3C, 0x11D3D],
|
||||
[0x11D3F, 0x11D45],
|
||||
[0x11D47, 0x11D47],
|
||||
[0x11D90, 0x11D91],
|
||||
[0x11D95, 0x11D95],
|
||||
[0x11D97, 0x11D97],
|
||||
[0x11EF3, 0x11EF4],
|
||||
[0x13430, 0x13438],
|
||||
[0x16AF0, 0x16AF4],
|
||||
[0x16B30, 0x16B36],
|
||||
[0x16F4F, 0x16F4F],
|
||||
[0x16F8F, 0x16F92],
|
||||
[0x1BC9D, 0x1BC9E],
|
||||
[0x1BCA0, 0x1BCA3],
|
||||
[0x1D167, 0x1D169],
|
||||
[0x1D173, 0x1D182],
|
||||
[0x1D185, 0x1D18B],
|
||||
[0x1D1AA, 0x1D1AD],
|
||||
[0x1D242, 0x1D244],
|
||||
[0x1DA00, 0x1DA36],
|
||||
[0x1DA3B, 0x1DA6C],
|
||||
[0x1DA75, 0x1DA75],
|
||||
[0x1DA84, 0x1DA84],
|
||||
[0x1DA9B, 0x1DA9F],
|
||||
[0x1DAA1, 0x1DAAF],
|
||||
[0x1E000, 0x1E006],
|
||||
[0x1E008, 0x1E018],
|
||||
[0x1E01B, 0x1E021],
|
||||
[0x1E023, 0x1E024],
|
||||
[0x1E026, 0x1E02A],
|
||||
[0x1E130, 0x1E136],
|
||||
[0x1E2EC, 0x1E2EF],
|
||||
[0x1E8D0, 0x1E8D6],
|
||||
[0x1E944, 0x1E94A],
|
||||
[0xE0001, 0xE0001],
|
||||
[0xE0020, 0xE007F],
|
||||
[0xE0100, 0xE01EF],
|
||||
];
|
||||
|
||||
const BMP_WIDE = [
|
||||
[0x1100, 0x115F],
|
||||
[0x231A, 0x231B],
|
||||
[0x2329, 0x232A],
|
||||
[0x23E9, 0x23EC],
|
||||
[0x23F0, 0x23F0],
|
||||
[0x23F3, 0x23F3],
|
||||
[0x25FD, 0x25FE],
|
||||
[0x2614, 0x2615],
|
||||
[0x2648, 0x2653],
|
||||
[0x267F, 0x267F],
|
||||
[0x2693, 0x2693],
|
||||
[0x26A1, 0x26A1],
|
||||
[0x26AA, 0x26AB],
|
||||
[0x26BD, 0x26BE],
|
||||
[0x26C4, 0x26C5],
|
||||
[0x26CE, 0x26CE],
|
||||
[0x26D4, 0x26D4],
|
||||
[0x26EA, 0x26EA],
|
||||
[0x26F2, 0x26F3],
|
||||
[0x26F5, 0x26F5],
|
||||
[0x26FA, 0x26FA],
|
||||
[0x26FD, 0x26FD],
|
||||
[0x2705, 0x2705],
|
||||
[0x270A, 0x270B],
|
||||
[0x2728, 0x2728],
|
||||
[0x274C, 0x274C],
|
||||
[0x274E, 0x274E],
|
||||
[0x2753, 0x2755],
|
||||
[0x2757, 0x2757],
|
||||
[0x2795, 0x2797],
|
||||
[0x27B0, 0x27B0],
|
||||
[0x27BF, 0x27BF],
|
||||
[0x2B1B, 0x2B1C],
|
||||
[0x2B50, 0x2B50],
|
||||
[0x2B55, 0x2B55],
|
||||
[0x2E80, 0x2E99],
|
||||
[0x2E9B, 0x2EF3],
|
||||
[0x2F00, 0x2FD5],
|
||||
[0x2FF0, 0x2FFB],
|
||||
[0x3000, 0x3029],
|
||||
[0x302E, 0x303E],
|
||||
[0x3041, 0x3096],
|
||||
[0x309B, 0x30FF],
|
||||
[0x3105, 0x312F],
|
||||
[0x3131, 0x318E],
|
||||
[0x3190, 0x31BA],
|
||||
[0x31C0, 0x31E3],
|
||||
[0x31F0, 0x321E],
|
||||
[0x3220, 0x3247],
|
||||
[0x3250, 0x4DBF],
|
||||
[0x4E00, 0xA48C],
|
||||
[0xA490, 0xA4C6],
|
||||
[0xA960, 0xA97C],
|
||||
[0xAC00, 0xD7A3],
|
||||
[0xF900, 0xFAFF],
|
||||
[0xFE10, 0xFE19],
|
||||
[0xFE30, 0xFE52],
|
||||
[0xFE54, 0xFE66],
|
||||
[0xFE68, 0xFE6B],
|
||||
[0xFF01, 0xFF60],
|
||||
[0xFFE0, 0xFFE6],
|
||||
];
|
||||
|
||||
const HIGH_WIDE = [
|
||||
[0x16FE0, 0x16FE3],
|
||||
[0x17000, 0x187F7],
|
||||
[0x18800, 0x18AF2],
|
||||
[0x1B000, 0x1B11E],
|
||||
[0x1B150, 0x1B152],
|
||||
[0x1B164, 0x1B167],
|
||||
[0x1B170, 0x1B2FB],
|
||||
[0x1F004, 0x1F004],
|
||||
[0x1F0CF, 0x1F0CF],
|
||||
[0x1F18E, 0x1F18E],
|
||||
[0x1F191, 0x1F19A],
|
||||
[0x1F200, 0x1F202],
|
||||
[0x1F210, 0x1F23B],
|
||||
[0x1F240, 0x1F248],
|
||||
[0x1F250, 0x1F251],
|
||||
[0x1F260, 0x1F265],
|
||||
[0x1F300, 0x1F320],
|
||||
[0x1F32D, 0x1F335],
|
||||
[0x1F337, 0x1F37C],
|
||||
[0x1F37E, 0x1F393],
|
||||
[0x1F3A0, 0x1F3CA],
|
||||
[0x1F3CF, 0x1F3D3],
|
||||
[0x1F3E0, 0x1F3F0],
|
||||
[0x1F3F4, 0x1F3F4],
|
||||
[0x1F3F8, 0x1F43E],
|
||||
[0x1F440, 0x1F440],
|
||||
[0x1F442, 0x1F4FC],
|
||||
[0x1F4FF, 0x1F53D],
|
||||
[0x1F54B, 0x1F54E],
|
||||
[0x1F550, 0x1F567],
|
||||
[0x1F57A, 0x1F57A],
|
||||
[0x1F595, 0x1F596],
|
||||
[0x1F5A4, 0x1F5A4],
|
||||
[0x1F5FB, 0x1F64F],
|
||||
[0x1F680, 0x1F6C5],
|
||||
[0x1F6CC, 0x1F6CC],
|
||||
[0x1F6D0, 0x1F6D2],
|
||||
[0x1F6D5, 0x1F6D5],
|
||||
[0x1F6EB, 0x1F6EC],
|
||||
[0x1F6F4, 0x1F6FA],
|
||||
[0x1F7E0, 0x1F7EB],
|
||||
[0x1F90D, 0x1F971],
|
||||
[0x1F973, 0x1F976],
|
||||
[0x1F97A, 0x1F9A2],
|
||||
[0x1F9A5, 0x1F9AA],
|
||||
[0x1F9AE, 0x1F9CA],
|
||||
[0x1F9CD, 0x1F9FF],
|
||||
[0x1FA70, 0x1FA73],
|
||||
[0x1FA78, 0x1FA7A],
|
||||
[0x1FA80, 0x1FA82],
|
||||
[0x1FA90, 0x1FA95],
|
||||
[0x20000, 0x2FFFD],
|
||||
[0x30000, 0x3FFFD],
|
||||
];
|
||||
|
||||
final table = buildTable();
|
||||
|
||||
Uint8List buildTable() {
|
||||
final table = Uint8List(65536);
|
||||
table.fillRange(0, table.length, 1);
|
||||
table[0] = 0;
|
||||
table.fillRange(1, 32, 0);
|
||||
table.fillRange(0x7f, 0xa0, 0);
|
||||
for (var r = 0; r < BMP_COMBINING.length; ++r) {
|
||||
table.fillRange(BMP_COMBINING[r][0], BMP_COMBINING[r][1] + 1, 0);
|
||||
}
|
||||
for (var r = 0; r < BMP_WIDE.length; ++r) {
|
||||
table.fillRange(BMP_WIDE[r][0], BMP_WIDE[r][1] + 1, 2);
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
bool bisearch(int ucs, List<List<int>> data) {
|
||||
var min = 0;
|
||||
var max = data.length - 1;
|
||||
int mid;
|
||||
if (ucs < data[0][0] || ucs > data[max][1]) {
|
||||
return false;
|
||||
}
|
||||
while (max >= min) {
|
||||
mid = (min + max) >> 1;
|
||||
if (ucs > data[mid][1]) {
|
||||
min = mid + 1;
|
||||
} else if (ucs < data[mid][0]) {
|
||||
max = mid - 1;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
class UnicodeV11 {
|
||||
final version = '11';
|
||||
|
||||
int wcwidth(int codePoint) {
|
||||
if (codePoint < 32) return 0;
|
||||
if (codePoint < 127) return 1;
|
||||
if (codePoint < 65536) return table[codePoint];
|
||||
if (bisearch(codePoint, HIGH_COMBINING)) return 0;
|
||||
if (bisearch(codePoint, HIGH_WIDE)) return 2;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
final unicodeV11 = UnicodeV11();
|
||||
Reference in New Issue
Block a user