rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

Add RFC for the inclusion of all erase codes in the Term package

Open SeanTAllen opened this issue 2 years ago • 3 comments

SeanTAllen avatar Oct 26 '22 20:10 SeanTAllen

@rhagenson @jemc I have a better implementation idea. Same shape of things but without the need for the match statement.

I prefer this and think it is easier to follow.

Thoughts?

primitive EraseLeft
  fun apply(): String =>
    "\x1B[1K"

primitive EraseLine
  fun apply(): String =>
    "\x1B[2K"

primitive EraseRight
  fun apply(): String =>
    "\x1B[0K"

type _EraseDirection is (EraseLeft | EraseLine | EraseRight)

primitive Ansi
  fun erase(direction: _EraseDirection = EraseRight): String =>
    """
    Erases content. The direction to erase is dictated by the `direction`
    parameter. Use `EraseLeft` to erase everything from the cursor to the
    beginning of the line. Use `EraseLine` to erase the entire line. Use
    `EraseRight` to erase everything from the cursor to the end of the line.
    The default direction is `EraseRight`.
    """
    direction()

SeanTAllen avatar Oct 27 '22 17:10 SeanTAllen

I like that a lot more. I was trying to think of a way to get rid of the match because I did not like one condition being the fall through in else when we know all the states that are possible.

rhagenson avatar Oct 27 '22 18:10 rhagenson

@rhagenson yeah. I didn't like it either. I dashed it off yesterday to get it open.

SeanTAllen avatar Oct 27 '22 18:10 SeanTAllen

I've updated again because "dur", exhaustive match, the else wasn't needed. I think I like the version in the RFC better than the one in my comment now. It fits the existing API better.

SeanTAllen avatar Oct 29 '22 23:10 SeanTAllen

@ergl Type aliases dont appear in any generated documentation.

SeanTAllen avatar Nov 15 '22 19:11 SeanTAllen

Approved during today's sync call :heavy_check_mark:

jemc avatar Nov 15 '22 19:11 jemc