1. trivial prints()...
- Posted by Lee woo seob <wslee at HHI.CO.KR> Oct 15, 1997
- 637 views
Hi all! the codes below is the one used in my simple text-mode user interface program, instead of puts(1,s). as you will see, the code is small and very trivial one, however, i felt this is a little handy. i hope someone find this useful to him... i will happy if anyone would make this routine better... from Lee woo seob... ---------------------------- codes start here --------------------------- global sequence bt bt={0,7} -- set background and text color procedure prints(integer r, integer c, integer k, object s) -- -- screen print procedure -- -- when s is a string sequence: -- if k=0, string will be written as left-justified -- if k=1, string will be written as right-justified -- if k>1, string will be written as centered text between the spaces -- from column "c" to "k" on the row of "r". -- -- when s is a integer(atom): -- the screen part from column "c" to "k" on the row of r will be erased. -- sequence a integer ls if sequence(s) then ls=length(s) a=repeat(bt[1]*16+bt[2],ls*2) for i=1 to ls do a[i*2-1]=s[i] end for if k=0 then elsif k=1 then c=c-ls+1 else c=c+floor((k-c+1-ls)/2) end if else ls=k-c+1 a=repeat(bt[1]*16+bt[2],ls*2) for i=1 to k-c+1 do a[i*2-1]=32 end for end if poke(#B8000+(r-1)*160+(c-1)*2,a) end procedure -------------------------- codes end here -----------------------
2. Re: trivial prints()...
- Posted by Robert B Pilkington <bpilkington at JUNO.COM> Oct 15, 1997
- 621 views
>the codes below is the one used in my simple text-mode user interface >program, instead of puts(1,s). as you will see, the code is small and >very trivial one, however, i felt this is a little handy. >i hope someone find this useful to him... >i will happy if anyone would make this routine better... > >from Lee woo seob... I have a routine, display(), that works similar except: It doesn't use the <>'s Color codes are done like BBS text door game color codes (eg `5 for magenta, color 5. `! for bright cyan, or 11.) Background colors use a tilid. (~4 for brown) (Sorry, no support for bright background colors, like the Text/GUI does!) use `` or ~~ to display a ` or ~. All % codes are supported, plus a %c for my add_commas() routine. Calls printf() to display the % codes. (And still supports full formatting) just use: display("Here is your change:\n$%7.2c", {34.1}) to display Here is your change: $ 34.10 or if you used 1330 Here is your change: $1,330.00 Here it is: (Just pop them into some .e file, comments appreciated.) global function add_commas(atom number, sequence field) -- Adds commas to numbers to make them more readable sequence revised, space atom float, modify space = "" modify = 1 revised = sprintf("%" & field & "f", {number}) while modify <= length(revised) do if revised[modify] = ' ' then space = space & ' ' revised = revised[modify+1..length(revised)] modify = modify - 1 end if modify = modify + 1 end while float = find('.', revised) if float then for j = (float-4) to 1 by -3 do revised = revised[1..j] & ',' & revised[j+1..length(revised)] if length(space) then space = space[1..length(space)-1] end if end for else if length(revised) > 3 then for j = (length(revised)-3) to 1 by -3 do revised = revised[1..j] & ',' & revised[j+1..length(revised)] if length(space) then space = space[1..length(space)-1] end if end for end if end if return(space & revised) end function global procedure display(sequence text, sequence vars) -- Allows color codes embeded into the text. -- Use ` for foreground (Use SHIFT number for above ten. (`@ = 12 -- (@ is SHIFT 2)) `) = 10. (SHIFT will add 10 to the number...) -- Use ~ for background. (Sorry, only 0-7 work. 8-15 won't work the same, -- but if you know how to use 'high' background colors, you can fix it. -- 8-15 will display the 'low' version. (8 = black (0), 9 = blue (1), etc) integer color_code integer curr_var curr_var = 1 color_code = 0 if length(text) < 1 then return end if for i = 1 to length(text) do if color_code > 0 then color_code = color_code -1 end if if text[i] = '~' and color_code = 0 and i < length(text) then color_code = 2 if text[i+1] >= '0' and text[i+1] <= '7' then bk_color(text[i+1] - 48) elsif text[i+1]='~' then puts(1, '~') end if end if if text[i] = '`' and color_code = 0 and i < length(text) then color_code = 2 if text[i+1] >= '0' and text[i+1] <= '9' then text_color(text[i+1] - 48) elsif text[i+1]=')' then text_color(10) elsif text[i+1]='!' then text_color(11) elsif text[i+1]='@' then text_color(12) elsif text[i+1]='#' then text_color(13) elsif text[i+1]='$' then text_color(14) elsif text[i+1]='%' then text_color(15) elsif text[i+1]='`' then puts(1, '`') end if end if if text[i] = '%' and color_code = 0 and i < length(text) then for j = i+1 to length(text) do if find(text[j], "dxosefgc%") then if text[j] = 'c' then puts(1, add_commas(vars[curr_var], text[i+1..j-1])) else printf(1, text[i..j], {vars[curr_var]}) end if curr_var = curr_var + 1 color_code = j-i+1 exit end if end for end if if color_code = 0 then puts(1, text[i]) end if end for end procedure