scoop:scoop.terminal:0.1.0
src/screen/content.scoop
Selected production source · src/screen/content.scoop
1
package scoop.terminal.screen3
import scoop.terminal.Command4
import scoop.terminal.requireTerminalParameter5
import scoop.terminal.writeCsiParameter7
/**8
* The screen or line region selected for an ANSI erase command.9
*/10
public enum ClearType {11
/**12
* Erase the visible screen.13
*/14
All,15
/**16
* Erase the terminal scrollback buffer.17
*/18
Purge,19
/**20
* Erase from the cursor to the end of the screen.21
*/22
FromCursorDown,23
/**24
* Erase from the beginning of the screen through the cursor.25
*/26
FromCursorUp,27
/**28
* Erase the complete current line.29
*/30
CurrentLine,31
/**32
* Erase from the cursor to the end of its line.33
*/34
UntilNewLine }36
/**37
* Erases the selected region without moving the cursor.38
*/39
public struct Clear(val type: ClearType) : Command {40
/**41
* Writes this command's ANSI representation to the supplied writer without flushing it.42
* Parameter validation happens before or during serialization.43
*/44
public override fun writeAnsi(writer: TextWriter) {45
val suffix = when (type) {46
case ClearType.All -> "2J"47
case ClearType.Purge -> "3J"48
case ClearType.FromCursorDown -> "J"49
case ClearType.FromCursorUp -> "1J"50
case ClearType.CurrentLine -> "2K"51
case ClearType.UntilNewLine -> "K"52
}53
writer.write("\u001b[" + suffix)54
}55
}57
/**58
* Scrolls the screen upward by the requested line count; zero emits no command.59
*/60
public struct ScrollUp(val count: Long) : Command {61
/**62
* Writes this command's ANSI representation to the supplied writer without flushing it.63
* Parameter validation happens before or during serialization.64
*/65
public override fun writeAnsi(writer: TextWriter) {66
if (count != 0L) writeCsiParameter(writer, count, "S")67
}68
}70
/**71
* Scrolls the screen downward by the requested line count; zero emits no command.72
*/73
public struct ScrollDown(val count: Long) : Command {74
/**75
* Writes this command's ANSI representation to the supplied writer without flushing it.76
* Parameter validation happens before or during serialization.77
*/78
public override fun writeAnsi(writer: TextWriter) {79
if (count != 0L) writeCsiParameter(writer, count, "T")80
}81
}83
/**84
* Requests terminal dimensions in character cells. Both dimensions must be in 1..65535.85
*/86
public struct SetSize(val columns: Long, val rows: Long) : Command {87
/**88
* Writes this command's ANSI representation to the supplied writer without flushing it.89
* Parameter validation happens before or during serialization.90
*/91
public override fun writeAnsi(writer: TextWriter) {92
requireTerminalParameter(columns, 1L)93
requireTerminalParameter(rows, 1L)94
writer.write("\u001b[8;" + rows.toString() + ";" + columns.toString() + "t")95
}96
}98
/**99
* Sets the terminal title. Control characters are rejected before serialization.100
*/101
public struct SetTitle(val title: String) : Command {102
/**103
* Writes this command's ANSI representation to the supplied writer without flushing it.104
* Parameter validation happens before or during serialization.105
*/106
public override fun writeAnsi(writer: TextWriter) {107
for (character in title) {108
if (character.code < 32 || (character.code >= 127 && character.code <= 159)) {109
throw IllegalArgumentException(Some("terminal title contains a control character"))110
}111
}112
writer.write("\u001b]0;" + title + "\u0007")113
}114
}