ZeroBraneStudio
ZeroBraneStudio copied to clipboard
What is the correct way for deleting characters from STDIN
Consider this code:
io.write("1234567890")
io.write(string.char(8):rep(5))
io.write(string.char(0x20):rep(5))
In C when you write a backspace to STDIN, the characters got deleted
int main()
{
const char a[100] = "1234567890";
printf("%s", a);
printf("%c%c%c%c%c",8,8,8,8,8);
printf("%c%c%c%c%c",0x20,0x20,0x20,0x20,0x20);
return 0;
}
Printing 1234567890<BS><BS><BS><BS><BS>
Instead of 12345
. I've searched for a solution to this but did not find any. Do you have the correct way for deleting from STDIN ?
Looks like Zerobrane/Lua does not want to go back, but prints <BS> instead.
Lua behaves the same as C. However, the result depends on what the destination device for STDOUT is - if it goes to console, it interprets the 0x08 characters as "delete". If you redirect to file, the file will contain all 10 numbers and the 5 <BS> characters.
ZBS behaves like a file in this manner, it doesn't recognize and interpret any special characters. Maybe a plugin can be made for that, although I don't see much point in it.
I was aiming to code a Unix progress bar for example
Complete 45% <================ >
Do you know a better way to do it via ZBE. I need to replace the last line in the console on progress change.