Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #31083 > unrolled thread

COLORS

Started byJason Damisch <jasondamisch@yahoo.com>
First post2014-05-31 10:45 -0700
Last post2014-06-02 00:30 -0400
Articles 11 — 8 participants

Back to article view | Back to comp.lang.forth


Contents

  COLORS Jason Damisch <jasondamisch@yahoo.com> - 2014-05-31 10:45 -0700
    Re: COLORS humptydumpty <ouatubi@gmail.com> - 2014-05-31 11:26 -0700
    Re: COLORS Paul Rubin <no.email@nospam.invalid> - 2014-05-31 11:47 -0700
      Re: COLORS Julian Fondren <julian.fondren@gmail.com> - 2014-06-01 03:07 -0700
    Re: COLORS Mark Wills <markwills1970@gmail.com> - 2014-05-31 13:52 -0700
      Re: COLORS Jason Damisch <jasondamisch@yahoo.com> - 2014-05-31 13:56 -0700
        Re: COLORS albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-06-01 09:41 +0000
      Re: COLORS "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-31 18:00 -0400
        Re: COLORS "Elizabeth D. Rather" <erather@forth.com> - 2014-05-31 17:14 -1000
        Re: COLORS Julian Fondren <julian.fondren@gmail.com> - 2014-06-01 02:57 -0700
          Re: COLORS "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-02 00:30 -0400

#31083 — COLORS

FromJason Damisch <jasondamisch@yahoo.com>
Date2014-05-31 10:45 -0700
SubjectCOLORS
Message-ID<7b87e201-c207-4c3a-8034-0b96190345db@googlegroups.com>
\ This in SwiftForth

: COLOR
\ (  attribute  --  )
   CREATE , 
   DOES> @ ATTRIBUTE
   ;

: COLORS  
   16 0  DO  
       I COLOR
   LOOP
   ;

COLORS  NORMAL  INVERSE  RED  BLUE  LIGHT-BLUE  PINK  YELLOW  LIGHT-GREEN  DARK-RED  DARK-GREEN  DARK-YELLOW  DARK-BLUE  PURPLE  TURQUOISE  LIGHT-GREY GREY

\ Jason

[toc] | [next] | [standalone]


#31087

Fromhumptydumpty <ouatubi@gmail.com>
Date2014-05-31 11:26 -0700
Message-ID<e31d0c5c-2e5d-4baa-8661-edccf2f02e74@googlegroups.com>
In reply to#31083
On Saturday, May 31, 2014 8:45:43 PM UTC+3, Jason Damisch wrote:
> \ This in SwiftForth
> 
> 
> 
> : COLOR
> 
> \ (  attribute  --  )
> 
>    CREATE , 
> 
>    DOES> @ ATTRIBUTE
> 
>    ;
> 
> 
> 
> : COLORS  
> 
>    16 0  DO  
> 
>        I COLOR
> 
>    LOOP
> 
>    ;
> 
> 
> 
> COLORS  NORMAL  INVERSE  RED  BLUE  LIGHT-BLUE  PINK  YELLOW  LIGHT-GREEN  DARK-RED  DARK-GREEN  DARK-YELLOW  DARK-BLUE  PURPLE  TURQUOISE  LIGHT-GREY GREY
> 
> 
> 
> \ Jason

Hi!

With '::' ';;' words inspired from Wil Baden 'Thisforth':

0 :: COLOR  | 1+ |  NORMAL  INVERSE  RED  BLUE  LIGHT-BLUE  PINK  YELLOW  LIGHT-GREEN  DARK-RED  DARK-GREEN  DARK-YELLOW  DARK-BLUE  PURPLE  TURQUOISE  LIGHT-GREY GREY ;; DROP

Have a nice day,
humptydumpty

[toc] | [prev] | [next] | [standalone]


#31088

FromPaul Rubin <no.email@nospam.invalid>
Date2014-05-31 11:47 -0700
Message-ID<7xtx85lr8k.fsf@ruckus.brouhaha.com>
In reply to#31083
Jason Damisch <jasondamisch@yahoo.com> writes:
> \ This in SwiftForth
>
> : COLOR
> \ (  attribute  --  )
>    CREATE , 
>    DOES> @ ATTRIBUTE
>    ;

