11# ABSTRACT: Input widgets for raw terminal text input
22
3- use Terminal::MakeRaw ;
3+ use Terminal::API ;
44use Terminal::ANSIParser;
55use Terminal::LineEditor::DuospaceInput;
66use Terminal::LineEditor::History;
@@ -311,7 +311,7 @@ role Terminal::LineEditor::RawTerminalIO {
311311 has atomicint $ ! done = 0 ;
312312 has $ ! parse = make-ansi-parser(emit-item => { $ ! raw-supplier . emit ($ _ ) });
313313 has MouseEventMode: D $ ! previous-mouse-mode = MouseNoEvents;
314- has $ ! saved-termios ;
314+ has $ ! saved-term-config ;
315315 has @ ! active-queries ;
316316
317317 # | Atomically set done, even from outside role
@@ -325,10 +325,10 @@ role Terminal::LineEditor::RawTerminalIO {
325325 # termios), then start the parser, save current TTY mode, flush
326326 # previous I/O, and convert TTY to raw mode
327327
328- if $ . input . t && ! $ ! saved-termios {
328+ if $ . input . t && ! $ ! saved-term-config {
329329 my $ fd = $ . input . native-descriptor;
330- $ ! saved-termios = Terminal::MakeRaw::getattr ($ fd );
331- Terminal::MakeRaw::makeraw ($ fd , : FLUSH);
330+ $ ! saved-term-config = Terminal::API::get-config ($ fd );
331+ Terminal::API::make-raw ($ fd , : when(Terminal::API:: FLUSH) );
332332
333333 $ ! done ⚛= 0 ;
334334 self . start-parser;
@@ -341,11 +341,11 @@ role Terminal::LineEditor::RawTerminalIO {
341341 # mark the saved termios as unused, and optionally output a \n to push
342342 # the cursor to the start of the next line
343343
344- if $ ! saved-termios {
344+ if $ ! saved-term-config {
345345 $ ! done ⚛= 1 ;
346346 my $ fd = $ . input . native-descriptor;
347- Terminal::MakeRaw::setattr( $ fd , $ ! saved-termios , : DRAIN);
348- $ ! saved-termios = Nil ;
347+ Terminal::API::restore-config( $ ! saved-term-config , $ fd , : when(Terminal::API:: DRAIN) );
348+ $ ! saved-term-config = Nil ;
349349 $ . output . put (' ' ) if $ nl ;
350350 }
351351 }
@@ -565,20 +565,9 @@ role Terminal::LineEditor::RawTerminalUtils {
565565 # | Detect terminal size, returning a Promise that will be kept with
566566 # | (rows, cols) or Empty if unable
567567 method detect-terminal-size () {
568- # XXXX: This query has been found to have compatibility problems; it
569- # works in xterm and libvte terminals, but not in many others
570- # such as Konsole, Windows Console, linux, etc.
571- # my $response = self.query-terminal("\e[18t", 't');
572- # $response ~~ /^ "\e[8;" (\d+) ';' (\d+) 't' $/ ?? (+$0, +$1) !! Empty
573-
574- # Instead of the above, take advantage of clipping behavior of cursor
575- # movement commands by saving the cursor, requesting a move way outside
576- # the terminal, detecting the cursor position, and restoring the cursor.
577-
578- $ . output . print (" \e 7\e [9999;9999H" );
579- my $ p := self . detect-cursor-pos;
580- $ . output . print (" \e 8" );
581- $ p
568+ my $ fd = $ . output . native-descriptor;
569+ my $ size = Terminal::API::get-window-size($ fd );
570+ Promise . kept(($ size . rows, $ size . cols))
582571 }
583572
584573 # | Suspend using SIGTSTP job control, switching back to normal mode first;
0 commit comments