Line data Source code
1 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3 : !!!! !!!!
4 : !!!! ParaMonte: Parallel Monte Carlo and Machine Learning Library. !!!!
5 : !!!! !!!!
6 : !!!! Copyright (C) 2012-present, The Computational Data Science Lab !!!!
7 : !!!! !!!!
8 : !!!! This file is part of the ParaMonte library. !!!!
9 : !!!! !!!!
10 : !!!! LICENSE !!!!
11 : !!!! !!!!
12 : !!!! https://github.com/cdslaborg/paramonte/blob/main/LICENSE.md !!!!
13 : !!!! !!!!
14 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
15 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16 :
17 : !> \brief
18 : !> This module contains implementations of the procedures in [pm_sysShell](@ref pm_sysShell).
19 : !>
20 : !> \finmain
21 : !>
22 : !> \author
23 : !> \AmirShahmoradi
24 :
25 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26 :
27 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 : #if isFailedGetShellShape_ENABLED || isFailedGetShellWidth_ENABLED || isFailedGetShellHeight_ENABLED
29 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 :
31 : use pm_arraySplit, only: setSplit
32 : integer(IK) :: iostat, iline
33 : integer(IK) , allocatable :: sindex(:,:)
34 192807 : character(:, SK), allocatable :: string
35 : character(1, SK) :: dumstr
36 192807 : type(shell_type) :: Shell
37 : #if isFailedGetShellHeight_ENABLED
38 : integer(IK) :: width
39 : #elif isFailedGetShellWidth_ENABLED
40 : integer(IK) :: height
41 : #elif !isFailedGetShellShape_ENABLED
42 : #error "Unrecognized interface."
43 : #endif
44 192807 : shell = shell_type(failed) ! Determine the shell type.
45 : if (failed) return ! LCOV_EXCL_LINE
46 :
47 192807 : if (shell%is%cmd) then
48 :
49 : ! First try calling PowerShell.
50 :
51 0 : failed = isFailedGetOutput(SK_"powershell ^(Get-Host^).UI.RawUI.WindowSize.ToString()", string) ! `width`,`height`
52 0 : if (.not. failed) then
53 0 : read(string, *, iostat = iostat) width, height
54 0 : failed = logical(iostat /= 0_IK, LK)
55 : end if
56 :
57 : ! If failed, try a pure CMD approach.
58 :
59 0 : if (failed) then
60 0 : width = -1_IK
61 0 : height = -1_IK
62 0 : failed = isFailedGetOutput(SK_"mode con /status", string)
63 : ! string contains a table like the following:
64 : ! Lines: 30
65 : ! Columns: 120
66 : ! Keyboard rate: 31
67 : ! Keyboard delay: 0
68 : ! Code page: 437
69 0 : if (.not. failed) then
70 0 : call setSplit(sindex, string, new_line(SK_"a"))
71 0 : do iline = 1, size(sindex, 2, IK)
72 0 : if (index(string(sindex(1,iline) : sindex(2,iline)), SK_"Lines", kind = IK) > 0_IK) then
73 0 : read(string, *, iostat = iostat) dumstr, height
74 0 : failed = logical(iostat /= 0_IK, LK)
75 0 : if (failed) return
76 : end if
77 0 : if (index(string(sindex(1,iline) : sindex(2,iline)), SK_"Columns", kind = IK) > 0_IK) then
78 0 : read(string, *, iostat = iostat) dumstr, width
79 0 : failed = logical(iostat /= 0_IK, LK)
80 0 : if (failed) return
81 : end if
82 0 : if (height /= -1_IK .and. width /= -1_IK) exit
83 : end do
84 0 : failed = logical(height == -1_IK .or. width == -1_IK, LK)
85 : end if
86 : end if
87 :
88 192807 : elseif (shell%is%powershell) then
89 :
90 0 : failed = isFailedGetOutput("(Get-Host).UI.RawUI.WindowSize.ToString()", string) ! `width`,`height`
91 0 : if (.not. failed) then
92 0 : read(string, *, iostat = iostat) width, height
93 0 : failed = logical(iostat /= 0_IK, LK)
94 : end if
95 :
96 : else
97 :
98 : #if isFailedGetShellShape_ENABLED || isFailedGetShellWidth_ENABLED
99 96404 : failed = isFailedGetEnvVar(SK_"COLUMNS", string, length = 3_IK)
100 96404 : if (.not. failed) then
101 96404 : read(string, *, iostat = iostat) width
102 96404 : failed = logical(iostat /= 0_IK, LK)
103 : end if
104 : #elif isFailedGetShellShape_ENABLED || isFailedGetShellHeight_ENABLED
105 96403 : failed = isFailedGetEnvVar(SK_"LINES", string, length = 3_IK)
106 96403 : if (.not. failed) then
107 96403 : read(string, *, iostat = iostat) height
108 96403 : failed = logical(iostat /= 0_IK, LK)
109 : end if
110 : #endif
111 : ! One last attempt through the `tput` command.
112 :
113 192807 : if (failed) then
114 192807 : failed = isFailedGetOutput(SK_"echo $(tput cols),$(tput lines)", string) ! `width`,`height`
115 192807 : if (.not. failed) then
116 192807 : read(string, *, iostat = iostat) width, height
117 192807 : failed = logical(iostat /= 0_IK, LK)
118 : end if
119 : end if
120 :
121 : end if
122 :
123 : #else
124 : !%%%%%%%%%%%%%%%%%%%%%%%%
125 : #error "Unrecognized interface."
126 : !%%%%%%%%%%%%%%%%%%%%%%%%
127 : #endif
|