|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 | 3 | const Vim = require('./js-vim');
|
4 |
| -const tui = require('terminal-ui'); |
| 4 | +let vim; |
| 5 | +let kb; |
| 6 | +let io; |
| 7 | +let res; |
| 8 | +// const tui = require('terminal-ui'); |
5 | 9 |
|
6 |
| -const mauve = require('./mauve'); |
7 |
| -const scheme = require('./lib/scheme'); |
8 |
| -mauve.set(scheme); |
| 10 | +// const mauve = require('./mauve'); |
| 11 | +// const scheme = require('./lib/scheme'); |
| 12 | +// mauve.set(scheme); |
9 | 13 |
|
10 |
| -function main(api) { |
| 14 | +const kbaliases = { |
| 15 | + enter: '\n', |
| 16 | + tab: '\t', |
| 17 | + backspace: '\b', |
| 18 | + space: ' ', |
| 19 | + escape: 'esc', |
| 20 | + kpup: '↑', |
| 21 | + kpdown: '↓', |
| 22 | + kpleft: '←', |
| 23 | + kpright: '→', |
| 24 | +}; |
| 25 | + |
| 26 | +// const kbignore = ['kpdown', 'kpup', 'kpleft', 'kpright']; |
| 27 | + |
| 28 | +function keyboard(key) { |
| 29 | + if (key.type === 'kppagedown') { |
| 30 | + kb.onKeydown.remove(keyboard); |
| 31 | + return res(0); |
| 32 | + } |
| 33 | + |
| 34 | + // if (kbignore.indexOf(key.type) !== -1) return false; |
| 35 | + if (key.type === 'character') { |
| 36 | + vim.exec(kbaliases[key.character] || key.character); |
| 37 | + } else { |
| 38 | + vim.exec(kbaliases[key.type] || key.type.slice(0, 2) === 'kp' ? '' : key.type); |
| 39 | + } |
| 40 | + return false; |
| 41 | +} |
| 42 | + |
| 43 | +function main(api, cb) { |
11 | 44 | // Instance
|
12 |
| - const vim = new Vim(); |
| 45 | + vim = new Vim(); |
13 | 46 |
|
14 |
| - // Apply node commands (file write, etc.) |
15 |
| - require('./lib/commands')(vim); |
| 47 | + kb = api.keyboard; |
| 48 | + io = api.stdio; |
| 49 | + res = cb; |
16 | 50 |
|
17 |
| - // Keystrokes |
18 |
| - const Keys = require('terminal-keys'); |
19 |
| - const keys = new Keys(); |
| 51 | + // Apply node commands (file write, etc.) |
| 52 | + require('./lib/commands')(vim); |
20 | 53 |
|
21 |
| - // Connect keys to vim instance |
22 |
| - keys.fn = function (key) { |
23 |
| - vim.exec(key); |
24 |
| - }; |
| 54 | + kb.onKeydown.add(keyboard); |
25 | 55 |
|
26 |
| - // Clear the terminal screen |
27 |
| -// tui.clear(); |
| 56 | + io.clear(); |
| 57 | + io.write(vim.view.getText()); |
28 | 58 |
|
29 | 59 | // Tie tui to vim.view
|
30 | 60 | vim.view.on('change', () => {
|
31 |
| - api.stdio.write(vim.view.getText()); |
32 |
| - // tui.write(vim.view.getText()); |
| 61 | + io.clear(); |
| 62 | + io.write(vim.view.getText()); |
33 | 63 | });
|
34 |
| - |
35 |
| - // Open file if one has been indicated |
36 |
| - const files = []; // TODO: make this take cl args |
37 |
| - if (files.length) { |
38 |
| - vim.exec(`:e ${files.shift()}\n`); |
39 |
| - } |
40 | 64 | }
|
41 | 65 | exports.commands = ['vim'];
|
42 |
| -exports.call = (app, args, api) => { |
43 |
| - main(api); |
| 66 | +exports.call = (app, args, api, res) => { |
| 67 | + main(api, res); |
44 | 68 | };
|
0 commit comments