This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
moTechPlz's profile picture

box drawing characters

Started by moTechPlz, 19 March 2016 - 08:09 PM
moTechPlz #1
Posted 19 March 2016 - 09:09 PM
Found some box drawing characters using unicode escape sequences. There are some parsing problems with the api (why i use native) and the characters don't render aligned. Anyway, i'll just post it here to share it.

Comment if you can get this working on your machine or have ideas how to better code this or just talk about it.

Yes, i'm new here, Hi all o/



-> Code is very hacky and just proof of concept <- used computercraft 1.75 mc 1.7.10

term.native().clear()
term.native().setCursorPos( 2 , 2 )
term.native().blit( "\226\149\146\226\149\144\226\149\144\226\149\144\226\149\144\226\149\144\226\149\149", "0000000", "bbbbbbb" )
term.native().setCursorPos( 2 , 3 )
term.native().blit( "\226\148\130" .. " YES " .. "\226\148\130", "0000000", "bbbbbbb" )
term.native().setCursorPos( 2 , 4 )
term.native().blit( "\226\148\148\226\148\128\226\148\128\226\148\128\226\148\128\226\148\128\226\148\152", "0000000", "bbbbbbb" )

local monitor = peripheral.find("monitor")
  if monitor then
	monitor.clear()
	monitor.setCursorPos( 1 , 1 )
	monitor.blit( "\226\149\146\226\149\144\226\149\144\226\149\144\226\149\144\226\149\144\226\149\149", "0000000", "bbbbbbb" )
	monitor.setCursorPos( 1 , 2 )
	monitor.blit( "\226\148\130" .. " YES " .. "\226\148\130", "0000000", "bbbbbbb" )
	monitor.setCursorPos( 1 , 3 )
	monitor.blit( "\226\148\148\226\148\128\226\148\128\226\148\128\226\148\128\226\148\128\226\148\152", "0000000", "bbbbbbb" )
end

while true do
  event, x = os.pullEvent()
  if event == "key_up" and x == 16 then
   break
  end
end

characters - > http://pastebin.com/ZURrECkL
Bomb Bloke #2
Posted 19 March 2016 - 11:43 PM
Heh, I knew those later 1.7.10 builds could output some extra symbols, but I never considered throwing some multi-byte characters at them… Nice find! :)/>

Alignment could indeed be a bit of an issue with the particular "border" characters you're using in your screenshot there (due to the way pre-MC1.8 builds of CC load fonts). I don't think it's possible to get rid of the gap between rows, and other chars may even be horizontally cropped.

Under MC1.8, CC uses its own custom font file (earlier it just used whatever one Minecraft was using), and you can render any of its 256 symbols simply by specifying which one you want. Eg, for the 240th, you just print("\239") (bearing in mind they're zero-indexed).

So I suppose the "neatest" way to make use of these under MC1.7.10 would be to load all the known working chars into a table, then create a custom blit function that allows the same functionality - eg, parse the incoming string and look for references to the x'th character in the font file, and translating them to the most suitable unicode symbols, if known.

Does that make sense? I could take a stab at coding that up myself, if you'd prefer?
moTechPlz #3
Posted 20 March 2016 - 02:37 PM
Heh, I knew those later 1.7.10 builds could output some extra symbols, but I never considered throwing some multi-byte characters at them… Nice find! :)/>
Thanks

Alignment could indeed be a bit of an issue with the particular "border" characters you're using in your screenshot there (due to the way pre-MC1.8 builds of CC load fonts). I don't think it's possible to get rid of the gap between rows, and other chars may even be horizontally cropped.
Yes, this is probably the biggest problem against making these characters actually useful.

Under MC1.8, CC uses its own custom font file (earlier it just used whatever one Minecraft was using), and you can render any of its 256 symbols simply by specifying which one you want. Eg, for the 240th, you just print("\239") (bearing in mind they're zero-indexed).
Too bad 1.8 'broke' this. After i got around the "Arguments must be the same length" thingy. 1.8 sees it instead as 3 one byte characters. No more escape codes (i think) just one byte page.

So I suppose the "neatest" way to make use of these under MC1.7.10 would be to load all the known working chars into a table, then create a custom blit function that allows the same functionality - eg, parse the incoming string and look for references to the x'th character in the font file, and translating them to the most suitable unicode symbols, if known.
Yes, you're right. But as long is it is not that useful i don't see any reason to put time into polishing it.
moTechPlz #4
Posted 21 March 2016 - 12:03 PM
You may notice i used native() because there is a argument length check inside the window api. It does not recognize multi byte characters. Going through monitor.blit you don't have this problem, probably an oversight. If you want to use these codes outside of term.native() you have to rewrite/remove the check.

if #sTextColor ~= #sText or #sBackgroundColor ~= #sText then
	error( "Arguments must be the same length", 2 )
end
This uses the # to get the charactercount but gets only the bytecount so it does not work for multi byte characters.

You can add a string.len overwrite to the string overwrite section in bios. something like this

local nativestringlen = string.len
.
.
stringCopy.len = function ( s )
	_, count = string.gsub(s, "\226", "\226")
	return nativestringlen( s ) - (count * 2)
end
.
.
and make it pretty!

Anyway, have fun with this.
moTechPlz #5
Posted 21 March 2016 - 09:39 PM
I can confirm 1.76+ fixes the alignment problem.

Edited on 23 March 2016 - 06:55 AM
Creator #6
Posted 21 March 2016 - 09:43 PM
That looks awesome!

Full source code?
Bomb Bloke #7
Posted 21 March 2016 - 09:48 PM
Huh. ComputerCraft for MC 1.8 must be loading both its own font file and also MC's. I'm surprised to learn that, but it opens up quite a few possibilities, as your screenshots show! :)/>
moTechPlz #8
Posted 21 March 2016 - 10:42 PM
I wish. No, escape code is not possible in vanilla 1.76+, it is hardcoded. This just shows that the new FixedWidthFontRenderer in 1.76+ is much better and it solves the alignment problem.

