Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit to easier print colored text #77

Open
EmilyGraceSeville7cf opened this issue Apr 21, 2024 · 0 comments
Open

Unit to easier print colored text #77

EmilyGraceSeville7cf opened this issue Apr 21, 2024 · 0 comments

Comments

@EmilyGraceSeville7cf
Copy link

unit helper;

interface
uses crt;

type
  strings = array of string;
  integers = array of integer;
  booleans = array of boolean;
  
  unique_strings = set of string;
  unique_integers = set of integer;
  unique_booleans = set of boolean;
  
  JColor = android_graphics_Color;
  
  JList = java_util_ArrayList;
  JSet = java_util_HashSet;
  JMap = java_util_TreeMap;
  
  JStack = java_util_Stack;
  JQueue = java_util_PriorityQueue;
  JDeque = java_util_ArrayDeque;
  
  TColor = record
    foreground, background: integer;
  end;

function javaList(): JList;
function javaSet(): JSet;
function javaMap(): JMap;

function javaStack(): JStack;
function javaQueue(): JQueue;
function javaDeque(): JDeque;

function clARGB(a, r, g, b: integer): integer;
function clRGB(r, g, b: integer): integer;

function clNew(foreground, background: integer): TColor;
procedure clSet(cl: TColor);

procedure clWrite(cl: TColor; value: string);
procedure clWriteln(cl: TColor; value: string);
procedure clWrite(cl: TColor; value: integer);
procedure clWriteln(cl: TColor; value: integer);
procedure clWrite(cl: TColor; value: boolean);
procedure clWriteln(cl: TColor; value: boolean);
procedure clWrite(value: JList);
procedure clWriteln(value: JList);

procedure clBlack(value: string);
procedure clWhite(value: string);
procedure clRed(value: string);
procedure clYellow(value: string);
procedure clGreen(value: string);
procedure clBlue(value: string);

procedure clBlack(value: integer);
procedure clWhite(value: integer);
procedure clRed(value: integer);
procedure clYellow(value: integer);
procedure clGreen(value: integer);
procedure clBlue(value: integer);

procedure clBlack(value: boolean);
procedure clWhite(value: boolean);
procedure clRed(value: boolean);
procedure clYellow(value: boolean);
procedure clGreen(value: boolean);
procedure clBlue(value: boolean);

procedure clBlackln(value: string);
procedure clWhiteln(value: string);
procedure clRedln(value: string);
procedure clYellowln(value: string);
procedure clGreenln(value: string);
procedure clBlueln(value: string);

procedure clBlackln(value: integer);
procedure clWhiteln(value: integer);
procedure clRedln(value: integer);
procedure clYellowln(value: integer);
procedure clGreenln(value: integer);
procedure clBlueln(value: integer);

procedure clBlackln(value: boolean);
procedure clWhiteln(value: boolean);
procedure clRedln(value: boolean);
procedure clYellowln(value: boolean);
procedure clGreenln(value: boolean);
procedure clBlueln(value: boolean);

procedure clInfo(value: string);
procedure clWarn(value: string);
procedure clErr(value: string);

procedure clInfoln(value: string);
procedure clWarnln(value: string);
procedure clErrln(value: string);


implementation
const
  InfoPrefix = '[information]:';
  WarnPrefix = '[warning]:';
  ErrPrefix = '[error]:';
  
  ListLikeBorders = '[]';
  
  Delimiter = ', ';
  
  BorderColor = Red;
  DelimiterColor = Green;
  ItemColor = Yellow;


function javaList(): JList;
var
  list: JList;

begin
  new(list);
  javaList := list;
end;

function javaSet(): JSet;
var
  set_: JSet;

begin
  new(set_);
  javaSet := set_;
end;

function javaMap(): JMap;
var
  map: JMap;

begin
  new(map);
  javaMap := map;
end;

function javaStack(): JStack;
var
  stack: JStack;

begin
  new(stack);
  javaStack := stack;
end;

function javaQueue(): JQueue;
var
  queue: JQueue;

begin
  new(queue);
  javaQueue := queue;
end;

function javaDeque(): JDeque;
var
  deque: JDeque;

begin
  new(deque);
  javaDeque := deque;
end;  
  
function clARGB(a, r, g, b: integer): integer;
var
  generator: JColor;


begin
  clARGB := generator.argb(a, r, g, b);
end; 

function clRGB(r, g, b: integer): integer;
begin
  clRGB := clARGB(0, r, g, b);
end; 

function clNew(foreground, background: integer): TColor;
var
  color: TColor;


begin
  color.foreground := foreground;
  color.background := background;
  clNew := color;
end; 

procedure clSet(cl: TColor);
begin
  textColor(cl.foreground);
  textBackground(cl.background);
end; 

procedure clWrite(cl: TColor; value: string);
begin
  clSet(cl);
  Write(value);
end; 

procedure clWriteln(cl: TColor; value: string); 
begin
  clSet(cl);
  Writeln(value);
end; 

procedure clWrite(cl: TColor; value: integer); 
begin
  clSet(cl);
  Write(value);
end; 

procedure clWriteln(cl: TColor; value: integer); 
begin
  clSet(cl);
  Writeln(value);
end;

procedure clWrite(cl: TColor; value: boolean); 
begin
  clSet(cl);
  Write(value);
end; 

procedure clWriteln(cl: TColor; value: boolean); 
begin
  clSet(cl);
  Writeln(value);
end; 

