about summary refs log tree commit diff stats
path: root/src/main.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-03-17 21:14:51 +0100
committerbptato <nincsnevem662@gmail.com>2024-03-17 21:20:04 +0100
commitfc8937b53327f99b5809f78e3257e62a05bd1c79 (patch)
tree64655d81478c9fb8ac93d67259c60cb4fd246b5f /src/main.nim
parentd385d07b197cef65c2d2a800378de9152551e3e6 (diff)
downloadchawan-fc8937b53327f99b5809f78e3257e62a05bd1c79.tar.gz
config: clean up/simplify
* Parse the default config at runtime. There's no significant
  performance difference, but this makes it much less painful to write
  config code.
* Add better error reporting
* Make fromJS2 easier to use
* Unquote ChaPaths while parsing config
Diffstat (limited to 'src/main.nim')
-rw-r--r--src/main.nim26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/main.nim b/src/main.nim
index ea5a92dd..51b1219f 100644
--- a/src/main.nim
+++ b/src/main.nim
@@ -6,12 +6,11 @@ let forks = newForkServer()
 import std/options
 import std/os
 
-import config/chapath
 import config/config
 import io/serversocket
+import js/javascript
 import local/client
 import local/term
-import types/opt
 import utils/strwidth
 import utils/twtstr
 
@@ -178,9 +177,15 @@ Options:
       pages.add(param)
     inc i
 
-  let config = readConfig(configPath)
+  let jsrt = newJSRuntime()
+  let jsctx = jsrt.newJSContext()
+  let config = readConfig(configPath, jsctx)
+  var warnings = newSeq[string]()
   for opt in opts:
-    config.parseConfig(getCurrentDir(), opt, laxnames = true)
+    let res = config.parseConfig(getCurrentDir(), opt, laxnames = true)
+    if not res.success:
+      stderr.write(res.errorMsg)
+      quit(1)
   config.css.stylesheet &= stylesheet
 
   set_cjk_ambiguous(config.display.double_width_ambiguous)
@@ -200,16 +205,11 @@ Options:
       help(1)
 
   forks.loadForkServerConfig(config)
-  let tmpdir0 = config.external.tmpdir.unquote()
-  if tmpdir0.isErr:
-    stderr.write("Error unquoting external.tmpdir: " & tmpdir0.error)
-    stderr.write("Exiting...")
-    quit(1)
-  SocketDirectory = tmpdir0.get
-
-  let c = newClient(config, forks)
+  SocketDirectory = config.external.tmpdir
+
+  let c = newClient(config, forks, jsctx)
   try:
-    c.launchClient(pages, ctype, cs, dump)
+    c.launchClient(pages, ctype, cs, dump, warnings)
   except CatchableError:
     c.flushConsole()
     raise
#n208'>208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340