ponylang / rfcs

RFCs for changes to Pony
https://ponylang.io/
61 stars 48 forks source link

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

Closed SeanTAllen closed 2 years ago

SeanTAllen commented 2 years ago

@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()
rhagenson commented 2 years ago

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.

SeanTAllen commented 2 years ago

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

SeanTAllen commented 2 years ago

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 commented 2 years ago

@ergl Type aliases dont appear in any generated documentation.

jemc commented 2 years ago

Approved during today's sync call :heavy_check_mark: