_CHAR_COLL_SEP_PAGE = '='
_CHAR_COL_SOLID = '+'
_CHAR_COL_TRANSPARENT = '-'
+_CHARS_COLL_SEP_ID_TOKS = (':', '.')
_BOX_PREFIX = 'box:'
ARG_QMARK = '?'
lambda item: item.show(to_boxes=True))
}
+ @classmethod
+ def sorters(
+ cls
+ ) -> dict[str, tuple[str, Callable[['BricksDb', tuple[Self, ...]],
+ tuple[Self, ...]]]]:
+ def by_structured_id(
+ _: BricksDb,
+ pre_sorted: tuple[Self, ...]
+ ) -> tuple[Self, ...]:
+ ids_to_items = {item.id_: item for item in pre_sorted}
+ ids_to_splits = {}
+ widths = [0]
+ for id_ in ids_to_items:
+ toks = ['']
+ for c in id_:
+ toks[-1] = toks[-1] + c
+ if c in _CHARS_COLL_SEP_ID_TOKS:
+ toks += ['']
+ ids_to_splits[id_] = toks
+ for idx, width in enumerate([len(tok) for tok in toks]):
+ widths[idx:idx+1] = [max(width, widths[idx])
+ if len(widths) > idx else width]
+ ids_padded_to_items = {}
+ for id_, toks in ids_to_splits.items():
+ id_padded = ''
+ for idx, tok in enumerate(toks):
+ id_padded = id_padded + ' '*(widths[idx] - len(tok)) + tok
+ ids_padded_to_items[id_padded] = ids_to_items[id_]
+ return tuple(ids_padded_to_items[id_padded]
+ for id_padded in sorted(ids_padded_to_items))
+ return super().sorters() | {TOK_ID: ('by ID tokens',
+ by_structured_id)}
+
class _Box(_Lookupable):
'Order of designs.'