Terminal control/Positional read: Difference between revisions

→‎{{header|TXR}}: Get the console window info to treat coordinates as physical, translated to virtual.
(→‎{{header|TXR}}: Get the console window info to treat coordinates as physical, translated to virtual.)
Line 169:
(typedef WCHAR wchar)
(typedef DWORD uint32)
(typedef WORD uint16)
(typedef SHORT short)
 
(typedef COORD (struct COORD
(X SHORT)
(Ystruct SHORT)))COORD
(X SHORT)
(Y SHORT)))
 
(typedef SMALL_RECT
(struct SMALL_RECT
(Left SHORT)
(Top SHORT)
(Right SHORT)
(Bottom SHORT)))
 
(typedef CONSOLE_SCREEN_BUFFER_INFO
(struct CONSOLE_SCREEN_BUFFER_INFO
(dwSize COORD)
(dwCursorPosition COORD)
(wAttributes WORD)
(srWindow SMALL_RECT)
(dwMaximumWindowSize COORD)))
 
;;; Various constants
Line 187 ⟶ 205:
(with-dyn-lib "kernel32.dll"
(deffi GetStdHandle "GetStdHandle" HANDLE (DWORD))
(deffi GetConsoleScreenBufferInfo "GetConsoleScreenBufferInfo"
(deffi ReadConsoleOutputCharacter
"ReadConsoleOutputCharacterW" BOOL (HANDLE (ptr-out CONSOLE_SCREEN_BUFFER_INFO)))
(deffi ReadConsoleOutputCharacter "ReadConsoleOutputCharacterW"
BOOL (HANDLE (ptr-out (array 1 WCHAR))
DWORD
DWORD COORD (ptr-out (array 1 COORDDWORD)))))
(ptr-out (array 1 DWORD)))))
 
;;; Now the character at <2, 5> -- column 3, row 6.
Line 199 ⟶ 216:
(when (equal console-handle INVALID_HANDLE_VALUE)
(error "couldn't get console handle"))
 
(let* ((chars (vector 5))
(let* ((cinfo (new CONSOLE_SCREEN_BUFFER_INFO))
(getinfo-ok (GetConsoleScreenBufferInfo console-handle cinfo))
(coord (if getinfo-ok
^#S(COORD X ,(+ 2 cinfo.srWindow.Left)
Y ,(+ 5 DWORDcinfo.srWindow.Top))
^#S(COORD X 20 Y 50)))
(let* ( (chars (vector 5))
(nread (vector 1))
(successread-pok (ReadConsoleOutputCharacter console-handle chars
1 coord charsnread)))
(unless getinfo-ok
1
(error "GetConsoleScreenBufferInfo failed"))
#S(COORD X 2 Y 5)
(prinl cinfo)
nread)))
(unless successread-pok
(error "ReadConsoleOutputCharacter failed"))
(unless (plusp [nread 0])
543

edits