FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
termplot/code/termplot/ts/termplot/app/cli/geometry.ts at main · astrohackerlabs/termplot · GitHub
astrohackerlabs
termplot
Repository navigation
Code
Issues
2
(2)
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
termplot
/
code
/
termplot
/
ts
/
termplot
/
app
/
cli
/
geometry.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
103 lines (94 loc) · 3.09 KB
Breadcrumbs
termplot
/
code
/
termplot
/
ts
/
termplot
/
app
/
cli
/
geometry.ts
Copy path
File metadata and controls
103 lines (94 loc) · 3.09 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/** Cell geometry. Overlay SetOverlay uses the inner rect. */
export
interface
PaneGeometry
{
col
:
number
;
row
:
number
;
width
:
number
;
height
:
number
;
}
export
interface
OverlayLayout
{
pane
:
{
width
:
number
;
height
:
number
}
;
/** Inner webview — SetOverlay / CaptureOverlay. */
overlay
:
PaneGeometry
;
/** Outer box including the 1-cell ring, or equal to overlay if unbordered. */
outer
:
PaneGeometry
;
bordered
:
boolean
;
}
/** Landscape default in pixels (~2:1 cell aspect → 100×32 is wider than tall). */
export
const
DEFAULT_MAX_COLS
=
100
;
export
const
DEFAULT_MAX_ROWS
=
32
;
export
function
fullPaneGeometry
(
columns
:
number
,
rows
:
number
)
:
PaneGeometry
{
const
width
=
Math
.
max
(
1
,
Math
.
floor
(
columns
)
||
80
)
;
const
height
=
Math
.
max
(
1
,
Math
.
floor
(
rows
)
||
24
)
;
return
{
col
:
0
,
row
:
0
,
width
,
height
}
;
}
/** Read pane size from process stdout or env overrides (tests). */
export
function
readTerminalGeometry
(
env
:
NodeJS
.
ProcessEnv
=
process
.
env
,
stdout
:
{
columns
?:
number
;
rows
?:
number
}
=
process
.
stdout
,
)
:
PaneGeometry
{
if
(
env
.
TERMPLOT_COLS
&&
env
.
TERMPLOT_ROWS
)
{
return
fullPaneGeometry
(
Number
(
env
.
TERMPLOT_COLS
)
,
Number
(
env
.
TERMPLOT_ROWS
)
,
)
;
}
const
columns
=
stdout
.
columns
??
80
;
const
rows
=
stdout
.
rows
??
24
;
return
fullPaneGeometry
(
columns
,
rows
)
;
}
function
positiveCell
(
n
:
number
,
fallback
:
number
)
:
number
{
const
v
=
Math
.
floor
(
n
)
;
if
(
!
Number
.
isFinite
(
v
)
||
v
<
1
)
return
fallback
;
return
v
;
}
/**
* Center a landscape-capped overlay. Max is a ceiling on the inner
* webview. Border is a 1-cell ring when the pane is at least 3×3.
*/
export
function
overlayLayout
(
paneCols
:
number
,
paneRows
:
number
,
maxCols
:
number
=
DEFAULT_MAX_COLS
,
maxRows
:
number
=
DEFAULT_MAX_ROWS
,
)
:
OverlayLayout
{
const
paneW
=
positiveCell
(
paneCols
,
80
)
;
const
paneH
=
positiveCell
(
paneRows
,
24
)
;
const
maxW
=
positiveCell
(
maxCols
,
DEFAULT_MAX_COLS
)
;
const
maxH
=
positiveCell
(
maxRows
,
DEFAULT_MAX_ROWS
)
;
const
pane
=
{
width
:
paneW
,
height
:
paneH
}
;
let
bordered
=
paneW
>=
3
&&
paneH
>=
3
;
if
(
bordered
)
{
const
innerW
=
Math
.
max
(
1
,
Math
.
min
(
paneW
-
2
,
maxW
)
)
;
const
innerH
=
Math
.
max
(
1
,
Math
.
min
(
paneH
-
2
,
maxH
)
)
;
const
outerW
=
innerW
+
2
;
const
outerH
=
innerH
+
2
;
if
(
outerW
>
paneW
||
outerH
>
paneH
||
innerW
<
1
||
innerH
<
1
)
{
bordered
=
false
;
}
else
{
const
outerCol
=
Math
.
floor
(
(
paneW
-
outerW
)
/
2
)
;
const
outerRow
=
Math
.
floor
(
(
paneH
-
outerH
)
/
2
)
;
return
{
pane
,
overlay
:
{
col
:
outerCol
+
1
,
row
:
outerRow
+
1
,
width
:
innerW
,
height
:
innerH
,
}
,
outer
:
{
col
:
outerCol
,
row
:
outerRow
,
width
:
outerW
,
height
:
outerH
,
}
,
bordered
:
true
,
}
;
}
}
const
w
=
Math
.
max
(
1
,
Math
.
min
(
paneW
,
maxW
)
)
;
const
h
=
Math
.
max
(
1
,
Math
.
min
(
paneH
,
maxH
)
)
;
const
col
=
Math
.
floor
(
(
paneW
-
w
)
/
2
)
;
const
row
=
Math
.
floor
(
(
paneH
-
h
)
/
2
)
;
const
overlay
=
{
col
,
row
,
width
:
w
,
height
:
h
}
;
return
{
pane
,
overlay
,
outer
:
overlay
,
bordered
:
false
}
;
}
Back
|
FazBrowse Home
|
New Git URL