Wow, that is cute, I didn't realize you could do that.  Gforth doesn't
recognize the word ATTRIBUTE so I chopped it out so it just defines the
argument name as a constant.

[toc] | [prev] | [next] | [standalone]


#31125

FromJulian Fondren <julian.fondren@gmail.com>
Date2014-06-01 03:07 -0700
Message-ID<59487101-6d70-46f6-b785-f938bc582ad7@googlegroups.com>
In reply to#31088
On Saturday, May 31, 2014 1:47:55 PM UTC-5, Paul Rubin wrote:
> Jason Damisch <jasondamisch@yahoo.com> writes:
> > \ This in SwiftForth
> >
> > : COLOR
> > \ (  attribute  --  )
> >    CREATE , 
> >    DOES> @ ATTRIBUTE
> >    ;
> 
> Wow, that is cute, I didn't realize you could do that.

What is it that you didn't realize you could do?


-- Julian

[toc] | [prev] | [next] | [standalone]


#31091

FromMark Wills <markwills1970@gmail.com>
Date2014-05-31 13:52 -0700
Message-ID<b8bd00b6-df6f-4868-95c8-db4c43e44f4d@googlegroups.com>
In reply to#31083
On Saturday, 31 May 2014 18:45:43 UTC+1, Jason Damisch  wrote:
> COLORS  NORMAL  INVERSE  RED  BLUE  LIGHT-BLUE  PINK  YELLOW
> LIGHT-GREEN  DARK-RED  DARK-GREEN  DARK-YELLOW  DARK-BLUE  
> PURPLE  TURQUOISE  LIGHT-GREY GREY
> 

Yeah, that's really cute! What does ATTRIBUTE do?

[toc] | [prev] | [next] | [standalone]


#31092

FromJason Damisch <jasondamisch@yahoo.com>
Date2014-05-31 13:56 -0700
Message-ID<13dcbbe8-881f-4d48-b3c7-b9eead91fc22@googlegroups.com>
In reply to#31091
On Saturday, May 31, 2014 1:52:42 PM UTC-7, Mark Wills wrote:

> Yeah, that's really cute! What does ATTRIBUTE do?

You would need to know by seeing it used in context.  In SwiftForth, it is defined in the file PERSONALITY.F like this

  CODE EMIT      ( char -- )       DO-VECTOR CALL END-CODE   DUP ,     1+
  CODE TYPE      ( addr len -- )   DO-VECTOR CALL END-CODE   DUP ,     1+
  CODE ?TYPE     ( addr len -- )   DO-VECTOR CALL END-CODE   DUP ,     1+
  CODE CR        ( -- )            DO-VECTOR CALL END-CODE   DUP ,     1+
  CODE PAGE      ( -- )            DO-VECTOR CALL END-CODE   DUP ,     1+
  CODE ATTRIBUTE ( n -- )          DO-VECTOR CALL END-CODE   DUP ,     1+

which does not offer an immediate clue.

What it does is to take a number and then change the color of the text.  The color corresponds to the number code.

Jason

[toc] | [prev] | [next] | [standalone]


#31121

