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

Content added Content deleted
(Terminal control/Restricted width positional input/No wrapping in FreeBASIC)
m (syntax highlighting fixup automation)
Line 17: Line 17:
==={{header|ncurses}}===
==={{header|ncurses}}===
To interface ncurses from Lisp, the ''[https://www.cliki.net/croatoan croatoan]'' library is used.
To interface ncurses from Lisp, the ''[https://www.cliki.net/croatoan croatoan]'' library is used.
<lang lisp>;; Load the library from the quicklisp repository
<syntaxhighlight lang="lisp">;; Load the library from the quicklisp repository
(ql:quickload "croatoan")
(ql:quickload "croatoan")
(in-package :croatoan)
(in-package :croatoan)
Line 34: Line 34:


;; call the routine
;; call the routine
(field-input-no-wrapping 2 4 8)</lang>
(field-input-no-wrapping 2 4 8)</syntaxhighlight>




=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>Function getInput(fila As Integer, columna As Integer, ancho As Integer) As String
<syntaxhighlight lang="freebasic">Function getInput(fila As Integer, columna As Integer, ancho As Integer) As String
Locate fila, columna, 0
Locate fila, columna, 0
Dim As String KBD, cadena = ""
Dim As String KBD, cadena = ""
Line 57: Line 57:
Dim As String s = getInput(3, 5, 8)
Dim As String s = getInput(3, 5, 8)
Locate 23,1 : Print "You entered: "; s
Locate 23,1 : Print "You entered: "; s
Sleep</lang>
Sleep</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
Line 64: Line 64:
<br>
<br>
This uses _getch() rather than _getwch() as only ASCII is supported.
This uses _getch() rather than _getwch() as only ASCII is supported.
<lang go>package main
<syntaxhighlight lang="go">package main


/*
/*
Line 127: Line 127:
setCursor(coord)
setCursor(coord)
fmt.Printf("You entered '%s'\n", s)
fmt.Printf("You entered '%s'\n", s)
}</lang>
}</syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
Requires an ANSI compatible terminal and a system C library implementing _getch() for unbuffered keyboard input. Note the code below is identical to the code in [[Terminal_control/Restricted_width_positional_input/No_wrapping]] but with no width argument in the input call.
Requires an ANSI compatible terminal and a system C library implementing _getch() for unbuffered keyboard input. Note the code below is identical to the code in [[Terminal_control/Restricted_width_positional_input/No_wrapping]] but with no width argument in the input call.
<lang julia>getch() = UInt8(ccall(:_getch, Cint, ()))
<syntaxhighlight lang="julia">getch() = UInt8(ccall(:_getch, Cint, ()))
cls() = print("\33[2J")
cls() = print("\33[2J")
reposition(row, col) = print("\u001b[$row;$(col)H")
reposition(row, col) = print("\u001b[$row;$(col)H")
Line 155: Line 155:
s = input_y_x_upto(3, 5, 8)
s = input_y_x_upto(3, 5, 8)
println("\n\n\nResult: You entered <<$s>>")
println("\n\n\nResult: You entered <<$s>>")
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
Line 164: Line 164:


It would also be possible to allow for printable Unicode characters (>= 160) to be entered by adding an extra clause to the 'when' statement. However, for this to work properly, you will need to be using a suitable code page (65001, say) and a suitable font (Lucida Console, say).
It would also be possible to allow for printable Unicode characters (>= 160) to be entered by adding an extra clause to the 'when' statement. However, for this to work properly, you will need to be using a suitable code page (65001, say) and a suitable font (Lucida Console, say).
<lang scala>// Kotlin Native v0.5
<syntaxhighlight lang="scala">// Kotlin Native v0.5


import kotlinx.cinterop.*
import kotlinx.cinterop.*
Line 205: Line 205:
}
}
println("You entered '$s'")
println("You entered '$s'")
}</lang>
}</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
Line 211: Line 211:
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.
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
<syntaxhighlight lang="nim">import strformat, terminal


proc eraseLineEnd() = stdout.write("\e[K")
proc eraseLineEnd() = stdout.write("\e[K")
Line 228: Line 228:
setCursorPos(3, 5)
setCursorPos(3, 5)
let s = inputXYUpto(3, 5, 8)
let s = inputXYUpto(3, 5, 8)
echo &"\n\n\nResult: You entered <<{s}>>"</lang>
echo &"\n\n\nResult: You entered <<{s}>>"</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(notonline)-->
<!--<syntaxhighlight lang="phix">(notonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (position, wait_key, backspace)</span>
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (position, wait_key, backspace)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">getInput</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">row</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">col</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">width</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">getInput</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">row</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">col</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">width</span><span style="color: #0000FF;">)</span>
Line 258: Line 258:
<span style="color: #7060A8;">position</span><span style="color: #0000FF;">(</span><span style="color: #000000;">23</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">position</span><span style="color: #0000FF;">(</span><span style="color: #000000;">23</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"You entered '%s'\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">s</span><span style="color: #0000FF;">})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"You entered '%s'\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">s</span><span style="color: #0000FF;">})</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|Raku}}==
=={{header|Raku}}==
Line 267: Line 267:
All printable character keys work, as does backspace and enter. Ctrl-c to exit. All other keys / key-combos are ignored.
All printable character keys work, as does backspace and enter. Ctrl-c to exit. All other keys / key-combos are ignored.


<lang perl6>use Term::termios;
<syntaxhighlight lang="raku" line>use Term::termios;


constant $saved = Term::termios.new(fd => 1).getattr;
constant $saved = Term::termios.new(fd => 1).getattr;
Line 329: Line 329:
@screen = "\e[41m{' ' x $cols}\e[0m" xx $rows;
@screen = "\e[41m{' ' x $cols}\e[0m" xx $rows;
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>
}</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
(This REXX program only works with: &nbsp; REXX/Personal)
(This REXX program only works with: &nbsp; REXX/Personal)
<lang rexx>/*REXX pgm reads text from the terminal screen from a certain row, column, and length.*/
<syntaxhighlight lang="rexx">/*REXX pgm reads text from the terminal screen from a certain row, column, and length.*/
parse arg row col len . /*obtain optional arguments from the CL*/
parse arg row col len . /*obtain optional arguments from the CL*/
if row=='' | row=="," then row= 3 /*Not specified? Then use the default.*/
if row=='' | row=="," then row= 3 /*Not specified? Then use the default.*/
Line 349: Line 349:
say 'data read from terminal row ' row " col " col ' length ' len " is:"
say 'data read from terminal row ' row " col " col ' length ' len " is:"
say $
say $
exit 0 /*stick a fork in it, we're all done. */</lang>
exit 0 /*stick a fork in it, we're all done. */</syntaxhighlight>


=={{header|Wren}}==
=={{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.
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
<syntaxhighlight lang="ecmascript">import "io" for Stdin, Stdout


var textAtPos = Fn.new { |text, r, c|
var textAtPos = Fn.new { |text, r, c|
Line 396: Line 396:


var res = input.call(3, 5, 8)
var res = input.call(3, 5, 8)
System.print(res)</lang>
System.print(res)</syntaxhighlight>


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>proc GetData(Col, Row, Width, Str);
<syntaxhighlight lang="xpl0">proc GetData(Col, Row, Width, Str);
int Col, Row, Width; char Str;
int Col, Row, Width; char Str;
int I, C;
int I, C;
Line 430: Line 430:
You entered: ");
You entered: ");
Text(0, Str);
Text(0, Str);
]</lang>
]</syntaxhighlight>


=={{header|Yabasic}}==
=={{header|Yabasic}}==
<lang Yabasic>// Rosetta Code problem: http://rosettacode.org/wiki/Restricted_width_positional_input/No_wrapping
<syntaxhighlight lang="yabasic">// Rosetta Code problem: http://rosettacode.org/wiki/Restricted_width_positional_input/No_wrapping
// by Galileo, 04/2022
// by Galileo, 04/2022


Line 461: Line 461:
text$ = getInput$(3, 5, 8)
text$ = getInput$(3, 5, 8)
print at(1, 23) "You entered: ", text$</lang>
print at(1, 23) "You entered: ", text$</syntaxhighlight>