BarText = "\0337"; // Save the current cursor position.
BarText = "\033
BarText = "\0337"; // Save the current cursor position.
BarText = "\033[0;0r"; // Remove the bar region.
BarText = "\033[0;0H"; // Move the cursor to the top of the screen.[/code]Should have been:
[code]
BarText = "\0337"; // Save the current cursor position.
BarText += "\033[0;0r"; // Remove the bar region.
BarText += "\033[0;0H"; // Move the cursor to the top of the screen.[/code]I broke it up to make it easier to follow, and messed it up by forgetting to change "+" to "+=" - Scandum spotted it when debugging it with tt++ (thanks!). However following his post I've changed it to the following:
[code]
BarText = "\0337"; // Save the current cursor position.
BarText += "\033[1;1H"; // Move the cursor to the top of the screen.[/code]And I've removed the following from the end as well:
[code]
BarText += "\033[2;0r"; // Fix the bar region.[/code]
I'll fiddle with it a bit more, get it to only update if it's actually changed (like I do with MSDP), but as I said before I don't want to invest too much time into it - I've too many projects already :P
So this is what I came up with:
One problem I found was that after drawing the bar and restoring the cursor position, the cursor was at the beginning of the line, meaning you'd type over your prompt (as if you'd displayed a "\r"). To get around this, when you're using the energy bar the mud always adds a newline after your prompt if there isn't one already. Not ideal, but it works.
When using my cygwin telnet client, the bar stops updating while typing something. When using TinTin++ it continues to update, but every time it does the prompt returns to the front of the line, so you're typing over your own input. Is there a solution for this other than using character mode?
I've also noticed that sometimes the bar vanishes when text scrolls up the screen, although it reappears a moment later - not a big deal, but not very nice either.
I also tried drawing the bar at the bottom of the window, using NAWS to find the window height - but I had trouble getting the cursor to move up afterwards (you'd start typing over the bar). I know other muds have done this so I'm sure it can be done, but I didn't want to spend more than an hour or two playing with it. It was really just to test the idea out, out of personal curiosity.
Experimental code here, if anyone wants it: