3

How do \r in lua ? This my code :

for port = 1, 65535 do
    local sock = socket.tcp()
    local scan = sock:connect("192.168.88.1", port)

    sock:close()

    if scan then
        print("[\27[1m\27[91m+\27[0m] " .. port .. "")
        print("Scanning...\r")

    end
end

and the result:

[+] 21
Scanning...
[+] 22
Scanning...
[+] 23
Scanning...
[+] 53
Scanning...
[+] 80
Scanning...
[+] 2000
Scanning...
[+] 8291
Scanning...
[+] 8728
Scanning...
[+] 8729
Scanning...

and I want that as soon as a port is displayed the scanning... is erased and reappears at the end so just after the port.

I can't find much documentation on lua, sorry

i try all the print(en="\r") but it's not fine.

ESkri
  • 1,461
  • 1
  • 1
  • 8
Saviam
  • 31
  • 3

1 Answers1

3

print automatically appends a newline character (\n), which you don't want. Instead, you should use io.write. This will however not flush, so you'll have to also use io.flush. Here's a simple example using the Unix sleep command to wait 1s between messages:

for i = 1, 10 do
    io.write(("test %02d\r"):format(i))
    io.flush()
    os.execute("sleep 1")
end

This will continously overwrite test XX with the new value of i until i=10 is reached.

Luatic
  • 8,513
  • 2
  • 13
  • 34