控制终端光标和字体或擦除内容。 使用彩色和动态的输出字符串构建现代、交互式的命令行工具。
https://en.wikipedia.org/wiki/ANSI_escape_code
目录
将 ANSIEscapeCode 添加到 Package.swift
。
dependencies: [
.package(url: "https://github.com/flintbox/ANSIEscapeCode", from: "0.1.1")
]
\u{001B}[(n)A
:将光标向上移动 n
个单元格(默认为 1)。
ANSIEscapeCode.Cursor.up(3) // \u{001B}[3A
moveCursorUp() /// Move cursor up 1 cell.
\u{001B}[(n)B
:将光标向下移动 n
个单元格(默认为 1)。
ANSIEscapeCode.Cursor.down() // \u{001B}[1B
moveCursorDown(5) /// Move cursor down 5 cells.
\u{001B}[(n)C
:将光标向前移动 n
个单元格(默认为 1)。
ANSIEscapeCode.Cursor.forward(9) // \u{001B}[9C
moveCursorForward(4) // Move cursor forward 4 cells.
\u{001B}[(n)D
:将光标向后移动 n
个单元格(默认为 1)。
ANSIEscapeCode.Cursor.backward() // \u{001B}[1D
moveCursorBackward(2) // Move cursor backward 2 cells.
\u{001B}[(n)E
:将光标移动到下方 n
行(默认为 1)的行首。
ANSIEscapeCode.Cursor.nextLine(2) // \u{001B}[2E
moveCursorNextLine() // Move cursor to next line.
\u{001B}[(n)F
:将光标移动到上方 n
行(默认为 1)的行首。
ANSIEscapeCode.Cursor.previousLine(3) // \u{001B}[3F
moveCursorPreviousLine(5) // Move cursor to next line 5 times.
\u{001B}[(n)G
:将光标移动到第 n
列。
ANSIEscapeCode.Cursor.column(2) // \u{001B}[2G
moveCursorToColumn(2) // Move cursor to second column.
\u{001B}[(n);(m)1H
:将光标移动到第 n
行,第 m
列。
ANSIEscapeCode.Cursor.position(row: 1, column: 1) // \u{001B}[1;1H
moveCursorToPosition(row: 5, column: 10) // Move cursor to position row 5 and column 10.
\u{001B}[s
:保存光标位置。
ANSIEscapeCode.Cursor.saveCursorPosition // \u{001B}[s
saveCursorPosition() // Save cursor position.
\u{001B}[u
:恢复光标位置。
ANSIEscapeCode.Cursor.restoreCursorPosition // \u{001B}[u
restoreCursorPosition() // Restore cursor position.
\u{001B}[?25l
:隐藏光标。
ANSIEscapeCode.Cursor.hideCursor // \u{001B}[?25l
hideCursor() // Hide cursor.
\u{001B}[?25h
:显示光标。
ANSIEscapeCode.Cursor.showCursor // \u{001B}[?25h
showCursor() // Show cursor.
\u{001B}[(n)J
:清除屏幕的一部分。如果 n
为 0(或缺失),则从光标处清除到屏幕末尾。 如果 n
为 1,则从光标处清除到屏幕开头。 如果 n
为 2,则清除整个屏幕。
ANSIEscapeCode.Erase.eraseInDisplay(.entireScreen) // \u{001B}[2J
eraseInDisplay(.fromCursorToBeginningOfScreen) // Erase content from cursor to beginning of screen.
\u{001B}[(n)K
:擦除该行的一部分。 如果 n
为零(或缺失),则从光标处清除到行尾。 如果 n
为 1,则从光标处清除到行首。 如果 n
为 2,则清除整行。 光标位置不变。
ANSIEscapeCode.Erase.eraseInLine(.fromCursorToEndOfLine) // \u{001B}[0K
eraseInLine(.entireLine) // Erase entire line.
\u{001B}[(n)S
:将整个页面向上滚动 n
行(默认为 1)。 新行添加到底部。
ANSIEscapeCode.Scroll.up() // \u{001B}[1S
scrollUp(3) // Scroll up screen 3 lines.
\u{001B}[(n)T
:将整个页面向下滚动 n
行(默认为 1)。 新行添加到顶部。
ANSIEscapeCode.Scroll.down(5) // \u{001B}[5T
scrollDown() // Scroll down screen 1 line.
\u{001B}[0m
:重置所有装饰属性。
ANSIEscapeCode.Decoration.reset // \u{001B}[0m
\u{001B}[39m
:重置背景装饰属性。
ANSIEscapeCode.Decoration.resetBackgroundColor // \u{001B}[39m
\u{001B}[1m
:使输出变为粗体。
ANSIEscapeCode.Decoration.bold // \u{001B}[1m
print("bold text".boldOutput) // Print bold text.
\u{001B}[3m
:使输出变为斜体。
ANSIEscapeCode.Decoration.italic // \u{001B}[3m
print("italic text".italicOutput) // Print italic text.
\u{001B}[4m
:使输出带有下划线。
ANSIEscapeCode.Decoration.underline // \u{001B}[4m
print("underline text".underlineOutput) // Print underline text.
\u{001B}[5m
:使输出闪烁。
ANSIEscapeCode.Decoration.blink // \u{001B}[5m
print("blinking text".blinkOutput) // Print blinking text.
\u{001B}[(COLOR)m
设置终端上的文本颜色。 查看TextColor.swift
以获取可用颜色。
ANSIEscapeCode.Decoration.textColor(.red) // \u{001B}[31m
print("red text".color(.red)) // Print red text.
\u{001B}[38;5;(COLOR)m
设置终端上的文本 8 位颜色。查看这里 获取可用颜色。
ANSIEscapeCode.Decoration.text8BitsColor(200) // \u{001B}[38;5;200m
print("orange text".colorFrom8BitsColorSet(208)) // Print orange text.
\u{001B}[38;2;(RED);(GREEN);(BLUE)m
设置终端上的文本 RGB 颜色。 查看这里 获取更多信息。
ANSIEscapeCode.Decoration.textRGBColor(red: 30, green: 20, blue: 10) // \u{001B}[38;2;30;20;10m
print("mint text".colorFromRGBColorSet(red: 170, green: 240, blue: 209)) // Print mint text.
\u{001B}[(COLOR)m
设置终端上的文本背景颜色。 查看BackgroundColor.swift
以获取可用颜色。
ANSIEscapeCode.Decoration.backgroundColor(.red) // \u{001B}[41m
print("red background".backgroundColor(.red)) // Print text with red background.
\u{001B}[38;5;(COLOR)m
设置终端上的文本背景 8 位颜色。 查看这里 获取可用颜色。
ANSIEscapeCode.Decoration.background8BitsColor(200) // \u{001B}[48;5;200m
print("orange background".backgroundColorFrom8BitsColorSet(208)) // Print text with orange background.
\u{001B}[48;2;(RED);(GREEN);(BLUE)m
设置终端上的文本背景 RGB 颜色。 查看这里 获取更多信息。
ANSIEscapeCode.Decoration.backgroundRGBColor(red: 30, green: 20, blue: 10) // \u{001B}[48;2;30;20;10m
print("mint background".backgroundColorFromRGBColorSet(red: 170, green: 240, blue: 209)) // Print text with mint background.
如果您有好的想法或建议? 请随时提出 pull request 或发送 电子邮件 给我们。
希望您喜欢使用 ANSIEscapeCode 构建命令行工具!