Formerly I had this clunky handling of colors.
...
Now if you have FORMAT this becomes a lot less clunky.
: default-bw "%e [00m" FORMAT TYPE ;
On 29/04/2026 11:41 pm, albert@spenarnc.xs4all.nl wrote:
Formerly I had this clunky handling of colors.
...
Now if you have FORMAT this becomes a lot less clunky.
I agree the original was clunky. But whether FORMAT was necessary,
I'm less certain. Naturally, I'm too lazy to show an alternative.
But I can for your last example, as I'm sure can others ...
: default-bw "%e [00m" FORMAT TYPE ;
: default-bw ." \1b[00m" ;
On 29/04/2026 11:41 pm, albert@spenarnc.xs4all.nl wrote:
Formerly I had this clunky handling of colors.
...
Now if you have FORMAT this becomes a lot less clunky.
I agree the original was clunky. But whether FORMAT was necessary,
I'm less certain. Naturally, I'm too lazy to show an alternative.
But I can for your last example, as I'm sure can others ...
: default-bw "%e [00m" FORMAT TYPE ;
: default-bw ." \1b[00m" ;
On 29/04/2026 11:41 pm, albert@spenarnc.xs4all.nl wrote:
Formerly I had this clunky handling of colors.
...
Now if you have FORMAT this becomes a lot less clunky.
I agree the original was clunky. But whether FORMAT was necessary,
I'm less certain. Naturally, I'm too lazy to show an alternative.
But I can for your last example, as I'm sure can others ...
: default-bw "%e [00m" FORMAT TYPE ;
: default-bw ." \1b[00m" ;
In article <69f2ba42$1@news.ausics.net>, dxf <dxforth@gmail.com> wrote:
On 29/04/2026 11:41 pm, albert@spenarnc.xs4all.nl wrote:Now consider this:
Formerly I had this clunky handling of colors.
...
Now if you have FORMAT this becomes a lot less clunky.
I agree the original was clunky. But whether FORMAT was necessary,
I'm less certain. Naturally, I'm too lazy to show an alternative.
But I can for your last example, as I'm sure can others ...
: default-bw "%e [00m" FORMAT TYPE ;
: default-bw ." \1b[00m" ;
: AT-XY 1+ SWAP 1+ SWAP "%e [%d ;%d H" .FORMAT ; \ ISO
On 30/04/2026 7:11 pm, albert@spenarnc.xs4all.nl wrote:
In article <69f2ba42$1@news.ausics.net>, dxf <dxforth@gmail.com> wrote:
On 29/04/2026 11:41 pm, albert@spenarnc.xs4all.nl wrote:Now consider this:
Formerly I had this clunky handling of colors.
...
Now if you have FORMAT this becomes a lot less clunky.
I agree the original was clunky. But whether FORMAT was necessary,
I'm less certain. Naturally, I'm too lazy to show an alternative.
But I can for your last example, as I'm sure can others ...
: default-bw "%e [00m" FORMAT TYPE ;
: default-bw ." \1b[00m" ;
: AT-XY 1+ SWAP 1+ SWAP "%e [%d ;%d H" .FORMAT ; \ ISO
What if the digits field had to be exactly 2 or 3 digits to suit
a specific terminal? You would have to code for it. Worst case
is something like Turbo Pascal which handled almost any terminal.
In DX-Forth for CP/M, here's how that looks:
https://pastebin.com/EvZvaaCw
In article <69f2ba42$1@news.ausics.net>, dxf <dxforth@gmail.com> wrote:
On 29/04/2026 11:41 pm, albert@spenarnc.xs4all.nl wrote:Now consider this:
Formerly I had this clunky handling of colors.
...
Now if you have FORMAT this becomes a lot less clunky.
I agree the original was clunky. But whether FORMAT was necessary,
I'm less certain. Naturally, I'm too lazy to show an alternative.
But I can for your last example, as I'm sure can others ...
: default-bw "%e [00m" FORMAT TYPE ;
: default-bw ." \1b[00m" ;
: AT-XY 1+ SWAP 1+ SWAP "%e [%d ;%d H" .FORMAT ; \ ISO
In article <69f2ba42$1@news.ausics.net>, dxf <dxforth@gmail.com> wrote:
On 29/04/2026 11:41 pm, albert@spenarnc.xs4all.nl wrote:
Formerly I had this clunky handling of colors.
...
Now if you have FORMAT this becomes a lot less clunky.
I agree the original was clunky. But whether FORMAT was necessary,
I'm less certain. Naturally, I'm too lazy to show an alternative.
But I can for your last example, as I'm sure can others ...
: default-bw "%e [00m" FORMAT TYPE ;
: default-bw ." \1b[00m" ;
You don't realize that FORMAT makes escapes in strings
superfluous. It is a loadable alternative that is not
intrusive unlike escapes in strings, that are forever contraversial.
Follow the c-crowd for escapes? Or the FORTRAN crowd?
Add it to the Forth standard? If you do that you irreversibly
complicate the Forth kernel and add another bone of contention
in the mix.
Once you embrace `` $@ $! $+! $C+ $/ $\ '' string packet,
FORMAT is just one screen.
If you don't want it, you don't load it.
In article <69f36016$1@news.ausics.net>, dxf <dxforth@gmail.com> wrote:
On 30/04/2026 7:11 pm, albert@spenarnc.xs4all.nl wrote:
In article <69f2ba42$1@news.ausics.net>, dxf <dxforth@gmail.com> wrote: >>>> On 29/04/2026 11:41 pm, albert@spenarnc.xs4all.nl wrote:
Now consider this:Formerly I had this clunky handling of colors.
...
Now if you have FORMAT this becomes a lot less clunky.
I agree the original was clunky. But whether FORMAT was necessary,
I'm less certain. Naturally, I'm too lazy to show an alternative.
But I can for your last example, as I'm sure can others ...
: default-bw "%e [00m" FORMAT TYPE ;
: default-bw ." \1b[00m" ;
: AT-XY 1+ SWAP 1+ SWAP "%e [%d ;%d H" .FORMAT ; \ ISO
What if the digits field had to be exactly 2 or 3 digits to suit
a specific terminal? You would have to code for it. Worst case
is something like Turbo Pascal which handled almost any terminal.
In DX-Forth for CP/M, here's how that looks:
https://pastebin.com/EvZvaaCw
You have to code, but it is not hard. <# # #> are your friends.
You have to be careful, because there is only one hold area.
: prepare 1+ 0 <# # # # #> ;
: AT-XY SWAP prepare "%e [%s " .FORMAT prepare ";%s H" .FORMAT ; \ ISO
I wonder how you handle that with escapes in a regular string.
Or if you have an ALLOCATE available, you can make strings permanent.
: prepare 1+ 0 <# # # # #> >permanent ;
and it is even easier.
: >permanent DUP CELL+ ALLOCATE THROW >R R@ $! R> @$ ;
From a Gforth include:
: pn ( n -- ) 0 <# # # #> type ;
: ;pn [char] ; emit pn ;
: ESC[ 27 emit [char] [ emit ;
: at-xy 1+ 1 under+ ESC[ pn ;pn [char] H emit ;
dxf <dxforth@gmail.com> writes:
From a Gforth include:
: pn ( n -- ) 0 <# # # #> type ;
: ;pn [char] ; emit pn ;
: ESC[ 27 emit [char] [ emit ;
: at-xy 1+ 1 under+ ESC[ pn ;pn [char] H emit ;
Here's another one (the one active when I invoke Gforth):
: #n ( n -- ) [: 0 #s 2drop ;] #10 base-execute ;
: #n; ( n -- ) #n ';' hold ;
: #esc[ ( -- )
s\" \e[" holds ;
: vt100-at-xy ( u1 u2 -- )
1+ swap 1+ <<# 'H' hold #n; #n #esc[ #0. #> type #>> ;
Benefits:
1) Works also as intended when invoked while BASE is not decimal (BASE-EXECUTE).
2) Does not disturb any ongoing hold buffer usage (<<# ... #>>).
3) Stack effect comments.
Am 30.04.2026 um 11:11 schrieb albert@spenarnc.xs4all.nl:...
While
AT-XY \ ( col row -- ) 10.6.1.0742 set text cursor coordinates
is standard,
XY \ ( -- col row ) get text cursor coordinates
is much more interesting to implement. ;-)
IIRC the standard makes no mention of what needs preserving.
Some
implementations preserve BASE; while others don't.
dxf <dxforth@gmail.com> writes:
IIRC the standard makes no mention of what needs preserving.
It actually states explicitly what is not guaranteed to be preserved.
In particular, <https://forth-standard.org/standard/usage#subsubsection.3.3.3.6>
says:
|The previous contents of the regions identified by [...] #> may be
|invalid after each use of these words. Further, the regions returned
|by [...] #> may overlap in memory. Consequently, use of one of these
|words can corrupt a region returned earlier by a different word. The
|other words that construct pictured numeric output strings (<#, #, #S, |HOLD, HOLDS, XHOLD) may also modify the contents of these
|regions. Words that display numbers may be implemented using pictured |numeric output words. Consequently, . (dot), .R, .S, ?, D., D.R, U.,
|U.R could also corrupt the regions.
Note that AT-XY is not included in this list (and chapter 10 does not
add it to this list). So
123. <# #s #> 3 4 at-xy type
should display "123" at position 3,4. Testing this with a few Forth
systems, gforth, iforth, and SwiftForth pass this test, while lxf and
VFX don't.
Someallowed to change BASE (the specification of DECIMAL could be better, however), and of courseyou can change BASE explicitly, e.g., with
implementations preserve BASE; while others don't.
As far as standard words are concerned, only DECIMAL and HEX are
BASE !
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,116 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 89:17:58 |
| Calls: | 14,306 |
| Calls today: | 1 |
| Files: | 186,338 |
| D/L today: |
1,551 files (531M bytes) |
| Messages: | 2,525,562 |