Skip to content

Conversation

@Tyriar
Copy link
Member

@Tyriar Tyriar commented Jul 28, 2023

Fixes #4614

@Tyriar Tyriar added this to the 5.3.0 milestone Jul 28, 2023
@Tyriar Tyriar requested a review from jerch July 28, 2023 20:52
@Tyriar Tyriar self-assigned this Jul 28, 2023
Comment on lines 3433 to 3435
function isValidColorIndex(value: number): value is ColorIndex {
return 0 <= value && value < 259;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jerch should this be < 256 instead? If so what would be a good name for this color index sub-range? IsValidInputColorIndex or something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for colors the index is only 0..255, so its better to test for that range in during input. The fg/bg/cursor entries on top are an amalgamation, so the events and methods dont need re-declaration and/or branching.

: Enumerate<N, [...Acc, Acc['length']]>;
type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;

type ColorIndex = IntRange<0, 259>; // number from 0 to 258
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be clearer to limit ColorIndex here to 0..255, and to merge into a super type with the fg/bg/cursor values in a second step? Also the test function above can then refer to that narrower ColorIndex type.

@Tyriar Tyriar requested a review from jerch July 28, 2023 23:34
Copy link
Member

@jerch jerch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, beside the left-over doubled change check below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid as ColorIndex in src/common/InputHandler.test.ts

2 participants