about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/bindings/notcurses.nim66
-rw-r--r--src/bindings/quickjs.nim5
-rw-r--r--src/io/request.nim17
-rw-r--r--src/js/javascript.nim9
4 files changed, 7 insertions, 90 deletions
diff --git a/src/bindings/notcurses.nim b/src/bindings/notcurses.nim
deleted file mode 100644
index 8e1cd718..00000000
--- a/src/bindings/notcurses.nim
+++ /dev/null
@@ -1,66 +0,0 @@
-const notcurseslib = (func(): string =
-  when defined(windows): return "libnotcurses-core.dll"
-  elif defined(macos): return "libnotcurses-core(|.3|.3.0.8).dylib"
-  else: return "libnotcurses-core.so(|.3|.3.0.8)" # assume posix
-)()
-
-{.push cdecl, dynlib: notcurseslib.}
-
-const
-  NCOPTION_INHIBIT_SETLOCALE* = 0x0001u64
-  NCOPTION_NO_CLEAR_BITMAPS* = 0x0002u64
-  NCOPTION_NO_WINCH_SIGHANDLER* = 0x0004u64
-  NCOPTION_NO_QUIT_SIGHANDLERS* = 0x0008u64
-  NCOPTION_PRESERVE_CURSOR* = 0x0010u64
-  NCOPTION_SUPPRESS_BANNERS* = 0x0020u64
-  NCOPTION_NO_ALTERNATE_SCREEN* = 0x0040u64
-  NCOPTION_NO_FONT_CHANGES* = 0x0080u64
-  NCOPTION_DRAIN_INPUT* = 0x0100u64
-  NCOPTION_SCROLLING* = 0x0200u64
-
-const
-  NCDIRECT_OPTION_INHIBIT_SETLOCALE* = 0x0001u64
-  NCDIRECT_OPTION_INHIBIT_CBREAK* = 0x0002u64
-  NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS* = 0x0008u64
-  NCDIRECT_OPTION_VERBOSE* = 0x0010u64
-  NCDIRECT_OPTION_VERY_VERBOSE* = 0x0020u64
-
-const NCOPTION_CLI_MODE = NCOPTION_NO_ALTERNATE_SCREEN or
-  NCOPTION_NO_CLEAR_BITMAPS or
-  NCOPTION_PRESERVE_CURSOR or
-  NCOPTION_SCROLLING
-
-type
-  ncloglevel_e* {.size: sizeof(cint).} = enum
-    NCLOGLEVEL_SILENT  # print nothing once fullscreen service begins
-    NCLOGLEVEL_PANIC   # default. print diagnostics before we crash/exit
-    NCLOGLEVEL_FATAL   # we're hanging around, but we've had a horrible fault
-    NCLOGLEVEL_ERROR   # we can't keep doing this, but we can do other things
-    NCLOGLEVEL_WARNING # you probably don't want what's happening to happen
-    NCLOGLEVEL_INFO    # "standard information"
-    NCLOGLEVEL_VERBOSE # "detailed information"
-    NCLOGLEVEL_DEBUG   # this is honestly a bit much
-    NCLOGLEVEL_TRACE   # there's probably a better way to do what you want
-
-  notcurses_options_struct* = object
-    termtype*: cstring
-    loglevel*: ncloglevel_e
-    margin_t*: cuint
-    margin_r*: cuint
-    margin_b*: cuint
-    margin_l*: cuint
-    flags*: uint64
-
-  notcurses_options* = ptr notcurses_options_struct
-
-  notcurses* = pointer
-
-  ncdirect* = pointer
-
-{.push importc.}
-
-proc ncdirect_core_init*(termtype: cstring, fp: File, flags: uint64): ncdirect
-proc ncdirect_stop*(nc: ncdirect): cint
-
-{.pop.}
-{.pop.}
diff --git a/src/bindings/quickjs.nim b/src/bindings/quickjs.nim
index 97aefcc7..306a3b3d 100644
--- a/src/bindings/quickjs.nim
+++ b/src/bindings/quickjs.nim
@@ -327,8 +327,9 @@ proc JS_NewPromiseCapability*(ctx: JSContext, resolving_funcs: ptr JSValue): JSV
 proc JS_SetOpaque*(obj: JSValue, opaque: pointer)
 proc JS_GetOpaque*(obj: JSValue, class_id: JSClassID): pointer
 proc JS_GetOpaque2*(ctx: JSContext, obj: JSValue, class_id: JSClassID): pointer
