156 lines
5.5 KiB
Dart

// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'dart:io';
/// Abstract class providing some useful ANSI escape sequences
abstract class Sequences {
/// Clear screen (Raw Sequence) `\x1B[J`
static String escClearScreen() => '\x1B[J';
/// Clear screen from cursor to end (Raw Sequence) `\x1B[0J`
static String escClearScreenFromCursorToEnd() => '\x1B[0J';
/// Clear screen from cursor to start (Raw Sequence) `\x1B[1J`
static String escClearScreenFromCursorToStart() => '\x1B[1J';
/// Clear entire screen (Raw Sequence) `\x1B[2J`
static String escClearEntireScreen() => '\x1B[2J';
/// Clear line (Raw Sequence) `\x1B[K`
static String escClearLine() => '\x1B[K';
/// Clear line from cursor to end (Raw Sequence) `\x1B[0K`
static String escClearLineFromCursorToEnd() => '\x1B[0K';
/// Clear line from cursor to start (Raw Sequence) `\x1B[1K`
static String escClearLineFromCursorToStart() => '\x1B[1K';
/// Clear entire line (Raw Sequence) `\x1B[2K`
static String escClearEntireLine() => '\x1B[2K';
/// Move cursor up **#** lines (Raw Sequence) `\x1B[#A`
static String escMoveUp(int n) => '\x1B[${n}A';
/// Move cursor down **#** lines (Raw Sequence) `\x1B[#B`
static String escMoveDown(int n) => '\x1B[${n}B';
/// Move cursor right **#** columns (Raw Sequence) `\x1B[#C`
static String escMoveRight(int n) => '\x1B[${n}C';
/// Move cursor left **#** columns (Raw Sequence) `\x1B[#D`
static String escMoveLeft(int n) => '\x1B[${n}D';
/// Move cursor down **#** lines and place cursor at start (Raw Sequence) `\x1B[#E`
static String escMoveDownAtStart(int n) => '\x1B[${n}E';
/// Move cursor up **#** lines and place cursor at start (Raw Sequence) `\x1B[#F`
static String escMoveUpAtStart(int n) => '\x1B[${n}F';
/// Move cursor on x axis **#** columens (Raw Sequence) `\x1B[#G`
static String escMoveHorizontal(int n) => '\x1B[${n}G';
/// Move cursor on x,y axis (Raw Sequence) `\x1B[$line;${column}H`
static String escMoveCursor(int line, int column) => '\x1B[$line;${column}H';
/// Save cursor position (Raw Sequence) `\x1B7`
static String escSavePosition() => '\x1B7';
/// Restore cursor position (Raw Sequence) `\x1B8`
static String escRestorePosition() => '\x1B8';
/// Hide cursor (Raw Sequence) `\x1B[?25l`
static String escHideCursor() => '\x1B[?25l';
/// Unhide cursor (Raw Sequence) `\x1B[?25h`
static String escUnhideCursor() => '\x1B[?25h';
/// Clear screen `\x1B[J`
static void clearScreen() => write(escClearScreen());
/// Clear screen from cursor to end `\x1B[0J`
static void clearScreenFromCursorToEnd() =>
write(escClearScreenFromCursorToEnd());
/// Clear screen from cursor to start `\x1B[1J`
static void clearScreenFromCursorToStart() =>
write(escClearScreenFromCursorToStart());
/// Clear entire screen `\x1B[2J`
static void clearEntireScreen() => write(escClearEntireScreen());
/// Clear line `\x1B[K`
static void clearLine() => write(escClearLine());
/// Clear line from cursor to end `\x1B[0K`
static void clearLineFromCursorToEnd() =>
write(escClearLineFromCursorToEnd());
/// Clear line from cursor to start `\x1B[1K`
static void clearLineFromCursorToStart() =>
write(escClearLineFromCursorToStart());
/// Clear entire line `\x1B[2K`
static void clearEntireLine() => write(escClearEntireLine());
/// Move cursor up **#** lines `\x1B[#A`
static void moveUp(int n) => write(escMoveUp(n));
/// Move cursor down **#** lines `\x1B[#B`
static void moveDown(int n) => write(escMoveDown(n));
/// Move cursor right **#** columns `\x1B[#C`
static void moveRight(int n) => write(escMoveRight(n));
/// Move cursor left **#** columns `\x1B[#D`
static void moveLeft(int n) => write(escMoveLeft(n));
/// Move cursor down **#** lines and place cursor at start `\x1B[#E`
static void moveDownAtStart(int n) => write(escMoveDownAtStart(n));
/// Move cursor up **#** lines and place cursor at start `\x1B[#F`
static void moveUpAtStart(int n) => write(escMoveUpAtStart(n));
/// Move cursor on x axis **#** columens `\x1B[#G`
static void moveHorizontal(int n) => write(escMoveHorizontal(n));
/// Move cursor on x,y axis `\x1B[$line;${column}H`
static void moveCursor(int line, int column) =>
write(escMoveCursor(line, column));
/// Save cursor position `\x1B7`
static void savePosition() => write(escSavePosition());
/// Restore cursor position `\x1B8`
static void restorePosition() => write(escRestorePosition());
/// Hide cursor `\x1B[?25l`
static void hideCursor() => write(escHideCursor());
/// Unhide cursor `\x1B[?25h`
static void unhideCursor() => write(escUnhideCursor());
/// Write string in standard output
static void write(String string) {
stdout.write(string);
}
/// Write string on new line in standard output
static void writeln(String string) {
stdout.writeln(string);
}
}