Terminal control/Restricted width positional input/No wrapping: Difference between revisions
Content added Content deleted
m (→{{header|Julia}}: bug in references with entries in a subdirectory) |
|||
Line 184: | Line 184: | ||
println("You entered '$s'") |
println("You entered '$s'") |
||
}</lang> |
}</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}}== |
=={{header|Phix}}== |