Scoop API

scoop:scoop.terminal:0.1.0

src/cursor/movement.scoop

Selected production source · src/cursor/movement.scoop

1package scoop.terminal.cursor
3import scoop.terminal.Command
4import scoop.terminal.requireTerminalParameter
5import scoop.terminal.writeCsiParameter
7/**
8 * Moves to a zero-based column and row. Both coordinates must be in 0..65535; ANSI output converts
9 * them to one-based positions.
10 */
11public struct MoveTo(val column: Long, val row: Long) : Command {
12 /**
13 * Writes this command's ANSI representation to the supplied writer without flushing it.
14 * Parameter validation happens before or during serialization.
15 */
16 public override fun writeAnsi(writer: TextWriter) {
17 requireTerminalParameter(column)
18 requireTerminalParameter(row)
19 writer.write("\u001b[" + (row + 1L).toString() + ";" + (column + 1L).toString() + "H")
20 }
23/**
24 * Moves to a zero-based column in 0..65535 while retaining the row.
25 */
26public struct MoveToColumn(val column: Long) : Command {
27 /**
28 * Writes this command's ANSI representation to the supplied writer without flushing it.
29 * Parameter validation happens before or during serialization.
30 */
31 public override fun writeAnsi(writer: TextWriter) {
32 requireTerminalParameter(column)
33 writer.write("\u001b[" + (column + 1L).toString() + "G")
34 }
37/**
38 * Moves to a zero-based row in 0..65535 while retaining the column.
39 */
40public struct MoveToRow(val row: Long) : Command {
41 /**
42 * Writes this command's ANSI representation to the supplied writer without flushing it.
43 * Parameter validation happens before or during serialization.
44 */
45 public override fun writeAnsi(writer: TextWriter) {
46 requireTerminalParameter(row)
47 writer.write("\u001b[" + (row + 1L).toString() + "d")
48 }
51/**
52 * Moves the cursor up by the supplied count. The ANSI parameter must be in 0..65535; the terminal
53 * interprets zero according to its command rules.
54 */
55public struct MoveUp(val count: Long) : Command {
56 /**
57 * Writes this command's ANSI representation to the supplied writer without flushing it.
58 * Parameter validation happens before or during serialization.
59 */
60 public override fun writeAnsi(writer: TextWriter) { writeCsiParameter(writer, count, "A") }
63/**
64 * Moves the cursor down by the supplied count. The ANSI parameter must be in 0..65535; the
65 * terminal interprets zero according to its command rules.
66 */
67public struct MoveDown(val count: Long) : Command {
68 /**
69 * Writes this command's ANSI representation to the supplied writer without flushing it.
70 * Parameter validation happens before or during serialization.
71 */
72 public override fun writeAnsi(writer: TextWriter) { writeCsiParameter(writer, count, "B") }
75/**
76 * Moves the cursor right by the supplied count. The ANSI parameter must be in 0..65535; the
77 * terminal interprets zero according to its command rules.
78 */
79public struct MoveRight(val count: Long) : Command {
80 /**
81 * Writes this command's ANSI representation to the supplied writer without flushing it.
82 * Parameter validation happens before or during serialization.
83 */
84 public override fun writeAnsi(writer: TextWriter) { writeCsiParameter(writer, count, "C") }
87/**
88 * Moves the cursor left by the supplied count. The ANSI parameter must be in 0..65535; the
89 * terminal interprets zero according to its command rules.
90 */
91public struct MoveLeft(val count: Long) : Command {
92 /**
93 * Writes this command's ANSI representation to the supplied writer without flushing it.
94 * Parameter validation happens before or during serialization.
95 */
96 public override fun writeAnsi(writer: TextWriter) { writeCsiParameter(writer, count, "D") }
99/**
100 * Moves the cursor to the start of following lines by the supplied count. The ANSI parameter must
101 * be in 0..65535; the terminal interprets zero according to its command rules.
102 */
103public struct MoveToNextLine(val count: Long) : Command {
104 /**
105 * Writes this command's ANSI representation to the supplied writer without flushing it.
106 * Parameter validation happens before or during serialization.
107 */
108 public override fun writeAnsi(writer: TextWriter) { writeCsiParameter(writer, count, "E") }
111/**
112 * Moves the cursor to the start of preceding lines by the supplied count. The ANSI parameter must
113 * be in 0..65535; the terminal interprets zero according to its command rules.
114 */
115public struct MoveToPreviousLine(val count: Long) : Command {
116 /**
117 * Writes this command's ANSI representation to the supplied writer without flushing it.
118 * Parameter validation happens before or during serialization.
119 */
120 public override fun writeAnsi(writer: TextWriter) { writeCsiParameter(writer, count, "F") }