Terminal control/Restricted width positional input/No wrapping: Difference between revisions

Added Wren
m (→‎{{header|REXX}}: changed wording in the REXX section header.)
(Added Wren)
Line 325:
say $
exit 0 /*stick a fork in it, we're all done. */</lang>
 
<br><br>
=={{header|Wren}}==
Due to a bug the ''Stdin.readByte()'' method can currently process only the first byte of a multi-byte character. The others are skipped.
<lang ecmascript>import "io" for Stdin, Stdout
 
var cls = Fn.new {
System.write("\e[2J")
Stdout.flush()
}
 
var textAtPos = Fn.new { |text, r, c|
System.write("\e[%(r);%(c)H%(text)")
Stdout.flush()
}
 
var input = Fn.new { |r, c, maxWidth|
System.write("\e[2J")
textAtPos.call("", r, c)
Stdin.isRaw = true
var w = 0
var res = List.filled(maxWidth, "")
while (true) {
var byte = Stdin.readByte()
if (byte >= 32 && byte < 127) { // All printable ASCII characters
var char = String.fromByte(byte)
textAtPos.call(char, r, c+w)
if (w < maxWidth-1) {
res[w] = char
w = w + 1
} else {
System.write("\b")
Stdout.flush()
res[w] = char
}
} else if (byte == 127 && w > 0) { // Backspace/delete (127 used rather than 8)
System.write("\b \b")
Stdout.flush()
w = w - 1
res[w] = ""
} else if (byte == 13 || byte == 10) { // Carriage return or line feed
System.print()
break
} else if (byte == 3 || byte == 4) { // Ctrl-C or Ctrl-D
Fiber.abort("\nScript aborted")
}
}
Stdin.isRaw = false
return res.join().trimEnd(" ")
}
 
var res = input.call(3, 5, 8)
System.print(res)</lang>
9,476

edits