Terminal control/Restricted width positional input/No wrapping: Difference between revisions
Terminal control/Restricted width positional input/No wrapping (view source)
Revision as of 20:05, 14 March 2020
, 4 years agoRename Perl 6 -> Raku, alphabetize, minor clean-up
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Add a Perl 6 example) |
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
||
Line 134:
}</lang>
=={{header|
<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>▼
(formerly Perl 6)
{{works with|Rakudo|2018.10}}
Should work with any termios compatible terminal.
Line 203 ⟶ 231:
print "\e[H\e[J{@screen.join: "\n"}\e[$row;{$column}H$str\e[$row;{$column + $pointer}H";
}</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>
|