Maybe in future versions something like a CC specific multibyte code can be devised. You only need one non used character on the first page to start. 255 characters is just not enough.

Anyway, i did this by replacing the termFont. And the window shown in the picture is hardcoded not generated. Just to show the use of the characters. But it does look pretty cool huh
Edited on 23 March 2016 - 09:09 AM
moTechPlz #9
Posted 21 March 2016 - 10:57 PM
Creator said:
Full source code?

Hi, well i can't show you the source code because there isn't much to show. I cheated, i replaced the font file and use standard ascii codes. This will not work out of the box,

[EDIT ok, sourcecode below. You need the resource pack i made.]

Creator said:
That looks awesome!
Yes, it does.
Edited on 23 March 2016 - 04:56 PM
moTechPlz #10
Posted 23 March 2016 - 09:55 AM
So i made a resource pack to overwrite the default font texture for CC 1.76+.


Your program can test if this pack is installed with the asciifont variable [EDIT only reflects if the pack is inside the resourcepacks folder not if it is actually enabled. a minecraft thing i guess]

if asciifont then
	print( "ascii font installed" )
end

You can use the special characters with \000 .. \255

print( "\213\205\205\205\205\205\205\205\205\205\184" )
print( "\179" .. " pretty! " .. "\179" )
print( "\192\196\196\196\196\196\196\196\196\196\217" )



>> Just pop this into minecraft resourcepacks folder and enable it in minecraft options/resourcepacks menu.

REMOVED -> get the new version below v
Edited on 30 March 2016 - 01:41 PM
moTechPlz #11
Posted 23 March 2016 - 06:01 PM


The sourcecode for this ^, all hardcoded. Like said very hacky and a just tryout to test alignment.
> you need the resourcepack i posted above below <


local monitor = peripheral.find("monitor")
  if monitor then
		monitor.setTextScale( 0.5 )
		monitor.clear()
		monitor.setCursorPos( 1 , 1 )
		monitor.blit( "\213\205\205\205\205\205\205\205\205\205\205\205\205\205\184", "000000000000000", "bbbbbbbbbbbbbbb" )
		monitor.setCursorPos( 1 , 2 )
		monitor.blit( "\179" .. "box confirmed" .. "\179", "000000000000000", "bbbbbbbbbbbbbbb" )
		monitor.setCursorPos( 1 , 3 )
		monitor.blit( "\179\000\196\095\000\000\000\000\000\000\000\143\131\128\179", "00000000000bb00", "bbbbbbbbbbb000b" )
		monitor.setCursorPos( 1 , 4 )
		monitor.blit( "\179\000\000\000\196\095\000\000\143\131\128\128\128\128\179", "00000000bb00000", "bbbbbbbb000000b" )
		monitor.setCursorPos( 1 , 5 )
		monitor.blit( "\179\196\196\196\196\196\196\196\196\196\196\196\196\196\179", "000000000000000", "bbbbbbbbbbbbbbb" )
		monitor.setCursorPos( 1 , 6 )
		monitor.blit( "\179\128\128\128\128\128\000\000\000\000" .. "46%" .. "\000\179", "044444000000000", "b44444bbbbbbbbb" )
		monitor.setCursorPos( 1 , 7 )
		monitor.blit( "\179\128\128\128\128\128\149\000\000\000" .. "50%" .. "\000\179", "0eeeeeee0000000", "beeeeebbbbbbbbb" )
		monitor.setCursorPos( 1 , 8 )
		monitor.blit( "\195\196\196\196\196\196\196\196\196\196\196\196\196\196\180", "000000000000000", "bbbbbbbbbbbbbbb" )
		monitor.setCursorPos( 1 , 9 )
		monitor.blit( "\179\176\177\178\128" .. "100 %" .. "\128\178\177\176\179", "05555fff5f55550", "bbbb5555555bbbb" )
		monitor.setCursorPos( 1 , 10 )
		monitor.blit( "\212\205\205\205\205\205\205\205\205\205\205\205\205\205\190", "000000000000000", "bbbbbbbbbbbbbbb" )
	end

EDIT - updated using teletext character giving 2 more vertical bar levels.
Edited on 26 March 2016 - 06:57 PM
moTechPlz #12
Posted 25 March 2016 - 08:20 PM


I updated the resource pack with a new homebrew box drawing character font.
  • supports 1.76+ teletext type characters
  • supports 1.76+ lowercase special language characters


>> Just pop this into minecraft resourcepacks folder and enable it in minecraft options/resourcepacks menu.

EDIT fixed an error and added a couple of icons instead of some redundant characters.
EDIT2 fixed another error and added the © character

Attached file for computercraft version 1.76 and 1.78. See post below for computercraft version 1.79(+).
Edited on 01 April 2016 - 03:02 PM
Bomb Bloke #13
Posted 25 March 2016 - 10:48 PM
Be aware that CC 1.79 is going to change the font file format - you can see an example in my other resource pack thread.
moTechPlz #14
Posted 26 March 2016 - 07:52 PM
Thanks for the heads up, i will look into it. l want to test it out first anyway.

Attached file for computercraft 1.79.
Edited on 01 April 2016 - 03:04 PM