crossterm-rs / crossterm

Cross platform terminal library rust
MIT License
3.29k stars 280 forks source link

Attribute bytes start at 0x2 #915

Open joshka opened 3 months ago

joshka commented 3 months ago

Describe the bug Just checking out how attributes were implemented and I noticed that Attribute::Reset.bytes() starts at 0x2 instead of 1. This seems like a possible off by 1 error (but I'm not 100% sure.

To Reproduce Steps to reproduce the behavior:

    #[rstest]
    #[case(Attribute::Reset, 0x2)]
    #[case(Attribute::Bold, 0x4)]
    #[case(Attribute::Dim, 0x8)]
    #[case(Attribute::Italic, 0x10)]
    #[case(Attribute::Underlined, 0x20)]
    #[case(Attribute::DoubleUnderlined, 0x40)]
    #[case(Attribute::Undercurled, 0x80)]
    #[case(Attribute::Underdotted, 0x100)]
    #[case(Attribute::Underdashed, 0x200)]
    #[case(Attribute::SlowBlink, 0x400)]
    #[case(Attribute::RapidBlink, 0x800)]
    #[case(Attribute::Reverse, 0x1000)]
    #[case(Attribute::Hidden, 0x2000)]
    #[case(Attribute::CrossedOut, 0x4000)]
    #[case(Attribute::Fraktur, 0x8000)]
    #[case(Attribute::NoBold, 0x10000)]
    #[case(Attribute::NormalIntensity, 0x20000)]
    #[case(Attribute::NoItalic, 0x40000)]
    #[case(Attribute::NoUnderline, 0x80000)]
    #[case(Attribute::NoBlink, 0x100000)]
    #[case(Attribute::NoReverse, 0x200000)]
    #[case(Attribute::NoHidden, 0x400000)]
    #[case(Attribute::NotCrossedOut, 0x800000)]
    #[case(Attribute::Framed, 0x1000000)]
    #[case(Attribute::Encircled, 0x2000000)]
    #[case(Attribute::OverLined, 0x4000000)]
    #[case(Attribute::NotFramedOrEncircled, 0x8000000)]
    #[case(Attribute::NotOverLined, 0x10000000)]
    fn bytes(#[case] attribute: Attribute, #[case] expected: u32) {
        assert_eq!(attribute.bytes(), expected);
    }

Expected behavior first bitfield should probably be 1

OS

Terminal/Console