Fromalbert@spenarnc.xs4all.nl (Albert van der Horst)
Date2014-06-01 09:41 +0000
Message-ID<538af54e$0$4954$e4fe514c@dreader35.news.xs4all.nl>
In reply to#31092
In article <13dcbbe8-881f-4d48-b3c7-b9eead91fc22@googlegroups.com>,
Jason Damisch  <jasondamisch@yahoo.com> wrote:
>On Saturday, May 31, 2014 1:52:42 PM UTC-7, Mark Wills wrote:
>
>> Yeah, that's really cute! What does ATTRIBUTE do?
>
>You would need to know by seeing it used in context.  In
>SwiftForth, it is defined in the file PERSONALITY.F like this
>
>  CODE EMIT      ( char -- )       DO-VECTOR CALL END-CODE   DUP ,     1+
>  CODE TYPE      ( addr len -- )   DO-VECTOR CALL END-CODE   DUP ,     1+
>  CODE ?TYPE     ( addr len -- )   DO-VECTOR CALL END-CODE   DUP ,     1+
>  CODE CR        ( -- )            DO-VECTOR CALL END-CODE   DUP ,     1+
>  CODE PAGE      ( -- )            DO-VECTOR CALL END-CODE   DUP ,     1+
>  CODE ATTRIBUTE ( n -- )          DO-VECTOR CALL END-CODE   DUP ,     1+
>
>which does not offer an immediate clue.
>
>What it does is to take a number and then change the color of the
>text.  The color corresponds to the number code.

Changing colors and page position is a matter of sending escape sequences.
That can be terribly complicated if you're going to ask the OS what terminal
is used.

Just assuming an ISO / ASCII terminal the esc sequences are fixed.
This works in a context where the ministring package ($@ $! $, ) is
available (or just steal it from ciforth).
(It is part of the code colorization of my analyzer.)

The 10 characters at escape-color do the trick. At two places you can
fill in the background and fore-ground colors. Then your do
    escape-color 10 TYPE

That is all there is to it.
I throw in a bunch of other codes, you don't (but might) need, e.g.
for cursor movement.

------------

( Copyright Albert van der Horst, HCC FIG Holland by GNU Public License)
( $Id: esc.frt,v 1.7 2008-12-02 21:32:41 albert Exp $)

\ Fix up the analyser with information about what are duplicators.

WANT $-PREFIX

$1B CONSTANT ESC

: esc-seq   CREATE $, DROP DOES> ESC EMIT $@ TYPE ;

"[?25l" esc-seq INVIS  \ Make cursor invisible
"[?25h" esc-seq CVVIS  \ Make cursor visible
"[H"    esc-seq HOME   \ Set cursor home
"[2J"   esc-seq CLEAR  \ Clear Page
"[4h"   esc-seq enter_insert_mode
"[4l"   esc-seq exit_insert_mode
"[L"    esc-seq insert_line
"[M"    esc-seq delete_line
"[1A"   esc-seq scroll-up
"[1B"   esc-seq scroll-down
"[P"    esc-seq delete_character
"[C"    esc-seq cursor_right
"[D"    esc-seq cursor_left
"[A"    esc-seq cursor_up
"[B"    esc-seq cursor_down

\ ISO ``PAGE'' command
: PAGE   HOME CLEAR ;
: scroll-down  ^J EMIT ;

\ Print N but no space and decimal.
: .no BASE @ >R DECIMAL 0  <# #S #> TYPE R> BASE ! ;

