Debian Codegraph @

ext/windows/windows.scm

raw
1 ;;;
2 ;;; os.windows - Windows-specific procedures
3 ;;;
4 ;;; Copyright (c) 2010-2024 Shiro Kawai <[email protected]>
5 ;;;
6 ;;; Redistribution and use in source and binary forms, with or without
7 ;;; modification, are permitted provided that the following conditions
8 ;;; are met:
9 ;;;
10 ;;; 1. Redistributions of source code must retain the above copyright
11 ;;; notice, this list of conditions and the following disclaimer.
12 ;;;
13 ;;; 2. Redistributions in binary form must reproduce the above copyright
14 ;;; notice, this list of conditions and the following disclaimer in the
15 ;;; documentation and/or other materials provided with the distribution.
16 ;;;
17 ;;; 3. Neither the name of the authors nor the names of its contributors
18 ;;; may be used to endorse or promote products derived from this
19 ;;; software without specific prior written permission.
20 ;;;
21 ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 ;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 ;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 ;;;
33
34 (cond-expand [gauche.os.windows
35
36 (define-module os.windows
37 (export
38 ;; Fileapi
39 sys-get-disk-free-space-ex
40
41 ;; MessageBox
42 MB_ABORTRETRYIGNORE MB_CANCELTRYCONTINUE MB_HELP MB_OK MB_OKCANCEL
43 MB_RETRYCANCEL MB_YESNO MB_YESNOCANCEL
44 MB_ICONEXCLAMATION MB_ICONWARNING MB_ICONINFORMATION MB_ICONASTERISK
45 MB_ICONQUESTION MB_ICONSTOP MB_ICONERROR MB_ICONHAND
46 MB_DEFBUTTON1 MB_DEFBUTTON2 MB_DEFBUTTON3 MB_DEFBUTTON4
47 MB_APPLMODAL MB_SYSTEMMODAL MB_TASKMODAL
48 MB_DEFAULT_DESKTOP_ONLY MB_RIGHT MB_RTLREADING MB_SETFOREGROUND
49 MB_TOPMOST MB_SERVICE_NOTIFICATION
50 IDABORT IDCANCEL IDCONTINUE IDIGNORE IDNO IDOK IDRETRY IDTRYAGAIN IDYES
51 sys-message-box
52
53 ;; Console-related (see the comment in console.stub)
54 sys-alloc-console sys-free-console
55 CTRL_C_EVENT CTRL_BREAK_EVENT sys-generate-console-ctrl-event
56 GENERIC_READ GENERIC_WRITE FILE_SHARE_READ FILE_SHARE_WRITE
57 sys-create-console-screen-buffer
58 sys-set-console-active-screen-buffer
59 sys-scroll-console-screen-buffer
60 sys-get-console-cp sys-get-console-output-cp
61 sys-set-console-cp sys-set-console-output-cp
62 sys-get-console-cursor-info
63 sys-set-console-cursor-info
64 sys-set-console-cursor-position
65 ENABLE_LINE_INPUT ENABLE_ECHO_INPUT ENABLE_PROCESSED_INPUT
66 ENABLE_WINDOW_INPUT ENABLE_MOUSE_INPUT ENABLE_PROCESSED_OUTPUT
67 ENABLE_WRAP_AT_EOL_OUTPUT
68 sys-get-console-mode sys-set-console-mode
69 <win:console-screen-buffer-info>
70 FOREGROUND_BLUE
71 FOREGROUND_GREEN
72 FOREGROUND_RED
73 FOREGROUND_INTENSITY
74 BACKGROUND_BLUE
75 BACKGROUND_GREEN
76 BACKGROUND_RED
77 BACKGROUND_INTENSITY
78 sys-get-console-screen-buffer-info
79 sys-get-largest-console-window-size
80 sys-set-screen-buffer-size
81 <win:input-record>
82 sys-get-number-of-console-input-events
83 sys-get-number-of-console-mouse-buttons
84 sys-peek-console-input
85 sys-read-console-input
86 sys-read-console
87 sys-read-console-output
88 sys-read-console-output-attribute
89 sys-read-console-output-character
90 sys-set-console-text-attribute
91 sys-set-console-window-info
92 sys-write-console
93 sys-write-console-output-character
94 sys-fill-console-output-character
95 sys-fill-console-output-attribute
96 sys-flush-console-input-buffer
97 sys-get-console-title
98 sys-set-console-title
99 STD_INPUT_HANDLE STD_OUTPUT_HANDLE STD_ERROR_HANDLE
100 sys-get-std-handle sys-set-std-handle
101
102 ;; windows console related
103 sys-has-windows-console?
104 sys-windows-terminal?
105 sys-windows-console-legacy?
106 ))
107 (select-module os.windows)
108
109 (dynamic-load "os--windows")
110
111 ;; check if we have a windows console
112 ;;
113 ;; NB: this procedure returns #f on MSYS (mintty).
114 ;; see %sys-mintty? in src/libsys.scm for details.
115 ;;
116 (define (sys-has-windows-console?)
117 (boolean (or (sys-isatty (standard-input-port))
118 (sys-isatty (standard-output-port))
119 (sys-isatty (standard-error-port)))))
120
121 ;; check if running on windows terminal (windows 10)
122 (define (sys-windows-terminal?)
123 (boolean (and (not (sys-getenv "GAUCHE_WINDOWS_TERMINAL_OFF"))
124 (sys-getenv "WT_SESSION"))))
125
126 ;; check if windows console is in legacy mode (windows 10)
127 (define (sys-windows-console-legacy?)
128 (let* ([hout (sys-get-std-handle STD_OUTPUT_HANDLE)]
129 [mode (sys-get-console-mode hout)]
130 [ret (guard (e [(<system-error> e) #t])
131 (sys-set-console-mode hout #x0005) ; try VT mode
132 #f)])
133 (sys-set-console-mode hout mode) ; restore mode
134 ret))
135
136 ] ; gauche.os.windows
137 [else
138 (errorf "os.windows module is not available on this platform: ~a"
139 (gauche-architecture))
140 ])