From b790a4d76a9798c897f0eded7a222174d23edc69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Stra=C3=9Fburger?= Date: Sun, 18 Sep 2016 04:20:35 +0200 Subject: [PATCH] :white_check_mark: handling console resize, adding mvp status bar --- README.md | 1 + termap.coffee | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5e9eee6..e07134a 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Discover the world in your console - render vector tile maps from any source! * [ ] setCenter * [ ] setZoom * [x] accurate mouse drag&drop +* [x] handle console resize ## Wishlist * node-gyp binding to [libdrawille](https://github.com/Huulivoide/libdrawille) for speed refactor possibilities + filled polygons diff --git a/termap.coffee b/termap.coffee index 4e82247..68c2aad 100644 --- a/termap.coffee +++ b/termap.coffee @@ -8,8 +8,8 @@ mouse = require('term-mouse')() keypress process.stdin -width = Math.floor((process.stdout.columns-1)/2)*2*2; -height = Math.ceil(process.stdout.rows/4)*4*4; +width = null +height = null drawOrder = ["admin", "water", "landuse", "building", "road"] layers = @@ -19,7 +19,13 @@ layers = admin: "red" building: 8 -canvas = new Canvas width, height +canvas = null + +init = -> + width = Math.floor((process.stdout.columns-1)/2)*2*2 + height = Math.ceil(process.stdout.rows/4)*4*4 + canvas = new Canvas width, height +init() features = {} data = fs.readFileSync __dirname+"/tiles/regensburg.pbf.gz" @@ -42,7 +48,10 @@ size = 4 flush = -> process.stdout.write canvas._canvas.frame() +drawing = false draw = -> + return if drawing + drawing = true canvas.clearRect(0, 0, width, height) canvas.save() @@ -69,7 +78,12 @@ draw = -> canvas.restore() flush() + process.stdout.write getStatus() + drawing = false + +getStatus = -> + "view: [#{view.toString()}] scale: [#{size}] columns: [#{process.stdout.columns}]" moving = null process.stdin.on 'mousepress', (info) -> @@ -110,5 +124,9 @@ process.stdin.on 'keypress', (ch, key) -> draw() if result +process.stdout.on 'resize', -> + init() + draw() + process.stdin.setRawMode(true) process.stdin.resume()