sharkdp / pastel

A command-line tool to generate, analyze, convert and manipulate colors
Apache License 2.0
5k stars 97 forks source link

Bug: panic on `ansi-8bit-escaped` #116

Closed bbkane closed 4 years ago

bbkane commented 4 years ago

Repro

$ RUST_BACKTRACE=full pastel format ansi-8bit-escaped green
thread 'main' panicked at 'internal error: entered unreachable code: Unknown format type', src/cli/commands/format.rs:45:17
stack backtrace:
   0:        0x105a57af5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h54942195382ebc43
   1:        0x105a6f491 - core::fmt::write::h03a4fdeef33f04e5
   2:        0x105a578ab - std::io::Write::write_fmt::h2f54eb7e3d98f93c
   3:        0x105a5a803 - std::panicking::default_hook::{{closure}}::h5b49f92bd56be4e7
   4:        0x105a5a52f - std::panicking::default_hook::he9bfa0e01e764f9b
   5:        0x105a5ae3b - std::panicking::rust_panic_with_hook::hfdce9374aac935e9
   6:        0x105a5a9d9 - rust_begin_unwind
   7:        0x105a7796f - std::panicking::begin_panic_fmt::ha6a3e14aa30f2a56
   8:        0x1059c7e22 - <pastel::commands::format::FormatCommand as pastel::commands::traits::ColorCommand>::run::h35fc1d7f13cb1283
   9:        0x1059c51ab - pastel::main::hbec51e02cfeafdb4
  10:        0x1059b7906 - std::rt::lang_start::{{closure}}::hb7dc0bae37a6f3f0
  11:        0x105a5a8c8 - std::panicking::try::do_call::hdad9ba23601b147d
  12:        0x105a5cd7f - __rust_maybe_catch_panic
  13:        0x105a4e435 - std::rt::lang_start_internal::h820f58b1bdc07d9f
  14:        0x1059c5a39 - main

The type argument (ansi-8bit-escaped) is specified by $ pastel format --help:

ARGS:
    <type>
            Output format type. Note that the 'ansi-*-escaped' formats print ansi escape sequences
            to the terminal that will not be visible unless something else is printed in addition.
            [default: hex]  [possible values: rgb, rgb-float, hex,
            hsl, hsl-hue, hsl-saturation, hsl-lightness, lch,
            lch-lightness, lch-chroma, lch-hue, lab, lab-a,
            lab-b, luminance, brightness, ansi-8bit, ansi-24bit,
            ansi-8bit-escaped, ansi-24bit-escaped, name]

Cause?

cli.rs provides ansi-8bit-escaped - see https://github.com/sharkdp/pastel/blob/bb3d2abe1e9f048b646aba72ee617e1628259486/src/cli/cli.rs#L218

format.rs is looking for "ansi-8bit-escapecode", not ansi-8bit-escaped - see https://github.com/sharkdp/pastel/blob/b4f7c2c6253a07c38b5e7026ba9039ae246b481e/src/cli/commands/format.rs#L41

bbkane commented 4 years ago

If you pick a preferred name (ansi-8bit-escaped or ansi-8bit-escapecode) in a comment here, I'll be happy to submit a PR with the code change. It looks like an easy way to tell myself I can write rust code :)

sharkdp commented 4 years ago

Thank you for reporting this.

Let's go with escapecode.

sharkdp commented 4 years ago

Thank you for the detailed bug report and the quick fix! I tagged a patch release: https://github.com/sharkdp/pastel/releases/tag/v0.7.1