Skip to content

Commit

Permalink
Added ddoc and improved namings
Browse files Browse the repository at this point in the history
  • Loading branch information
al1-ce committed Dec 1, 2022
1 parent 2df9bea commit 1280cc6
Show file tree
Hide file tree
Showing 17 changed files with 849 additions and 543 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
# sily-dlang
# sily-dlang [WIP]

sily lib for d

## Modules

* sily - Core utils
* sily.dlib - [DLib](https://github.com/gecko0307/dlib) utils
* sily.dyaml - Improved [dyaml](https://github.com/dlang-community/D-YAML) node retrieving
* sily.openal - WIP
* sily.opengl - [bindbc opengl](https://github.com/BindBC/bindbc-opengl) wrapper
* sily.sdl - [bindbc sdl](https://github.com/BindBC/bindbc-sdl) wrapper and utils
14 changes: 7 additions & 7 deletions core/sily/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module sily.array;
* Params:
* val = Value to check
* vals = Array or sequence of values to check against
* Returns: if `val` is one of `vals`
* Returns: If `val` is one of `vals`
*/
bool isOneOf(T)(T val, T[] vals ...) {
foreach (T i; vals) {
Expand All @@ -17,9 +17,9 @@ bool isOneOf(T)(T val, T[] vals ...) {
/**
* Fills array with values `val` up to `size` if it's not 0
* Params:
* arr = array to fill
* val = values to fill with
* Returns: filled array
* arr = Array to fill
* val = Values to fill with
* Returns: Filled array
*/
T[] fill(T)(T[] arr, T val){

Expand All @@ -35,9 +35,9 @@ T[] fill(T)(T[] arr, T val){
/**
* Fills and returns new array with values `val` up to `size`
* Params:
* val = values to fill with
* size = amount of pos to fill
* Returns: filled array
* val = Values to fill with
* size = Amount of pos to fill
* Returns: Filled array
*/
T[] fill(T)(T val, size_t size){
T[] arr = new T[](size);
Expand Down
102 changes: 95 additions & 7 deletions core/sily/bashfmt.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ module sily.bashfmt;
import std.conv : to;
import std.stdio : write, writef;

static this() {
version(windows) {
import core.stdc.stdlib: exit;
exit(2);
}
}


alias FG = Foreground;
alias BG = Background;
Expand Down Expand Up @@ -80,26 +87,44 @@ enum FormattingReset : string {
oline = "\033[55m"
}

static this() {
version(windows) {
import core.stdc.stdlib: exit;
exit(2);
}
}

/**
* Casts args to string and writes to stdout
*
* Intended to be used to print formatting
* ---
* fwrite("White text", FG.red, "Red text", FG.reset, BG.red, "Red background", FR.fullreset);
* ---
* Params:
* args = Text or one of formatting strings
*/
void fwrite(A...)(A args) {
foreach (arg; args) {
write(cast(string) arg);
}
}

/**
* Casts args to string and writes to stdout with `\n` at the end
*
* Intended to be used to print formatting
* ---
* fwriteln("White text", FG.red, "Red text", FG.reset, BG.red, "Red background", FR.fullreset);
* ---
* Params:
* args = Text or one of formatting strings
*/
void fwriteln(A...)(A args) {
foreach (arg; args) {
write(cast(string) arg);
}
write("\n");
}

/**
* Erases `num` lines in terminal starting with current.
* Params:
* num = Number of lines to erase
*/
void eraseLines(int num) {
eraseCurrentLine();
--num;
Expand All @@ -111,59 +136,122 @@ void eraseLines(int num) {
}
}

/**
* Moves cursor in terminal to `{x, y}`
* Params:
* x = Column to move to
* y = Row to move to
*/
void moveCursorTo(int x, int y) {
writef("\033[%d;%df", x, y);
}

/**
* Moves cursor in terminal up by `lineAmount`
* Params:
* lineAmount = int
*/
void moveCursorUp(int lineAmount = 1) {
writef("\033[%dA", lineAmount);
}

/**
* Moves cursor in terminal down by `lineAmount`
* Params:
* lineAmount = int
*/
void moveCursorDown(int lineAmount = 1) {
writef("\033[%dB", lineAmount);
}

/**
* Moves cursor in terminal right by `columnAmount`
* Params:
* columnAmount = int
*/
void moveCursorRight(int columnAmount = 1) {
writef("\033[%dC", columnAmount);
}

/**
* Moves cursor in terminal left by `columnAmount`
* Params:
* columnAmount = int
*/
void moveCursorLeft(int columnAmount = 1) {
writef("\033[%dD", columnAmount);
}

/**
* Clears terminal screen and resets cursor position
*/
void clearScreen() {
write("\033[2J");
moveCursorTo(0, 0);
}

/**
* Clears terminal screen
*/
void clearScreenOnly() {
write("\033[2J");
}

/**
* Fully erases current line
*/
void eraseCurrentLine() {
write("\033[2K");
}

/**
* Erases text from start of current line to cursor
*/
void eraseLineLeft() {
write("\033[1K");
}

/**
* Erases text from cursor to end of current line
*/
void eraseLineRight() {
write("\033[K");
}

/**
* Saves cursor position to be restored later
*/
void saveCursorPosition() {
write("\033[s");
}

/**
* Restores saved cursor position (moves cursor to saved pos)
*/
void restoreCursorPosition() {
write("\033[u");
}

/**
* Hides cursor. Does not reset position
*/
void hideCursor() {
write("\033[?25l");
}

/**
* Shows cursor. Does not reset position
*/
void showCursor() {
write("\033[?25h");
}

/**
* Intended to be used in SIGINT callback
*
* Resets all formatting and shows cursor
*/
void cleanTerminalState() nothrow @nogc @system {
import core.stdc.stdio: printf;
printf("\033[?25h\033[m");
}
Loading

0 comments on commit 1280cc6

Please sign in to comment.