\ ISO ``AT-XY'' command.
: AT-XY   ESC EMIT   &[ EMIT   1+ .no   &; EMIT   1+ .no   &H EMIT ;

: change_scroll_region   ESC EMIT   &[ EMIT   1+ .no   &; EMIT   1+ .no   &r EMIT ;

CREATE escape-color
ESC C, &[ C, HERE _ C, _ C, &; C, HERE _ C, _ C, &; C, &1 C, &m C,
CONSTANT escape-fore   CONSTANT escape-back

: send-color-escape escape-color 10 TYPE ;

: fore escape-fore SWAP CMOVE ;
: back escape-back SWAP CMOVE ;

: fore-color CREATE $, DROP DOES> $@ fore send-color-escape ;

: back-color CREATE $, DROP DOES> $@ back send-color-escape ;

: color-escape CREATE $, DROP DOES> ESC EMIT &[ EMIT $@ TYPE ;

\ Put the screen in a mode such as to print the chars in the color.
"37"    fore-color    white
"37;1m" color-ESCAPE  white2
"36"    fore-color    aqua
"32"    fore-color    green
"33"    fore-color    yellow
"31"    fore-color    red
"35"    fore-color    pink
"34"    fore-color    fblue
"30"    fore-color    f30

\ Put the screen in a mode such as the background color.
"40"    back-color    black
"41"    back-color    b41
"42"    back-color    b42
"43"    back-color    b43
"44"    back-color    blue
"45"    back-color    b45
"46"    back-color    b46
"47"    back-color    b47
"48"    back-color    b48
"49"    back-color    bwhite

white ( on) black

----------------------

--
>
>Jason
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [prev] | [next] | [standalone]


#31097

From"Rod Pemberton" <dont_use_email@xnothavet.cqm>
Date2014-05-31 18:00 -0400
Message-ID<op.xgqvfeo46zenlw@localhost>
In reply to#31091
On Sat, 31 May 2014 16:52:42 -0400, Mark Wills <markwills1970@gmail.com>  
wrote:
> On Saturday, 31 May 2014 18:45:43 UTC+1, Jason Damisch  wrote:

>> COLORS  NORMAL  INVERSE  RED  BLUE  LIGHT-BLUE  PINK  YELLOW
>> LIGHT-GREEN  DARK-RED  DARK-GREEN  DARK-YELLOW  DARK-BLUE
>> PURPLE  TURQUOISE  LIGHT-GREY GREY
>>
>
> Yeah, that's really cute! What does ATTRIBUTE do?

It probably sets the console foreground text color, or perhaps
the text background color instead, but most likely the foreground.

Obviously, I'm not sure where those are defined in a Forth
environment, or if they are normally, i.e., therefore the
need for the Forth word COLORS.

FYI, I can tell you where the C functions are located in case
you need to consult them or use them:

For DOS C, some C compilers have pre-defined arrays for
the foreground and/or background colors.  If they're defined,
they're DOS functions, i.e., #include <conio.h>.  Consult
your compiler's documentation for more info on the functions.

For Linux C, there is no pre-defined array of colors for foreground
or background text.  The colors are set via pdcurses functions, i.e.,
#include <curses.h> and 'gcc -lcurses'.  Type 'man ncurses" in a
console for the man page.  Linux is a bit more complicated than DOS.
For DOS, you can set the foreground or background text color
independently of the other.  With curses, you must set both at once.
That's fine for text, if the program was designed that way.  It's
not so good for colored text images or ASCII art.


Rod Pemberton

[toc] | [prev] | [next] | [standalone]


#31104

From"Elizabeth D. Rather" <erather@forth.com>
Date2014-05-31 17:14 -1000
Message-ID<mJidnWERkojnBxfOnZ2dnUVZ_u2dnZ2d@supernews.com>
In reply to#31097
On 5/31/14 12:00 PM, Rod Pemberton wrote:
> On Sat, 31 May 2014 16:52:42 -0400, Mark Wills <markwills1970@gmail.com>
> wrote:
>> On Saturday, 31 May 2014 18:45:43 UTC+1, Jason Damisch  wrote:
>
>>> COLORS  NORMAL  INVERSE  RED  BLUE  LIGHT-BLUE  PINK  YELLOW
>>> LIGHT-GREEN  DARK-RED  DARK-GREEN  DARK-YELLOW  DARK-BLUE
>>> PURPLE  TURQUOISE  LIGHT-GREY GREY
>>>
>>
>> Yeah, that's really cute! What does ATTRIBUTE do?
>
> It probably sets the console foreground text color, or perhaps
> the text background color instead, but most likely the foreground.
>
> Obviously, I'm not sure where those are defined in a Forth
> environment, or if they are normally, i.e., therefore the
> need for the Forth word COLORS.
>
> FYI, I can tell you where the C functions are located in case
> you need to consult them or use them:
>
> For DOS C, some C compilers have pre-defined arrays for
> the foreground and/or background colors.  If they're defined,
> they're DOS functions, i.e., #include <conio.h>.  Consult
> your compiler's documentation for more info on the functions.
>
> For Linux C, there is no pre-defined array of colors for foreground
> or background text.  The colors are set via pdcurses functions, i.e.,
> #include <curses.h> and 'gcc -lcurses'.  Type 'man ncurses" in a
> console for the man page.  Linux is a bit more complicated than DOS.
> For DOS, you can set the foreground or background text color
> independently of the other.  With curses, you must set both at once.
> That's fine for text, if the program was designed that way.  It's
> not so good for colored text images or ASCII art.

This is a Windows thing. The PERSONALITY.F file describes the command 
window user interface. including (in this case) font attributes. The 
Linux and OSX versions are less complicated, I assume. Different tasks 
may have different values for all these things. You may set up your 
command window (or an application window) any way you wish, using things 
like this, described in the SwiftForth manual.

The value associated with each COLOR is sent to Windows by ATTRIBUTE. 
It's a good example of an application-specific data type with a value 
and an action.

Cheers,
Elizabeth

-- 
==================================================
Elizabeth D. Rather   (US & Canada)   800-55-FORTH
FORTH Inc.                         +1 310.999.6784
5959 West Century Blvd. Suite 700
Los Angeles, CA 90045
http://www.forth.com

"Forth-based products and Services for real-time
applications since 1973."
==================================================

[toc] | [prev] | [next] | [standalone]


#31124

FromJulian Fondren <julian.fondren@gmail.com>
Date2014-06-01 02:57 -0700
Message-ID<a2e81b5f-4a8b-48ec-912f-9097fae160a6@googlegroups.com>
In reply to#31097
On Saturday, May 31, 2014 5:00:40 PM UTC-5, Rod Pemberton wrote:
> Obviously, I'm not sure where those are defined in a Forth
> environment, or if they are normally, i.e., therefore the
> need for the Forth word COLORS.
> 
> FYI, I can tell you where the C functions are located in case
> you need to consult them or use them:

> For Linux C,

Yeah, forget that.  This is COLORS in a unix environment:

  [defined] ESC[ 0= [if]
    : ESC[ 27 emit [char] [ emit ;
  [then]
  
  : color ( n "name" -- )
    create , does>  ESC[ @ 0 .r ." m" ;
  
  : colors 8 0 do i 30 + color loop ;
  : bgcolors 8 0 do i 40 + color loop ;
  
  colors black red green yellow blue magenta cyan white
  bgcolors bg-black bg-red bg-green bg-yellow bg-blue bg-magenta bg-cyan bg-white
  0 color null
  1 color bold

Usage:

  bold red bg-yellow .( hello) null

'man console_codes' under linux (the manpage is linux-specific; the codes are
not) for more.

ncurses adds drawing efficiency for slow network connections and for slow
terminals.  For most purposes (like, adding a bit of color to some output) it
is not just overkill but actively undesireable.

Under gforth on Android, BLACK RED GREEN are already defined (by ansi.fs) and
are used by fg! and bg! .  >BLACK and >WHITE return the terminal to 'normal',
respectively white-on-black or black-on-white:

  red fg! yellow bg! .( hello) >black

Still,

  : color ( n "name" -- )
    create , does>  @ set-fg! ;
  : colors 8 0 do i color loop ;

  colors black red green yellow blue magenta cyan white


-- Julian

[toc] | [prev] | [next] | [standalone]


#31145

From"Rod Pemberton" <dont_use_email@xnothavet.cqm>
Date2014-06-02 00:30 -0400
Message-ID<op.xgs75tte6zenlw@localhost>
In reply to#31124
On Sun, 01 Jun 2014 05:57:56 -0400, Julian Fondren  
<julian.fondren@gmail.com> wrote:
> On Saturday, May 31, 2014 5:00:40 PM UTC-5, Rod Pemberton wrote:

>> Obviously, I'm not sure where those are defined in a Forth
>> environment, or if they are normally, i.e., therefore the
>> need for the Forth word COLORS.
>>
>> FYI, I can tell you where the C functions are located in case
>> you need to consult them or use them:
>
>> For Linux C,
>
> Yeah, forget that.  This is COLORS in a unix environment:
>
>   [defined] ESC[ 0= [if]
>     : ESC[ 27 emit [char] [ emit ;
>   [then]

Yes, ANSI color codes can work in some instances too.


Rod Pemberton

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web