Skip to content

Commit 41af657

Browse files
committed
define const for erase-modes
The current implementation considers erase-modes for "lines" and "display" to be equivalent; while there's an overlap, they have distinct values. This patch: - Introduces type-aliases for each to make the lists self-describing. Aliases are used to remain backward-compatible. - Changes the EraseDisplay and EraseLine functions to use the corresponding type-alias. The EraseModes struct is left in place, although it's currently not used in the codebase itself; it's worth considering to mark it deprecated (and recommend users to use the defined consts). Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 63bc8cf commit 41af657

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

aec.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,31 @@ var EraseModes = struct {
2121
All: 2,
2222
}
2323

24+
// EraseDisplayMode is the parameter for the ED (Erase in Display, CSI Ps J)
25+
// control sequence. It defines which portion of the display should be erased.
26+
//
27+
// This is an alias of [EraseMode] for backward compatibility.
28+
type EraseDisplayMode = EraseMode
29+
30+
const (
31+
EraseDisplayTail EraseDisplayMode = 0 // erase from cursor to end of display
32+
EraseDisplayHead EraseDisplayMode = 1 // erase from start of display to cursor
33+
EraseDisplayAll EraseDisplayMode = 2 // erase entire display
34+
EraseDisplaySavedLines EraseDisplayMode = 3 // erase saved lines (scrollback), non-standard but widely supported
35+
)
36+
37+
// EraseLineMode is the parameter for the EL (Erase in Line, CSI Ps K)
38+
// control sequence. It defines which portion of the current line should be erased.
39+
//
40+
// This is an alias of [EraseMode] for backward compatibility.
41+
type EraseLineMode = EraseMode
42+
43+
const (
44+
EraseLineTail EraseLineMode = 0 // erase from cursor to end of line
45+
EraseLineHead EraseLineMode = 1 // erase from start of line to cursor
46+
EraseLineAll EraseLineMode = 2 // erase entire line
47+
)
48+
2449
// Cursor control and reporting sequences.
2550
//
2651
// Includes CSI sequences defined by ECMA-48 / ISO 6429, DEC private modes,
@@ -99,13 +124,13 @@ func Position(row, col uint) ANSI {
99124
return newAnsi(fmt.Sprintf(Esc+"%d;%dH", row, col))
100125
}
101126

102-
// EraseDisplay erases the display using the given EraseMode (ED).
103-
func EraseDisplay(m EraseMode) ANSI {
127+
// EraseDisplay erases the display using the given [EraseDisplayMode] (ED).
128+
func EraseDisplay(m EraseDisplayMode) ANSI {
104129
return newAnsi(fmt.Sprintf(Esc+"%dJ", m))
105130
}
106131

107-
// EraseLine erases the line using the given EraseMode (EL).
108-
func EraseLine(m EraseMode) ANSI {
132+
// EraseLine erases the line using the given [EraseLineMode] (EL).
133+
func EraseLine(m EraseLineMode) ANSI {
109134
return newAnsi(fmt.Sprintf(Esc+"%dK", m))
110135
}
111136

builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ func (builder *Builder) Position(row, col uint) *Builder {
7474
// Erasing and scrolling.
7575

7676
// EraseDisplay erases the display using the given mode.
77-
func (builder *Builder) EraseDisplay(m EraseMode) *Builder {
77+
func (builder *Builder) EraseDisplay(m EraseDisplayMode) *Builder {
7878
return builder.With(EraseDisplay(m))
7979
}
8080

8181
// EraseLine erases the current line using the given mode.
82-
func (builder *Builder) EraseLine(m EraseMode) *Builder {
82+
func (builder *Builder) EraseLine(m EraseLineMode) *Builder {
8383
return builder.With(EraseLine(m))
8484
}
8585

0 commit comments

Comments
 (0)