tranleduy2000 / pascalnide

Pascal Compiler for Android
92 stars 25 forks source link

Code format uglifies code #71

Open EmilyGraceSeville7cf opened 2 months ago

EmilyGraceSeville7cf commented 2 months ago

Initial code:

program Test; 

uses
  Crt;

type
  TColor = record
    foreground, background: integer;
  end;
  // Create a new color from 3 color components

function clARGB(a, r, g, b: integer) : integer;
var
  generator: android_graphics_Color;

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

// Create a new color from 3 color components
function clRGB(r, g, b: integer) : integer;
begin
  clRGB := clARGB(0, r, g, b);
end; 

// Create a pair of colors
function clNew(foreground, background: integer) : TColor;
var
  color: TColor;

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

// Set text and its background color based on the color pair
procedure clSet(cl: TColor);
begin
  textColor(cl.foreground);
  textBackground(cl.background);
end;

// Write a colored text
procedure clWrite(cl: TColor;
value: string); 
begin
  clSet(cl);
  Write(value);
end; 

var
  cl: TColor;

begin
  cl := clNew(clRGB(255, 0, 0), clRGB(255, 255, 0));
  clWrite(cl, 'I love u, Lana');
end.

Formatted code:

program Test; 

uses
  Crt;

type
  TColor = record
    foreground, background: integer;
  end;
  // Create a new color from 3 color components

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

var
  generator: android_graphics_Color;

begin
  clARGB := generator.argb(a, r, g, b);
end; 
// Create a new color from 3 color components

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

begin
  clRGB := clARGB(0, r, g, b);
end; 
// Create a pair of colors

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

var
  color: TColor;

begin
  color.foreground := foreground;
  color.background := background;
  clNew := color;
end; 
// Set text and its background color based on the color pair

procedure clSet(cl: TColor);

begin
  textColor(cl.foreground);
  textBackground(cl.background);
end; 
// Write a colored text

procedure clWrite(cl: TColor;
value: string); 

begin
  clSet(cl);
  Write(value);
end; 

var
  cl: TColor;

begin
  cl := clNew(clRGB(255, 0, 0), clRGB(255, 255, 0));
  clWrite(cl, 'I love u, Lana');
end.

Issues found: