Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 04:52 06 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : VT100 Output Help.

     Page 1 of 2    
Author Message
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 10:38am 15 Jun 2017
Copy link to clipboard 
Print this post

Hi All,

Can anyone see what I'm doing wrong here?

On the output screen, the "Active Point" is marked with a "*" at the beginning of the line.

It's hard to follow that line easily with the eyes, so I thought I'd simply underline it.

I can get that working, but then the formatting changes; Stuff moves to the left...





Esc[4m attribute set to underline the active point, & stuff is moved left.



This is the code that's writing the screen.

The line to set the underlined attribute is shown commented out.

After the point number & description are printed he TAB(18) is supposed to move to column 18 before the C_Val is printed.

That seems to be what fails when the attribute is set.


  Quote   Print Esc+"[f"; 'Move cursor to upper left corner
Print " P# Description M C_Val Pre_3 Pre_2 Pre_1 R_Val D_Val On/Up Of/Dn";Esc+"[K" ' Clear to EOL
Print "================================================================================";Esc+"[K"

For Pn=1 To Last_Pt
IF S_Desc$(Pn)<>"" And Pn > 9 Then
'If Pn=Pt then Print Esc+"[4m"; Else Print Esc+"[4m"; 'Set the Underline Attribute for Active Point
IF Pn=Pt Then Print "* "; Else Print " ";
Print Str$(Pn,2);" ";S_Desc$(Pn);Tab(18);
IF I(Pn,Mode)=1 Then Print " A"; Else Print " D";
Print Str$(V(Pn,Cln_Val),4,2);Str$(V(Pn,Prev_Val3),4,2);Str$(V(Pn,Prev_Val2),4,2);Str$(V(Pn,Prev_Val1),4,2);
Print Str$(V(Pn,Value),4,2);Str$(V(Pn,Def_Val),4,2);
Print Str$(I(Pn,Curr_onup),4);"/";Str$(I(Pn,Time_onup));Tab(70);Str$(I(Pn,Curr_offdwn),3);"/";Str$(I(Pn,Time_offdwn));Esc+"[K"
End IF
Next Pn

Print Esc+"[J"; 'Clear to end of Screen....
Print Esc+"[22;1f"; 'Move Cursor to line 22
Print "--------------------------------------------------------------------------------"
Print "Options:- (P)-Change Point. (A/D)-Mode. (*)-Default. (+/-)-Up/Down Counters"
Print "Current Time is :- "; Time$;" System Up Time is:- "; UpTime();Esc+"[f";
request_DO
20,0 'green light off



Thanks

Phil.

 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 11:21am 15 Jun 2017
Copy link to clipboard 
Print this post

I think it's something to do with the TAB().

If I try padding it out with spaces, I end up with a mess, Double spaced etc,
And I lose the alignment of the /'s separating the On/Up & Of/Dn values if they contain 2 digit values.

Works fine until I try to introduce the attribute to underline the current point.
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 12:09pm 15 Jun 2017
Copy link to clipboard 
Print this post

@Phil23

Out of interest, does the weird formatting issue still occur IF instead you use a colour code setting to change the colour of the 'highlighted' line (instead of setting it with an underline escape code)?

I have come across a weird issue with TeraTerm which appeared to show incorrect formatting - however, it then worked when using PuTTY. Maybe worth seeing if PuTTY works with your underline code.

I am not in front of a MM at moment to be able to try this out - sorry

WW




For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5914
Posted: 12:41pm 15 Jun 2017
Copy link to clipboard 
Print this post

I have never liked TABs. Always cause grief.
TAB does different things depending on the terminal/text editor.

Why don't you pad all the S_Desc$(Pn) descriptions out to the same length with spaces and do away with the TAB altogether.
That will give you total control over the layout no matter which terminal you use to view it (or even pasting into a text editor)

Jim

VK7JH
MMedit   MMBasic Help
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 12:43pm 15 Jun 2017
Copy link to clipboard 
Print this post

  WhiteWizzard said  Out of interest, does the weird formatting issue still occur IF instead you use a colour code setting to change the colour of the 'highlighted' line (instead of setting it with an underline escape code)?


That was my first idea, to use colours, but it had similar issues, and was also breaking lines in two.

Not sure what you are referring to as colour codes;
I just tried colours with VT attributes.

IE

[Code]
Yellow - Esc[33m
Blue - Esc[34m

and for the underline I used

Underline - Esc[4m
Normal - Esc[0m
[/code]

Using the colours I get this.



 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 01:02pm 15 Jun 2017
Copy link to clipboard 
Print this post

Pretty much the same in PuTTY.

Need to look at the HEX output, as I think the TAB is causing the issues.

It's almost as if the characters used in the Esc codes are adding to the cursor position counter when MMBasic tries to output the spaces.

 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 01:23pm 15 Jun 2017
Copy link to clipboard 
Print this post

This is the HEX capture of what the Micromite is outputting when the underline is set.

Haven't tried to identify the TABS yet; work is calling.

Phil

[Code]
30 30 3A 32 30 1B 5B 66 1B 5B 66 20 20 50 23 20 00:20.[f.[f P#
44 65 73 63 72 69 70 74 69 6F 6E 20 20 4D 20 20 Description M
43 5F 56 61 6C 20 20 50 72 65 5F 33 20 20 50 72 C_Val Pre_3 Pr
65 5F 32 20 20 50 72 65 5F 31 20 20 52 5F 56 61 e_2 Pre_1 R_Va
6C 20 20 44 5F 56 61 6C 20 20 4F 6E 2F 55 70 20 l D_Val On/Up
20 4F 66 2F 44 6E 1B 5B 4B 0D 0A 3D 3D 3D 3D 3D Of/Dn.[K..=====
3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D ================
3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D ================
3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D ================
3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D ================
3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 1B 5B 4B 0D 0A ===========.[K..
1B 5B 30 6D 20 20 31 31 20 41 6D 62 69 65 6E 74 .[0m 11 Ambient
20 20 20 41 20 20 31 31 2E 37 35 20 20 31 31 2E A 11.75 11.
36 33 20 20 31 31 2E 36 39 20 20 31 31 2E 37 35 63 11.69 11.75
20 20 31 31 2E 37 35 20 20 32 34 2E 30 30 20 20 11.75 24.00
20 31 2F 35 20 20 20 20 31 2F 35 1B 5B 4B 0D 0A 1/5 1/5.[K..
1B 5B 34 6D 2A 20 31 32 20 52 6F 6F 66 5F 54 65 .[4m* 12 Roof_Te
6D 70 20 41 20 20 31 36 2E 32 35 20 20 31 36 2E mp A 16.25 16.
33 31 20 20 31 36 2E 33 31 20 20 31 36 2E 32 35 31 16.31 16.25
20 20 31 36 2E 32 35 20 20 32 36 2E 30 30 20 20 16.25 26.00
20 31 2F 35 20 20 20 20 31 2F 35 1B 5B 4B 0D 0A 1/5 1/5.[K..
1B 5B 30 6D 20 20 31 33 20 4C 5F 44 5F 54 65 6D .[0m 13 L_D_Tem
70 20 20 41 20 20 32 31 2E 37 35 20 20 32 31 2E p A 21.75 21.
37 35 20 20 32 31 2E 37 35 20 20 32 31 2E 37 35 75 21.75 21.75
20 20 32 31 2E 37 35 20 20 32 33 2E 30 30 20 20 21.75 23.00
20 31 2F 35 20 20 20 20 31 2F 35 1B 5B 4B 0D 0A 1/5 1/5.[K..
1B 5B 30 6D 20 20 31 34 20 42 65 64 5F 54 6D 70 .[0m 14 Bed_Tmp
20 20 20 41 20 20 31 35 2E 38 31 20 20 31 35 2E A 15.81 15.
38 31 20 20 31 35 2E 38 31 20 20 31 35 2E 38 31 81 15.81 15.81
20 20 31 35 2E 38 31 20 20 32 35 2E 30 30 20 20 15.81 25.00
20 31 2F 35 20 20 20 20 31 2F 35 1B 5B 4B 0D 0A 1/5 1/5.[K..
1B 5B 30 6D 20 20 31 35 20 46 72 6F 6E 74 5F 4F .[0m 15 Front_O
66 66 20 41 20 20 31 37 2E 35 36 20 20 31 37 2E ff A 17.56 17.
35 36 20 20 31 37 2E 35 36 20 20 31 37 2E 35 36 56 17.56 17.56
20 20 31 37 2E 35 36 20 20 32 34 2E 30 30 20 20 17.56 24.00
20 31 2F 35 20 20 20 20 31 2F 35 1B 5B 4B 0D 0A 1/5 1/5.[K..
1B 5B 30 6D 20 20 31 36 20 42 61 63 6B 5F 4F 66 .[0m 16 Back_Of
66 20 20 41 20 20 31 37 2E 35 30 20 20 31 37 2E f A 17.50 17.
34 34 20 20 31 37 2E 35 30 20 20 31 37 2E 35 30 44 17.50 17.50
20 20 31 37 2E 35 30 20 20 32 34 2E 30 30 20 20 17.50 24.00
20 31 2F 35 20 20 20 20 31 2F 35 1B 5B 4B 0D 0A 1/5 1/5.[K..
[/code]
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 01:28pm 15 Jun 2017
Copy link to clipboard 
Print this post

  TassyJim said  Why don't you pad all the S_Desc$(Pn) descriptions out to the same length with spaces and do away with the TAB altogether.


Padding the descriptors would probably make them hard to use elsewhere in the code, and I'm not sure how I would deal with keeping the Slashes in a line when a 2 digit number is used for the on/up etc.

But I'm open to any suggestions.

Lines are just hard to read across when they are mid screen for a selected point.

Phil
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5914
Posted: 02:17pm 15 Jun 2017
Copy link to clipboard 
Print this post

If you don't want to change the descriptors,
padd as required as you print
  Quote   PRINT STR$(Pn,2);" ";LEFT$(S_Desc$(Pn)+" ",16);

The 16 might need adjustment.

MMBasic doesn't know that your 'underline' code is not a printable character so it is counted as printable.
If you want to stick with TABs, you could also adjust the TAB(18) to TAB(xx) whenever you do the underline.

Jim
VK7JH
MMedit   MMBasic Help
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 03:16pm 15 Jun 2017
Copy link to clipboard 
Print this post

Why not just output a real tab.
It is CHR$(9).
You still have to make sure the string you output is same length as a tab is left aligned and your numbers are right aligned.

Having the output using tabs will make it a lot easier to import the output to a spreadsheet or other program.

Microblocks. Build with logic.
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2290
Posted: 04:40pm 15 Jun 2017
Copy link to clipboard 
Print this post

the below function, at$(), may be of some help to you:

clrscr

For X = 1 To 10
For Y = 1 To 5
Print at$((X*5)+10,(Y*2)+2) X*Y
Next Y
Next X

Print at$(1, 20) "press enter to exit ";
Line Input S$
End


Function at$(x,y)
at$=Chr$(27)+"["+Str$(Y)+";"+Str$(X)+"H"
End Function

Sub clrscr
Print Chr$(27)+"[2J";
End Sub


clrscr
Print at$(21,3) ca$(4) "Colour MicroMite Demonstration"

For B=30 To 37
For C=40 To 47
Print at$((B-25)*4, C-35) ca$(1, B, C) "abcd"
Next C: Next B

For A=0 To 9
Print at$(17+(A*4),14) ca$(0, 37, 40) Str$(A)
Print at$(16+(A*4),16) ca$(A, 37, 40) "xxx"
Next A

Print at$(1, 20) ca$() "press enter to exit ";
Line Input S$
End


Function at$(x,y)
at$=Chr$(27)+"["+Str$(Y)+";"+Str$(X)+"H"
End Function

Function ca$(A, B, C)
Local temp$
temp$=Chr$(27)+"["+Str$(A)
If B<>0 Then temp$=temp$+";"+Str$(B)
If C<>0 Then temp$=temp$+";"+Str$(C)
ca$=temp$+"m"
End Function

Sub clrscr
Print Chr$(27)+"[2J";
End Sub



cheers,
rob :-)Edited by robert.rozee 2017-06-17
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 12:24am 16 Jun 2017
Copy link to clipboard 
Print this post

  TassyJim said  MMBasic doesn't know that your 'underline' code is not a printable character so it is counted as printable.
If you want to stick with TABs, you could also adjust the TAB(18) to TAB(xx) whenever you do the underline.


Thanks All,

That's exactly what I discovered from the HEX output.
Because MMbasic is incrementing the cursor position for the control codes, excluding the Esc, the [4m adds 3 to the cursor position, hence the TAB command adds 3 less spaces than required.

I fried my brain a little trying to read the HeX output in Teraterm, before waking up to myself & realising Jim's HEX display in MMedit is far superior, having both Hex & Text on the screen, as any Hex display should offer.

So yes, TAB(18) became TAB(21) & the 70 became 73.

More readable now with the underline.....







 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 12:14pm 16 Jun 2017
Copy link to clipboard 
Print this post

@Phil23

Immediately thought of you as I read the opening sentence to this article
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3018
Posted: 03:11am 17 Jun 2017
Copy link to clipboard 
Print this post

  WhiteWizzard said   @Phil23--Immediately thought of you as I read the opening sentence to this article

From the article (re spaces vs tabs):
  Quote  "Spaces versus tabs is the Pepsi or Coke question for developers," said Jordan Poulton, a spokesman for London's Makers Academy that teaches people to code.
"It's almost impossible to draw an objective conclusion about which is the best," he said.

Yet:
  Quote  Computer programmers who use spaces as part of their coding earn $15,370 (£12,000) more per year than those who use tabs.
(survey of 12,400 developers).

One could draw the "(non-?)objective conclusion" that if you code professionally in a variety of languages, and sometimes move your code for display or documentation purposes to an environment other than the one you use for coding, you will find out that tabs often cause display problems, and spaces never do.

Edited by lizby 2017-06-18
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 04:13am 17 Jun 2017
Copy link to clipboard 
Print this post

  lizby said  .... and sometimes move your code for display or documentation purposes to an environment other than the one you use for coding, you will find out that tabs often cause display problems, and spaces never do....

I find that when using spaces i have no control how the source looks like. Some people use two spaces, some four spaces for indentation.
When it is done with tabs i can setup my preferences in my editor so that it looks like I want it to look like.
Hence i always use tabs and never spaces.
Also using proportional fonts that are so much better to read and use space much more efficiently will completely destroy a layout when spaces are used. With tabs again much more control and even proportional fonts will not completely mess up indentation.
Especially when code snippets are used in documentation tabs will make the editing process a lot easier.

Most editors nowadays will replace tabs with spaces while you type, without you noticing it.
Until you have to go print out some, then you are in for a treat.
All my editors are setup to use real tabs. Prevents a lot of time wasting editing later on.Edited by MicroBlocks 2017-06-18
Microblocks. Build with logic.
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 11:02pm 17 Jun 2017
Copy link to clipboard 
Print this post

I can see there the TAB() gives me grief, & usually my screen layouts are controlled by the space characters.

In this one, keeping all the forward slashes in a vertical line is required for the layout to appear correct.

Doing that with spacing became messy & long winded, while the Tab worked just fine until Introduced some control sequences.

Phil.

 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 11:46pm 17 Jun 2017
Copy link to clipboard 
Print this post

instead of TAB() use chr$(9).
Still even with that you will need to make sure your numbers are formatted with equal length so that you can right align them.
As such it does not really matter what you use as a way to separate those values, you always have to make them fixed length before displaying.
The easiest way to do that is with STR$() as you already did.

The only difficulty arises with the '/' that needs to be aligned.
[code]
Print Str$(I(Pn,Curr_onup),4);"/";Str$(I(Pn,Time_onup));Tab(70);Str$(I(Pn,Curr_offdwn),3);"/";Str$(I(Pn,Time_offdwn));Esc+"[K"
[/code]
change that into:
[code]
Print Str$(I(Pn,Curr_onup),4);"/";left$(Str$(I(Pn,Time_onup)) + " ", 4);Str$(I(Pn,Curr_offdwn),3);"/";left$(Str$(I(Pn,Time_offdwn) + " ", 4);Esc+"[K"
[/code]

Above is untested, so play with it a bit.
Edited by MicroBlocks 2017-06-19
Microblocks. Build with logic.
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2290
Posted: 11:59pm 17 Jun 2017
Copy link to clipboard 
Print this post

phil, the at$(x,y) function i posted earlier will allow you to position the cursor at an exact location on the screen, will this not achieve what you are after?

multiple calls to at$(x,y) can be embedded in a single print statement, allowing you to reposition the cursor for each item in a multi-item print statement. the only thing you will need to ensure is that the numbers or strings you are printing are of a fixed field width each time round.


cheers,
rob :-)
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 10:19am 18 Jun 2017
Copy link to clipboard 
Print this post

  robert.rozee said   phil, the at$(x,y) function i posted earlier will allow you to position the cursor at an exact location on the screen, will this not achieve what you are after?


Thanks Rob,

Yes, it will achieve exactly what I want & I plan on adding that function to all my screen output code. It will make life easier.

Unfortunately I have one of those problem solving minds that needs to know why somethings not working.

TAB() worked fine just plain text, but issues appeared when adding other attributes & control code.

Puttting TAB() aside because it wasn't working properly, was tainted by one thing...
Why???

I understand it's short comings now & can move on from it.
Painful & time wasting, but it's how my head works.

Cheers

Phil.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5914
Posted: 12:58pm 18 Jun 2017
Copy link to clipboard 
Print this post

  Phil23 said  
Puttting TAB() aside because it wasn't working properly, was tainted by one thing...
Why???

Phil.


In MMBasic, TAB(x) inserts extra space characters into the PRINT stream to increase the size of the stream to the number in the TAB command.
MMBasic has no idea where the data is going to or if the receiver interprets any characters as other than printing characters.
TAB() is just one of the ways you can format your data before sending it.
MMBasic seems to ignore some control codes when counting character positions.

Sending a TAB character CHR$(9) requires the receiving device to do the formatting. In the case of a VT100 terminal, the tab stops can be set at any position so you would normally send the commands to clear all currently set positions and then set the required positions before using CHR$(9). If you rely on the tab stops being set before you send your data, you may be in for a few surprises.

The other way control print locations is to use the VT100 commands to locate the cursor. Rob's at$() functions makes this easier to do. You need to set the line as well as column each time. This can add more work in keeping track of the line position but gives the most control.

Earlier versions of MMBasic used the PRINT @x,y command to print at specified locations on the screen. It was intended for use on graphic screens but would also send the VT100 positioning commands (suitably scaled) to the console.

Jim
VK7JH
MMedit   MMBasic Help
 
     Page 1 of 2    
Print this page
© JAQ Software 2024