-proc JS_ParseJSON*(ctx: JSContext, buf: ptr char, buf_len: csize_t, filename: cstring): JSValue
-proc JS_ParseJSON2*(ctx: JSContext, buf: ptr char, buf_len: csize_t, filename: cstring, flags: cint): JSValue
+proc JS_ParseJSON*(ctx: JSContext, buf: cstring, buf_len: csize_t, filename: cstring): JSValue
+proc JS_ParseJSON2*(ctx: JSContext, buf: cstring, buf_len: csize_t,
+  filename: cstring, flags: cint): JSValue
 
 proc JS_NewClassID*(pclass_id: ptr JSClassID): JSClassID
 proc JS_NewClass*(rt: JSRuntime, class_id: JSClassID, class_def: ptr JSClassDef): cint
diff --git a/src/io/request.nim b/src/io/request.nim
index 4a123a0b..da3437fb 100644
--- a/src/io/request.nim
+++ b/src/io/request.nim
@@ -310,25 +310,16 @@ proc close*(response: Response) {.jsfunc.} =
   if response.body != nil:
     response.body.close()
 
+#TODO text, json should return promises, not blocking reads
 proc text*(response: Response): string {.jsfunc.} =
   if response.body == nil:
     return ""
   result = response.body.readAll()
   response.close()
 
-#TODO: get rid of this
-proc readAll*(response: Response): string {.jsfunc.} =
-  return response.text()
-
-proc Response_json(ctx: JSContext, this: JSValue, argc: cint, argv: ptr JSValue): JSValue {.cdecl.} =
-  let op = getOpaque0(this)
-  if unlikely(not ctx.isInstanceOf(this, "Response") or op == nil):
-    return JS_ThrowTypeError(ctx, "Value is not an instance of %s", "Response")
-  let response = cast[Response](op)
+proc json(response: Response, ctx: JSContext): JSValue =
   var s = response.text()
-  if s == "":
-    return JS_ThrowSyntaxError("unexpected end of input")
-  return JS_ParseJSON(ctx, addr s[0], cast[csize_t](s.len), cstring"<input>")
+  return JS_ParseJSON(ctx, cstring(s), cast[csize_t](s.len), cstring"<input>")
 
 func credentialsMode*(attribute: CORSAttribute): CredentialsMode =
   case attribute
@@ -342,5 +333,5 @@ proc addRequestModule*(ctx: JSContext) =
     TabGetSet(name: "url", get: Request_url),
     TabGetSet(name: "referrer", get: Request_referrer)
   ])
-  ctx.registerType(Response, extra_funcs = [TabFunc(name: "json", fun: Response_json)])
+  ctx.registerType(Response)
   ctx.registerType(Headers)
diff --git a/src/js/javascript.nim b/src/js/javascript.nim
index 17bc555a..4de01aa9 100644
--- a/src/js/javascript.nim
+++ b/src/js/javascript.nim
@@ -1698,7 +1698,6 @@ type
 macro registerType*(ctx: typed, t: typed, parent: JSClassID = 0, asglobal =
                    false, nointerface = false, name: static string = "",
                    extra_getset: static openarray[TabGetSet] = [],
-                   extra_funcs: static openarray[TabFunc] = [],
                    namespace: JSValue = JS_NULL): JSClassID =
   result = newStmtList()
   let tname = t.strVal # the nim type's name.
@@ -1797,14 +1796,6 @@ macro registerType*(ctx: typed, t: typed, parent: JSClassID = 0, asglobal =
       let m = x.magic
       tabList.add(quote do: JS_CGETSET_MAGIC_DEF(`k`, `g`, `s`, `m`))
 
-  for x in extra_funcs:
-    #TODO TODO TODO ditto. wtf
-    if repr(x) != "" and repr(x) != "[]":
-      let name = x.name
-      let fun = x.fun
-      tabList.add(quote do:
-        JS_CFUNC_DEF(`name`, 0, (`fun`)))
-
   if ctorFun != nil:
     sctr = ctorFun
     result.add(ctorImpl)
a> ^
52daf072 ^

c8a3ccbe ^


52daf072 ^



a0d3cac4 ^



52daf072 ^

a0d3cac4 ^
52daf072 ^


a0d3cac4 ^
52daf072 ^

a0d3cac4 ^
52daf072 ^

a0d3cac4 ^
52daf072 ^
c8a3ccbe ^
52daf072 ^

a0d3cac4 ^
52daf072 ^















ce2c1efc ^
52daf072 ^
a0d3cac4 ^
52daf072 ^





a0d3cac4 ^

52daf072 ^

a0d3cac4 ^
c8a3ccbe ^
52daf072 ^

ce2c1efc ^



a0d3cac4 ^

ce2c1efc ^

a0d3cac4 ^
695f9bf8 ^
ce2c1efc ^
a0d3cac4 ^
ce2c1efc ^


52daf072 ^
ce2c1efc ^





































104e521c ^



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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211