1. extended print routine

Here is a small thing that I found inspiration for today. It is a sort of
printf, except with the possibility to change position of text and change
colors in the same call. It does also support basic text-squares (that is
squares 'drawn' with the background color). I've called the procedure
eprint ( = extended print) since I couldn't find a better name. My
programming is quite simple with no smart tricks, so the procedure is not
any faster than what separate statement lines would be, and I'm sure there
are better ways to do this. But it works.

I've used a HTML - kind of look. The routine should be called like this:

eprint(text sequence, variable sequence)

The variable sequence should be built in the same way as you do with printf
and sprintf. The text sequence can contain exactly the same as that of
printf, EXCEPT for the input of variables. Variable input must be marked
off by <> like this:

<%3d>

Apart from the <> it is similar.

The new formatting this procedure supports are these:

<bXX> sets background color XX
<tXX> sets text color XX
<pYY,XX> positions the cursor at YY,XX
<sY1,X1-Y2,X2> draws a box with the current background color, with Y1,X1 as
top left corner and Y2,X2 as bottom right corner.

Please note: there is yet no support for things like <bXX tXX>, only one
command will be executed within each <>. I will add it later, probably.

This is what I support yet. I will give a complete example here:

eprint("<p1,35><b1><t12>Hello <%s>!<b2><s2,1-15,80>",{"John Doe"})

Give me feedback! Suggestions! Improvements! Reasons for why mo
code/program suck! I'll be happy for anything.

PS: The feedback on my HAYES demo's been a bit low. I thank those who
wrote, but I would like to get even more mails!

Einar Mogen
Slimesoft
e-mail: nord.staernes at rollag.mail.telia.com
homesite: http://www.geocities.com/TimesSquare/Battlefield/2314

-- File starts here
include graphics.e
include get.e

constant YES = 1, NO = 0
sequence variables
integer current_variable

procedure do_command(sequence command_text)
    object junk
    integer comma
    if not length(command_text) then
        return
    elsif command_text[1] = 'b' then -- background color
        junk = value(command_text[2..length(command_text)])
        bk_color(junk[2])
    elsif command_text[1] = 't' then -- text color
        junk = value(command_text[2..length(command_text)])
        text_color(junk[2])
    elsif command_text[1] = 'p' then -- position
        comma = find(',', command_text)
        junk = value(command_text[2..comma - 1])
        junk[1] = junk[2]
        junk[2]=value(command_text[comma+1..length(command_text)])
        junk[2] = junk[2][2]
        position(junk[1], junk[2])
    elsif command_text[1] = '%' then
        printf(1,command_text,{variables[current_variable]})
        current_variable = current_variable + 1
    elsif command_text[1] = 's' then
        comma = find(',', command_text)
        junk = value(command_text[2..comma - 1])
        junk[1] = junk[2]
        junk[2] = value(command_text[comma + 1..find('-', command_text) - 1])
        junk[2] = junk[2][2]
        command_text =
 command_text[find('-',command_text)..length(command_text)]
        comma = find(',', command_text)
        junk = junk & value(command_text[2..comma - 1])
        junk[3] = junk[4]
        junk[4] = value(command_text[comma + 1..length(command_text)])
        junk[4] = junk[4][2]
        for y_pos = junk[1] to junk[3] do
            position(y_pos, junk[2])
            puts(1,repeat(' ', junk[4] - junk[2] + 1))
        end for
    end if
end procedure

global procedure eprint(sequence text, sequence var)
    integer put_text
    sequence command_sequence
    variables = var
    put_text = YES
    current_variable = 1
    for counter = 1 to length(text) do
        if text[counter] = '<' then
            put_text = NO
            command_sequence = {}
        elsif text[counter] = '>' then
            put_text = YES
            do_command(command_sequence)
        elsif put_text then
            puts(1,text[counter])
        else
            command_sequence = command_sequence&text[counter]
        end if
    end for
end procedure

new topic     » topic index » view message » categorize

2. Re: extended print routine

>Here is a small thing that I found inspiration for today. It is a sort
>of
>printf, except with the possibility to change position of text and
>change
>colors in the same call. It does also support basic text-squares (that
>is
>squares 'drawn' with the background color). I've called the procedure
>eprint ( = extended print) since I couldn't find a better name. My
>programming is quite simple with no smart tricks, so the procedure is
>not
>any faster than what separate statement lines would be, and I'm sure
>there
>are better ways to do this. But it works.
>
>I've used a HTML - kind of look. The routine should be called like
>this:
>
>eprint(text sequence, variable sequence)
>

Ooops.. I had the wrong message selected when I hit reply..... (The
display() routine was meant as a reply for this.. to show what I had
done.. :)
I'm saying this because I made a mention to the <>'s that eprint() uses..
(As for the poke()... I look at the code for prints() while not
thinking....
Oh well..... Ok, it's all cleared up now.. right?
(My routine can make the % formatting easier, IMO.)

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu