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

Content added Content deleted
(→‎{{header|Perl 6}}: Add a Perl 6 example)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 134: Line 134:
}</lang>
}</lang>


=={{header|Perl 6}}==
=={{header|Phix}}==
<lang Phix>function getInput(integer row, col, width)
position(row,col)
string s = ""
while 1 do
integer ch = wait_key()
if ch='\r' then exit end if
if ch='\b' then
if length(s)>0 then
puts(1,"\b \b")
s = s[1..$-1]
end if
elsif ch>=' ' and ch<='~' then
if length(s)<=width then
puts(1,ch)
s &= ch
end if
end if
end while
return s
end function

clear_screen() -- clear the console
string s = getInput(3, 5, 8)
position(23,1)
printf(1,"You entered '%s'\n",{s})</lang>

=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2018.10}}
{{works with|Rakudo|2018.10}}
Should work with any termios compatible terminal.
Should work with any termios compatible terminal.
Line 203: Line 231:
print "\e[H\e[J{@screen.join: "\n"}\e[$row;{$column}H$str\e[$row;{$column + $pointer}H";
print "\e[H\e[J{@screen.join: "\n"}\e[$row;{$column}H$str\e[$row;{$column + $pointer}H";
}</lang>
}</lang>

=={{header|Phix}}==
<lang Phix>function getInput(integer row, col, width)
position(row,col)
string s = ""
while 1 do
integer ch = wait_key()
if ch='\r' then exit end if
if ch='\b' then
if length(s)>0 then
puts(1,"\b \b")
s = s[1..$-1]
end if
elsif ch>=' ' and ch<='~' then
if length(s)<=width then
puts(1,ch)
s &= ch
end if
end if
end while
return s
end function

clear_screen() -- clear the console
string s = getInput(3, 5, 8)
position(23,1)
printf(1,"You entered '%s'\n",{s})</lang>