Anonymous user
Terminal control/Restricted width positional input/No wrapping: Difference between revisions
Terminal control/Restricted width positional input/No wrapping (view source)
Revision as of 16:56, 16 July 2021
, 2 years ago→{{header|Nim}}
m (→{{header|Julia}}: bug in references with entries in a subdirectory) |
|||
Line 184:
println("You entered '$s'")
}</lang>
=={{header|Nim}}==
{{trans|Julia}}
As in the Julia version we translated, the code is identical to the code in [[Terminal_control/Restricted_width_positional_input/No_wrapping]] but with no width argument in the input call. See this version for some general comments about the code.
<lang Nim>import strformat, terminal
proc eraseLineEnd() = stdout.write("\e[K")
proc inputXYUpto(row, col, cmax: int; width = cmax): string =
while result.len < cmax and not ((let c = getch(); c) in ['\xff', '\f', '\r']):
setCursorPos(row, col)
eraseLineEnd()
if c in ['\b', '\x7f'] and result.len > 0:
result.setLen(result.len - 1)
else:
result.add c
stdout.write result[(if result.len > width: result.len - width else: 0)..result.high]
eraseScreen()
setCursorPos(3, 5)
let s = inputXYUpto(3, 5, 8)
echo &"\n\n\nResult: You entered <<{s}>>"</lang>
=={{header|Phix}}==
|