1. EUPHORIA MarkUp - A Little Group Project

I've wanted to do this for a long time, and I finally got around to
starting the code. I wanted to create a modified puts command that would
let me embed color changes, location changes, etc., without having to exit
the puts and resort to more lines of commands. Know what I mean?

Instead of

puts(1,"blah blah blah ")
text_color(BLACK)
puts(1,"blah blah.\n")
bg_color(ORANGE)
puts(1,"etc. etc.")

How about just

markup("<C1,1>blah blah blah <T0> blah blah. <C2,1><T17> etc. etc.")

Anyway, here's the alpha-version of EMU.E (EMU stands for EUPHORIA MarkUp
[Language]). If you've got an idea for this let me know. If you want to do
some coding for it, have at it!

Please, send all code fragments/improvements/suggestions to me via e-mail
if possible, so I can combine everything and make a final file.

I think there should be a checker to make sure the Coordinate command
doesnt' send text off the screen. If anybody has a better format for
embedding the codes, let me know.

Thanks guys!
ck lester

--emu.e
--Euphoria Mark-Up Language for MS-DOS computers

include get.e
include graphics.e

global sequence MarkupCodes
global object temp

MarkupCodes = "TBC"

--<T#> for text color
--<B#> for background color
--<Cx,y> for text coordinate
--<Xx,y,width,height> for a text box graphic
--<Px,y,picture sequence OR picture file> for a graphic of format .???
--<Your Suggestion Here>

function get_code(sequence text, atom count)
atom counter, char
object code
    code = {}
    counter = 0
    char = text[count + counter]
    while char != ',' and char != '>' do
        code = code & text[count + counter]
        counter = counter + 1
        char = text[count + counter]
    end while
    code = value(code)
    code = code[2]
    return {code, counter + 1}
end function

global procedure markup(sequence text)
object xc, yc
atom curr_char, prev_char, next_char, count, max, code

    count = 1
    max = length(text)
    while count < max do
        curr_char = text[count]
        if count - 1 > 1 then
            prev_char = text[count-1]
        else
            prev_char = -1
        end if
        if length(text) > count then
            next_char = text[count+1]
        else
            next_char = -1
        end if

        if curr_char = '<' then
            count = count + 1
            code = find(next_char, MarkupCodes)
            if code != 0 then
                if next_char = 'T' then
                    count = count + 1
                    temp = get_code(text, count)
                    text_color(temp[1])
                    count = count + temp[2]
                end if
                if next_char = 'B' then
                    count = count + 1
                    temp = get_code(text, count)
                    bk_color(temp[1])
                    count = count + temp[2]
                end if
                if next_char = 'C' then
                    count = count + 1
                    --get x coordinate
                    temp = get_code(text, count)
                    xc = temp[1]
                    count = count + temp[2]
                    --get y coordinate
                    temp = get_code(text, count)
                    yc = temp[1]
                    count = count + temp[2]
                    position(xc, yc)
                end if
--Your 'if' Code Here!
            end if
        else
            puts(1,text[count])
            count = count + 1
        end if
    temp = get_key()   --this is here in case I screw up and
    if temp = 'q' then --find myself in an endless loop
        abort(0)
    end if
    end while
end procedure

markup("<C5,1><T12>I <T9>am starting at 5,1.<C1,1><T5><B7>Now I am at 1,1!")
markup("<C22,35><T8><B0>Now I'm way over here!")
markup("<C10,3><T2>Press any key to continue.<T7><B0>")

temp = wait_key()
clear_screen()

new topic     » topic index » view message » categorize

2. Re: EUPHORIA MarkUp - A Little Group Project

>I've wanted to do this for a long time, and I finally got around to
>starting the code. I wanted to create a modified puts command that
>would let me embed color changes, location changes, etc., without having
to
>exit the puts and resort to more lines of commands. Know what I mean?
>
>Instead of
>
>puts(1,"blah blah blah ")
>text_color(BLACK)
>puts(1,"blah blah.\n")
>bg_color(ORANGE)
>puts(1,"etc. etc.")
>
>How about just
>
>markup("<C1,1>blah blah blah <T0> blah blah. <C2,1><T17> etc. etc.")

Interesting. I did one in Qbasic that was designed to be like printf +
BBS door game color codes. (Plus some others)
I converted it to Euphoria
Anyway, the format is:
display("Stuff, stuff, stuff`4 color 4 (red) `` display a '``'...\n")
display("`7More stuff, stuff, stuff ~4 background red.......\n")
display("And some other C stuff... \r, \b.....")
It doesn't have positioning, but it is OK, IMO.
Another option is to use ANSI codes. (Like my ANSI routine). I can easily
modify my ANSI routine for this use. It would be something like:
show_ansi("Text" & 27 & "[31m Now you have red")
Although it doesn't support the \n's or %d's. (You can & a
sequence/string, though)
Yet another option is something I havn't tried yet (because I don't know
the codes) : HTML. The <>'s reminded me of HTML and it could be
done.......
Then again, your idea is good too, just putting in my two cents. (And now
I'm broke ;)

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

Search



Quick Links

User menu

Not signed in.

Misc Menu