iximeow / yaxpeax-arch

fundamental traits to describe an architecture in the yaxpeax project
BSD Zero Clause License
11 stars 2 forks source link

rework `colors` and display code #7

Closed iximeow closed 4 months ago

iximeow commented 4 months ago

the changelog says it better than another repetition:

## 0.3.0

added a new crate feature flag, `alloc`.
  this flag is for any features that do not require std, but do require
  containers from `liballoc`. good examples are `alloc::string::String` or
  `alloc::vec::Vec`.

added `yaxpeax_arch::display::DisplaySink` after revisiting output colorization.
  `DisplaySink` is better suited for general markup, rather than being focused
  specifically on ANSI/console text coloring. `YaxColors` also simply does not
  style text in some unfortunate circumstances, such as when the console that
  needs to be styled is only written to after intermediate buffering.

  `DisplaySink` also includes specializable functions for writing text to an
  output, and the implementation for `alloc::string::String` takes advantage of
  this: writing through `impl DisplaySink for String` will often be substantially
  more performant than writing through `fmt::Write`.

added `mod color_new`:
  this includes an alternate vision for `YaxColors` and better fits with the
  new `DisplaySink` machinery; ANSI-style text markup can be done through the
  new `yaxpeax_arch::color_new::ansi::AnsiDisplaySink`.

  this provides more flexibility than i'd initially expected! yours truly will
  be using this to render instructions with HTML spans (rather than ANSI
  sequences) to colorize dis.yaxpeax.net.

  in the future, `mod colored` will be removed, `mod color_new` will be renamed
  to `mod color`.

deprecated `mod colored`:
  generally, colorization of text is a presentation issue; `trait Colorize`
  mixed formatting of data to text with how that text is presented, but that is
  at odds with the same text being presented in different ways for which
  colorization is not generic. for example, rendering an instruction as marked
  up HTML involves coloring in an entirely different way than rendering an
  instruction with ANSI sequences for a VT100-like terminal.

added `yaxpeax_arch::safer_unchecked` to aid in testing use of unchecked methods
  these were originally added to improve yaxpeax-x86 testing:
  https://github.com/iximeow/yaxpeax-x86/pull/17, but are being pulled into
  yaxpeax-arch as they're generally applicable and overall wonderful tools.
  thank you again 522!

added `mod testkit`:
  this module contains tools to validate the correctness of crates implementing
  `yaxpeax-arch` traits. these initial tools are focused on validating the
  correctness of functions that write to `DisplaySink`, especially that span
  management is correct.

  `yaxpeax-x86`, for example, will imminently have fuzz targets to use these
  types for its own validation.

made VecSink's `records` private. instead of extracting records from the struct
  by accessing this field directly, call `VecSink::into_inner()`.

made VecSink is now available through the `alloc` feature flag as well as `std`.

meta: the major omission in this release is an architecture-agnostic way to
format an instruction into a `DisplaySink`. i haven't been able to figure out
quite the right shape for that! it is fully expected in the future, and will
probably end up somehow referenced through `yaxpeax_arch::Arch`.

(includes more than just colors and display adjustments because the new code also uses things like safer_unchecked that used to live in yaxpeax-x86 and really ought to be shared more broadly)

this... in a very roundabout way, starts to help with https://github.com/iximeow/yaxpeax-arch/issues/5, as well