From 3b616c23feb0f47b1562db73779c4a4bc9143547 Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Mon, 13 Dec 2021 16:55:48 +0000 Subject: [PATCH] Add initial basic Cursor manipulation codes --- SigTerm.jar | Bin 869 -> 2026 bytes run | 1 + src/sig/SigTerm.java | 123 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 123 insertions(+), 1 deletion(-) diff --git a/SigTerm.jar b/SigTerm.jar index 2d1020d70490fb6babe1c963a177328ea96079c6..c1eff33e5d52509e181ec0cf93676ab8110089f8 100644 GIT binary patch delta 1574 zcmV+>2HE-L2I>zCP)h>@6aWYa2msWEkqkQm)P|8sn*s8XZBY%ySiB}Ux z9LK*agiPXEaK#G*L)98+5yYbh)CvhmG=L=mwP@P~R#=*3W3mD9?tR~vy|wq<3N7;5 z_xcC)kLv4pvdd8=eR;f@-!Z@W?9A^sGvV)l{`d>PUi|Kb>Bj*~`0xZ0UL^e}#e_gg zN=tTWfiqHO{K&!<$O%jeOn(WS6_^${CvaZig1|+AO9Gb#t_VCS@RY#QekgcGcFzht zC*||9dqLnuDPIzJS;|)gUX}7S*}X2iHw504@-2b41>TYByFPaB3A``mRoQ(Y@S(s* za#bG-d?N6v^nNCAP0H&6pG*0Lz?TAFN%dpmm=2r5iL~)6+k&Kl{NT%OWo$vYL##za> zGTbgPd5)*w$QoQ-sT@?WK6rZp^7%;WCJ`HgLo1JqwvmLJK!1PC%4J53E>osUjhSO{ zBa_@EXE8lllhYiRiXQZO@x6*4@S}o_w{kmjW@6OfT31yMsrU&$%kCEiO1p|*al?xl z6|)$jql1klR#r@Qn!(@%8RSZhfG1(oLZh!l*HE9H< ztsDbS;1O0ivNIXb?L5J@(shK!$IWcOX8HqDdNwd_WDFH2CE^ecDyZ$q$>@a;(}@U} zyb*>zN^BPnsyHG;H@BxoozN*WkqD$LJ1}enhONY?0)MFZO(u&w-tBC>g&Xgd)2Q#E z9&z=()DOG*J|}cPT~X<(SSnKA@PskK6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diff --git a/run b/run index 6fb0c57..6f70b11 100755 --- a/run +++ b/run @@ -2,4 +2,5 @@ javac --release 8 src/sig/*.java -d bin cd bin jar cfe ../SigTerm.jar sig.SigTerm sig cd .. +clear java -cp bin sig/SigTerm \ No newline at end of file diff --git a/src/sig/SigTerm.java b/src/sig/SigTerm.java index d4c5be4..552c276 100644 --- a/src/sig/SigTerm.java +++ b/src/sig/SigTerm.java @@ -1,7 +1,128 @@ package sig; public class SigTerm{ + final static String ESC = "\u001b"; + final static String CSI = "["; + final static String CSICODE = ESC+CSI; + /** + Moves the cursor *rows* cells in the given direction. If the cursor is already at the edge of the screen, this has no effect. + **/ + public static void CursorUp(int rows) { + System.out.print(CSICODE+rows+"A"); + } + /** + Moves the cursor *rows* cells in the given direction. If the cursor is already at the edge of the screen, this has no effect. + **/ + public static void CursorDown(int rows) { + System.out.print(CSICODE+rows+"B"); + } + /** + Moves the cursor *rows* cells in the given direction. If the cursor is already at the edge of the screen, this has no effect. + **/ + public static void CursorRight(int cols) { + System.out.print(CSICODE+cols+"C"); + } + /** + Moves the cursor *rows* cells in the given direction. If the cursor is already at the edge of the screen, this has no effect. + **/ + public static void CursorLeft(int cols) { + System.out.print(CSICODE+cols+"D"); + } + /** + Moves cursor to beginning of the line *lines* lines down. + **/ + public static void CursorLineDown(int lines) { + System.out.print(CSICODE+lines+"E"); + } + /** + Moves cursor to beginning of the line *lines* lines up. + **/ + public static void CursorLineUp(int lines) { + System.out.print(CSICODE+lines+"F"); + } + /** + Moves the cursor to column col. + **/ + public static void CursorSetColumn(int col) { + System.out.print(CSICODE+col+"G"); + } + /** + Moves the cursor to column *col*, row *row*. The values are 1-based. + **/ + public static void CursorSetPosition(int col,int row) { + System.out.print(CSICODE+row+";"+col+"H"); + } + /** + Clears part of the screen. If *mode* is 0, clear from cursor to end of screen. If *mode* is 1, clear from cursor to beginning of the screen. If *mode* is 2, clear entire screen. If *mode* is 3, clear entire screen and delete all lines saved in the scrollback buffer + **/ + public static void EraseDisplay(int mode) { + System.out.print(CSICODE+mode+"J"); + } + /** + Erases part of the line. If *mode* is 0, clear from cursor to the end of the line. If *mode* is 1, clear from cursor to beginning of the line. If *mode* is 2, clear entire line. Cursor position does not change. + **/ + public static void EraseLine(int mode) { + System.out.print(CSICODE+mode+"K"); + } + /** + Scroll whole page up by *lines* lines. New lines are added at the bottom. + **/ + public static void ScrollUp(int lines) { + System.out.print(CSICODE+lines+"S"); + } + /** + Scroll whole page down by *lines* lines. New lines are added at the top. + **/ + public static void ScrollDown(int lines) { + System.out.print(CSICODE+lines+"T"); + } + /** + Sets the color of all following text to (r,g,b). Colors can be between 0-255. + **/ + public static void TextColor(int r,int g, int b) { + System.out.print(CSICODE+"2;"+r+";"+g+";"+b+"m"); + } + /**Clears all formatting currently applied via Text Functions.**/public static String RESET = CSICODE+"0m"; + /**Applies Bold.**/public static String BOLD = CSICODE+"1m"; + /**Applies a faint effect to text.**/public static String DIM = CSICODE+"2m"; + /**Applies Italics.**/public static String ITALIC = CSICODE+"3m"; + /**Applies Underline.**/public static String UNDERLINE = CSICODE+"4m"; + /**Applies a slow blink.**/public static String BLINK = CSICODE+"5m"; + /**Applies a rapid blink.**/public static String FASTBLINK = CSICODE+"6m"; + public static void Reset() { + System.out.print(CSICODE+"0m"); + } + /** + Prints text to the console at the current cursor position. + **/ + public static void Text(String text) { + System.out.print(text); + } public static void main(String[] args) { - System.out.println("Hello World!"); + EraseDisplay(2); + CursorUp(3); + Text("Test"); + CursorDown(3); + Text("Test2"); + CursorRight(5); + Text("I am on the right!"); + CursorLeft(30); + Text("Lefty"); + CursorLineDown(2); + Text("Test"); + CursorLineUp(3); + CursorSetColumn(6); + Text("Above you!"); + CursorLineDown(3); + CursorSetPosition(20,1); + Text("I'm at the top!"); + CursorSetPosition(1,6); + Text("This text was here"); + EraseLine(2); + Text(BOLD+"But this text is here instead!"); + Text(RESET); + CursorLineDown(1); + Text(BLINK+"And this will not be bold"); + System.out.println(""); } } \ No newline at end of file