Skip to content
This repository was archived by the owner on Aug 28, 2023. It is now read-only.

Commit e24c78e

Browse files
committed
add initial project
1 parent a2a54ca commit e24c78e

File tree

10 files changed

+256
-0
lines changed

10 files changed

+256
-0
lines changed

.bsb.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12375

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules/
2+
/lib/bs/

.merlin

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
####{BSB GENERATED: NO EDIT
2+
FLG -ppx /home/schube/Repos/autoit-advanced-descriptor/node_modules/bs-platform/lib/bsppx.exe
3+
S /home/schube/Repos/autoit-advanced-descriptor/node_modules/bs-platform/lib/ocaml
4+
B /home/schube/Repos/autoit-advanced-descriptor/node_modules/bs-platform/lib/ocaml
5+
FLG -nostdlib
6+
FLG -w -30-40+6+7+27+32..39+44+45+101
7+
S src
8+
B lib/bs/src
9+
####BSB GENERATED: NO EDIT}

.ocamlformat

Whitespace-only changes.

bsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "autoit-advanced-descriptor",
3+
"sources": ["src"]
4+
}

lib/js/src/index.js

Lines changed: 104 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "autoit-advanced-descriptor",
3+
"version": "1.0.0",
4+
"description": "Generate AutoIT advanced window descriptions according to https://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm",
5+
"main": "index.js",
6+
"repository": "git+https://github.com/schubev/autoit-advanced-descriptor",
7+
"scripts": {
8+
"bsb:make": "bsb -make-world",
9+
"bsb:clean": "bsb -clean-world",
10+
"bsb:watch": "bsb -w"
11+
},
12+
"author": "Victor Schubert <[email protected]>",
13+
"license": "MIT",
14+
"devDependencies": {
15+
"bs-platform": "^6.2.1"
16+
}
17+
}

src/index.ml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
type windowDescription =
2+
{ title: string Js.Nullable.t
3+
; className: string Js.Nullable.t
4+
; regexpTitle: string Js.Nullable.t
5+
; regexpClassName: string Js.Nullable.t
6+
; last: bool Js.Nullable.t
7+
; active: bool Js.Nullable.t
8+
; x: int Js.Nullable.t
9+
; y: int Js.Nullable.t
10+
; w: int Js.Nullable.t
11+
; h: int Js.Nullable.t
12+
; instance: int Js.Nullable.t }
13+
[@@bs.deriving abstract]
14+
15+
type windowDescriptor =
16+
| Title of string
17+
| ClassName of string
18+
| RegexpTitle of string
19+
| RegexpClassName of string
20+
| Last of bool
21+
| Active of bool
22+
| X of int
23+
| Y of int
24+
| W of int
25+
| H of int
26+
| Instance of int
27+
28+
let escaped s = s |. Js.String2.replaceByRe [%re "/;/g"] ";;"
29+
30+
let stringOfWindowDescriptor = function
31+
| Title title ->
32+
Some ("TITLE:" ^ escaped title)
33+
| ClassName className ->
34+
Some ("CLASS:" ^ escaped className)
35+
| RegexpTitle regexpTitle ->
36+
Some ("REGEXPTITLE:" ^ escaped regexpTitle)
37+
| RegexpClassName regexpClassName ->
38+
Some ("REGEXPCLASS:" ^ escaped regexpClassName)
39+
| Last last ->
40+
if last then Some "LAST" else None
41+
| Active active ->
42+
if active then Some "ACTIVE" else None
43+
| X x ->
44+
Some ("X:" ^ string_of_int x)
45+
| Y y ->
46+
Some ("Y:" ^ string_of_int y)
47+
| W w ->
48+
Some ("W:" ^ string_of_int w)
49+
| H h ->
50+
Some ("H:" ^ string_of_int h)
51+
| Instance instance ->
52+
Some ("INSTANCE:" ^ string_of_int instance)
53+
54+
let optionMap f = function Some x -> Some (f x) | None -> None
55+
56+
let filterSome xs =
57+
xs |. Js.Array2.filter Js.Option.isSome |. Js.Array2.map Js.Option.getExn
58+
59+
let splitDescription windowDescription =
60+
[| windowDescription |. titleGet |. Js.Nullable.toOption
61+
|> optionMap (fun title -> Title title)
62+
; windowDescription |. classNameGet |. Js.Nullable.toOption
63+
|> optionMap (fun className -> ClassName className)
64+
; windowDescription |. regexpTitleGet |. Js.Nullable.toOption
65+
|> optionMap (fun regexpTitle -> RegexpTitle regexpTitle)
66+
; windowDescription |. regexpClassNameGet |. Js.Nullable.toOption
67+
|> optionMap (fun regexpClassName -> RegexpClassName regexpClassName)
68+
; windowDescription |. lastGet |. Js.Nullable.toOption
69+
|> optionMap (fun last -> Last last)
70+
; windowDescription |. activeGet |. Js.Nullable.toOption
71+
|> optionMap (fun active -> Active active)
72+
; windowDescription |. xGet |. Js.Nullable.toOption
73+
|> optionMap (fun x -> X x)
74+
; windowDescription |. yGet |. Js.Nullable.toOption
75+
|> optionMap (fun y -> Y y)
76+
; windowDescription |. wGet |. Js.Nullable.toOption
77+
|> optionMap (fun w -> W w)
78+
; windowDescription |. hGet |. Js.Nullable.toOption
79+
|> optionMap (fun h -> H h)
80+
; windowDescription |. instanceGet |. Js.Nullable.toOption
81+
|> optionMap (fun instance -> Instance instance) |]
82+
|. filterSome
83+
84+
let descriptor windowDescription =
85+
let descriptors = splitDescription windowDescription in
86+
"["
87+
^ ( descriptors
88+
|. Js.Array2.map stringOfWindowDescriptor
89+
|. filterSome |. Js.Array2.joinWith "; " )
90+
^ "]"

src/index.mli

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type windowDescription =
2+
{ title: string Js.Nullable.t
3+
; className: string Js.Nullable.t
4+
; regexpTitle: string Js.Nullable.t
5+
; regexpClassName: string Js.Nullable.t
6+
; last: bool Js.Nullable.t
7+
; active: bool Js.Nullable.t
8+
; x: int Js.Nullable.t
9+
; y: int Js.Nullable.t
10+
; w: int Js.Nullable.t
11+
; h: int Js.Nullable.t
12+
; instance: int Js.Nullable.t }
13+
[@@bs.deriving abstract]
14+
15+
val descriptor : windowDescription -> string

0 commit comments

Comments
 (0)