Post Reply 
Terminal Usage
09-01-2015, 04:52 PM
Post: #1
Terminal Usage
Is there any way to determine the current column an item is being printed in? I need a TAB function in my programs to align output. Example;

PRINT(A+TAB(20)+B);

Variable B would always print starting in column 20 no matter how large or small A was.

I don't see any way to do something like that. If there was a function such as LLOC() that gave the current position of the cursor, I could do this:

Code:

EXPORT TAB(X);
BEGIN
  LOCAL TEMP:="";
  FOR I FROM LLOC() TO X DO
    TEMP:=TEMP+" ";
  END;
  RETURN TEMP;
END;

If A was two characters long, TAB(20) would return a string of 18 blanks. If A was 5 characters long, TAB(20) would return 15 blanks. You get the idea.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
09-01-2015, 06:35 PM (This post was last modified: 09-01-2015 06:36 PM by eried.)
Post: #2
RE: Terminal Usage
Since the font in the terminal for any number has the same width per number, and each number is 2 spaces wide, why don't you pass the first number to that function?

Example:
Code:
spaces (var,len)
BEGIN
local ss:="";
for X from 0 to (len-length(var+""))*2 do ss:=ss+" "; end;
return ss;
END;

EXPORT test1()
BEGIN
local a:=1234, b:=5555;
print(a+spaces(a,20)+b);
END;

You could optimize that but is an idea.

My website: ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
09-02-2015, 05:57 PM
Post: #3
RE: Terminal Usage
(09-01-2015 06:35 PM)eried Wrote:  Since the font in the terminal for any number has the same width per number, and each number is 2 spaces wide, why don't you pass the first number to that function?

Example:
Code:
spaces (var,len)
BEGIN
local ss:="";
for X from 0 to (len-length(var+""))*2 do ss:=ss+" "; end;
return ss;
END;

EXPORT test1()
BEGIN
local a:=1234, b:=5555;
print(a+spaces(a,20)+b);
END;

You could optimize that but is an idea.

Thanks a lot! I still have the problem of minus signs and decimal points (one space instead of two) messing up the columns but it's a lot better than it was.

I still wish for a real TAB function, though, where TAB(10) would always start printing in column 10 no matter what had been printed before.
LOCATE(X,Y) to start printing at a given column and row would also be handy. Especially if you had a way to determine what row and column you were on to begin with.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
09-02-2015, 06:47 PM (This post was last modified: 09-02-2015 06:52 PM by eried.)
Post: #4
RE: Terminal Usage
Terminal is just an line/output you could create a whole complete UI drawing each text in the display where you want, check:

Code:
Syntax: TEXTOUT_P(text, [G], x, y, [font], [textColor], [width], [backgroundColor])
Draws text on graphic G at position (x, y) using font. Paints the background before drawing the text using color backgroundColor. If width is specified, does not draw text more than width pixels wide. If backgroundColor is not specified, the background is not erased.

The sizes for font are:

0=current font (default)
1=font_10
2=font_12 (Small)
3=font_14 (Medium)
4=font_16 (Large)
5=font_18
6=font_20
7=font_22

Code:
Syntax: BLIT_P([trgtG], [dx1, dy1], [dx2, dy2], srcG, [sx1, sy1], [sx2, sy2], [c])
Copies the region of graphic srcG between point (sx1, sy1) and (sx2, sy2) into the region of trgtG between points (dx1, dy1) and (dx2, dy2). Does not copy pixels from srcG that are color c.

The defaults for the optional arguments are:
trgtG=G0
srcG=G0
sx1, sy1=srcGRB top left corner
sx2, sy2=srcGRB bottom right corner
dx1, dx2=trgtGRB top left corner
dx2, dy2=calculated so destination area is the same as source area
c=all pixel colors

My website: ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
09-03-2015, 12:29 PM (This post was last modified: 09-03-2015 12:34 PM by toml_12953.)
Post: #5
RE: Terminal Usage
Thanks to eried, I created this simple LOCATE function. It only uses the default font.

Code:
EXPORT LOCATE(TEXT,X,Y)
BEGIN
  TEXTOUT(TEXT,(X-1)*10,242-(Y-1)*14);
END;

Both X and Y start at 1 and (1,1) is the upper left corner of the display. 19 lines fit on the display.

Here's a calling program:

Code:
EXPORT LOCTEST()
BEGIN
  RECT();
  X:=1;
  FOR Y FROM 1 TO 19 DO
    LOCATE("HELLO",X,Y);
    X:=X+1;
  END;
  WAIT;
END;

Thanks again, eried!

Tom L

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
09-03-2015, 12:55 PM
Post: #6
RE: Terminal Usage
Notice that _P means "pixels", so TEXTOUT_P will use pixel positions, and TEXTOUT will use coordinates (these could change)

My website: ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)