summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThorkil Værge <thorkilk@gmail.com>2020-08-12 01:44:39 +0200
committerGitHub <noreply@github.com>2020-08-12 01:44:39 +0200
commit34d628d1d19ff619b1e810e3a08014d422b83cba (patch)
treebce2859394bbebc42d1899c77270c907bb4575f1
parent219161e13ea035fedb18f4a6f3ef56a515f75f2e (diff)
Add preliminary support for parsing of command line options (#86)
* Add preliminary support for parsing of command line options * Remove redundant options for width and height * Add parser for command line arguments. Type validation outstanding. * Update TODO list * Use config for argv's default values, simplify argument management Co-authored-by: LH <@>
-rw-r--r--README.md10
-rw-r--r--main.js72
-rw-r--r--package.json3
-rw-r--r--src/Mapscii.js23
-rw-r--r--src/config.js7
5 files changed, 92 insertions, 23 deletions
diff --git a/README.md b/README.md
index f2a3fc3..a638dbe 100644
--- a/README.md
+++ b/README.md
@@ -99,11 +99,11 @@ If your terminal supports mouse events you can drag the map and use your scroll
* MapSCII
* [ ] GeoJSON support via [geojson-vt](https://github.com/mapbox/geojson-vt)
* [ ] CLI support
- * [ ] startup parameters
- * [ ] TileSource
- * [ ] Style
- * [ ] center position
- * [ ] zoom
+ * [-] startup parameters
+ * [X] TileSource
+ * [X] Style
+ * [X] center position
+ * [X] zoom
* [ ] demo mode?
* [ ] mouse control
diff --git a/main.js b/main.js
index 7498c1a..afc3337 100644
--- a/main.js
+++ b/main.js
@@ -8,9 +8,79 @@
TODO: params parsing and so on
#*/
'use strict';
+const config = require('./src/config');
const Mapscii = require('./src/Mapscii');
+const argv = require('yargs')
+ .option('latitude', {
+ alias: 'lat',
+ description: 'Latitude of initial centre',
+ default: config.initialLat,
+ type: 'number',
+ })
+ .option('longitude', {
+ alias: 'lon',
+ description: 'Longitude of initial centre',
+ default: config.initialLon,
+ type: 'number',
+ })
+ .option('zoom', {
+ alias: 'z',
+ description: 'Initial zoom',
+ default: config.initialZoom,
+ type: 'number',
+ })
+ .option('width', {
+ alias: 'w',
+ description: 'Fixed width of rendering in dot units',
+ type: 'number',
+ })
+ .option('height', {
+ alias: 'h',
+ description: 'Fixed height of rendering in dot units',
+ type: 'number',
+ })
+ .option('braille', {
+ alias: 'b',
+ description: 'Activate braille rendering',
+ default: config.useBraille,
+ type: 'boolean',
+ })
+ .option('headless', {
+ alias: 'H',
+ description: 'Activate headless mode',
+ default: config.headless,
+ type: 'boolean',
+ })
+ .option('tile_source', {
+ alias: 'tileSource',
+ description: 'URL or path to osm2vectortiles source',
+ default: config.source,
+ type: 'string',
+ })
+ .option('style_file', {
+ alias: 'style',
+ description: 'path to json style file',
+ default: config.styleFile,
+ type: 'string',
+ })
+ .strict()
+ .argv;
-const mapscii = new Mapscii();
+const options = {
+ initialLat: argv.latitude,
+ initialLon: argv.longitude,
+ initialZoom: argv.zoom,
+ size: {
+ width: argv.width,
+ height: argv.height
+ },
+ useBraille: argv.braille,
+ headless: argv.headless,
+ source: argv.tile_source,
+ styleFile: argv.style_file,
+}
+
+const mapscii = new Mapscii(options);
mapscii.init().catch((err) => {
console.error('Failed to start MapSCII.');
console.error(err);
diff --git a/package.json b/package.json
index 8bab5b1..fa4740c 100644
--- a/package.json
+++ b/package.json
@@ -42,7 +42,8 @@
"string-width": "^4.2.0",
"term-mouse": "^0.2.2",
"userhome": "^1.0.0",
- "x256": "0.0.2"
+ "x256": "0.0.2",
+ "yargs": "^15.3.1"
},
"devDependencies": {
"eslint": "^7.0.0",
diff --git a/src/Mapscii.js b/src/Mapscii.js
index 541e3d2..133d756 100644
--- a/src/Mapscii.js
+++ b/src/Mapscii.js
@@ -31,17 +31,13 @@ class Mapscii {
this.renderer = null;
this.zoom = 0;
- // sf lat: 37.787946, lon: -122.407522
- // iceland lat: 64.124229, lon: -21.811552
- // rgbg
- // lat: 49.019493, lon: 12.098341
- this.center = {
- lat: 52.51298,
- lon: 13.42012,
- };
-
this.minZoom = null;
config = Object.assign(config, options);
+
+ this.center = {
+ lat: config.initialLat,
+ lon: config.initialLon
+ };
}
async init() {
@@ -97,13 +93,8 @@ class Mapscii {
}
_resizeRenderer() {
- if (config.size) {
- this.width = config.size.width;
- this.height = config.size.height;
- } else {
- this.width = config.output.columns >> 1 << 2;
- this.height = config.output.rows * 4 - 4;
- }
+ this.width = config.size && config.size.width ? config.size.width : config.output.columns >> 1 << 2;
+ this.height = config.size && config.size.height ? config.size.height : config.output.rows * 4 - 4;
this.minZoom = 4-Math.log(4096/this.width)/Math.LN2;
diff --git a/src/config.js b/src/config.js
index ce48ea7..1e9a4fe 100644
--- a/src/config.js
+++ b/src/config.js
@@ -13,6 +13,13 @@ module.exports = {
maxZoom: 18,
zoomStep: 0.2,
+ // sf lat: 37.787946, lon: -122.407522
+ // iceland lat: 64.124229, lon: -21.811552
+ // rgbg
+ // lat: 49.019493, lon: 12.098341
+ initialLat: 52.51298,
+ initialLon: 14.42012,
+
simplifyPolylines: false,
useBraille: true,