procedure clWriteColored(cl: integer; value: string);
begin
  TextColor(cl);
  Write(value);
end;

procedure clWriteColored(cl: integer; value: integer);
begin
  TextColor(cl);
  Write(value);
end;

procedure clWriteColored(cl: integer; value: boolean);
begin
  TextColor(cl);
  Write(value);
end;

procedure clWriteColoredln(cl: integer; value: string);
begin
  TextColor(cl);
  Writeln(value);
end;

procedure clWriteColoredln(cl: integer; value: integer);
begin
  TextColor(cl);
  Writeln(value);
end;

procedure clWriteColoredln(cl: integer; value: boolean);
begin
  TextColor(cl);
  Writeln(value);
end;

procedure clWrite(value: JList);
var
  i: integer;

begin
  clWriteColored(BorderColor, ListLikeBorders[1]);
  
  if value.size() > 0 then
    clWriteColored(ItemColor, value.get(0));
  
  for i := 1 to value.size() - 1 do
  begin
    clWriteColored(DelimiterColor, Delimiter);
    clWriteColored(ItemColor, value.get(i));
  end;
  
  clWriteColored(BorderColor, ListLikeBorders[2]);
end;

procedure clWriteln(value: JList);
begin
  clWrite(value);
  Writeln();
end;

procedure clBlack(value: string);
begin 
  clWriteColored(Black, value);
end;

procedure clWhite(value: string);
begin 
  clWriteColored(White, value);
end;

procedure clRed(value: string);
begin 
  clWriteColored(Red, value);
end;

procedure clYellow(value: string);
begin 
  clWriteColored(Yellow, value);
end;

procedure clGreen(value: string);
begin 
  clWriteColored(Green, value);
end;

procedure clBlue(value: string);
begin 
  clWriteColored(Blue, value);
end;

procedure clBlack(value: integer);
begin 
  clWriteColored(Black, value);
end;

procedure clWhite(value: integer);
begin 
  clWriteColored(White, value);
end;

procedure clRed(value: integer);
begin 
  clWriteColored(Red, value);
end;

procedure clYellow(value: integer);
begin 
  clWriteColored(Yellow, value);
end;

procedure clGreen(value: integer);
begin 
  clWriteColored(Green, value);
end;

procedure clBlue(value: integer);
begin 
  clWriteColored(Blue, value);
end;

procedure clBlack(value: boolean);
begin 
  clWriteColored(Black, value);
end;

procedure clWhite(value: boolean);
begin 
  clWriteColored(White, value);
end;

procedure clRed(value: boolean);
begin 
  clWriteColored(Red, value);
end;

procedure clYellow(value: boolean);
begin 
  clWriteColored(Yellow, value);
end;

procedure clGreen(value: boolean);
begin 
  clWriteColored(Green, value);
end;

procedure clBlue(value: boolean);
begin 
  clWriteColored(Blue, value);
end;

procedure clBlackln(value: string);
begin 
  clWriteColoredln(Black, value);
end;

procedure clWhiteln(value: string);
begin 
  clWriteColoredln(White, value);
end;

procedure clRedln(value: string);
begin 
  clWriteColoredln(Red, value);
end;

procedure clYellowln(value: string);
begin 
  clWriteColoredln(Yellow, value);
end;

procedure clGreenln(value: string);
begin 
  clWriteColoredln(Green, value);
end;

procedure clBlueln(value: string);
begin 
  clWriteColoredln(Blue, value);
end;

procedure clBlackln(value: integer);
begin 
  clWriteColoredln(Black, value);
end;

procedure clWhiteln(value: integer);
begin 
  clWriteColoredln(White, value);
end;

procedure clRedln(value: integer);
begin 
  clWriteColoredln(Red, value);
end;

procedure clYellowln(value: integer);
begin 
  clWriteColoredln(Yellow, value);
end;

procedure clGreenln(value: integer);
begin 
  clWriteColoredln(Green, value);
end;

procedure clBlueln(value: integer);
begin 
  clWriteColoredln(Blue, value);
end;

procedure clBlackln(value: boolean);
begin 
  clWriteColoredln(Black, value);
end;

procedure clWhiteln(value: boolean);
begin 
  clWriteColoredln(White, value);
end;

procedure clRedln(value: boolean);
begin 
  clWriteColoredln(Red, value);
end;

procedure clYellowln(value: boolean);
begin 
  clWriteColoredln(Yellow, value);
end;

procedure clGreenln(value: boolean);
begin 
  clWriteColoredln(Green, value);
end;

procedure clBlueln(value: boolean);
begin 
  clWriteColoredln(Blue, value);
end;

procedure clMessage(cl: integer; prefix, value: string);
begin
  clWriteColored(cl, prefix + ' ' + value);
end;

procedure clMessageln(cl: integer; prefix, value: string);
begin
  clWriteColoredln(cl, prefix + ' ' + value);
end;

procedure clInfo(value: string);
begin 
  clMessage(Green, InfoPrefix, value);
end;

procedure clWarn(value: string);
begin 
  clMessage(Yellow, WarnPrefix, value);
end;

procedure clErr(value: string);
begin 
  clMessage(Red, ErrPrefix, value);
end;

procedure clInfoln(value: string);
begin 
  clMessageln(Green, InfoPrefix, value);
end;

procedure clWarnln(value: string);
begin 
  clMessageln(Yellow, WarnPrefix, value);
end;

procedure clErrln(value: string);
begin 
  clMessageln(Red, ErrPrefix, value);
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant