btco / qx82

Tiny Javascript engine for retro games
MIT License
421 stars 19 forks source link

Add maxWidth and respect maxLen in readLine #10

Closed HoofedEar closed 3 months ago

HoofedEar commented 3 months ago

Related to #8

Allows for setting a maximum width of characters for readLine. Which means if the user types beyond the maxWidth, it will move the cursor to the next line. It is currently set to default of 28 so that it aligns well with the "example-hello.html" example, but of course can be set to other values. For example, here is it set to 5 (readLine("", -1, 5);) image

When you press "Enter", it will return the entire line as a single string with no newlines, so it will preserve the nature of readLine.

Also, made sure that it respects the value set for maxLen so that works now too 👍

Feel free to adjust or change anything in my code!

btco commented 3 months ago

Very nice! I think it will be a great addition to QX82.

Just one tiny thing: I like to keep 100% backwards compatibility when possible, so in this case I'd prefer if it defaulted to an infinite max width (in other words, no wrapping) if the user omits the maxLength parameter. Maybe you can make it so it defaults to -1, and have -1 mean "no wrapping" in the code?

Thanks!

HoofedEar commented 3 months ago

Maybe you can make it so it defaults to -1, and have -1 mean "no wrapping" in the code?

Done! Good call on backwards compatibility, 28 as default would have been jarring lol

Also fixed a bug in my code related to checking maxLen, so it should be good to go now! :+1:

btco commented 3 months ago

Great, perfect!