reslop 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/keys.js CHANGED
@@ -1,20 +1,76 @@
1
1
  'use strict';
2
2
 
3
3
  const ACTIONS = {
4
- add: { keys: ['a'], label: 'Add' },
5
- unstage: { keys: ['u'], label: 'Unstage' },
6
- revert: { keys: ['r'], label: 'Revert' },
7
- prev: { keys: ['left', 'p', 'k'], hot: '←', label: 'Prev' },
8
- next: { keys: ['right', 'n', 'j'], hot: '→', label: 'Next' },
9
- layout: { keys: ['m'], label: 'Mode' },
10
- files: { keys: ['l'], label: 'Files' },
11
- feedback: { keys: ['f'], label: 'Feedback' },
12
- todo: { keys: ['t'], label: 'Todo' },
13
- quit: { keys: ['q', 'ctrl-c'], label: 'Quit' },
4
+ add: ['a'],
5
+ unstage: ['u'],
6
+ revert: ['d'],
7
+ commit: ['c'],
8
+ prev: ['left', 'p', 'k'],
9
+ next: ['right', 'n', 'j'],
10
+ layout: ['m'],
11
+ feedback: ['f'],
12
+ todo: ['t'],
13
+ code: ['e'],
14
+ reload: ['r'],
15
+ branch: ['b'],
16
+ pull: ['p'],
17
+ push: ['s'],
18
+ quit: ['q', 'ctrl-c'],
14
19
  };
15
20
  const ACTION_IDS = Object.keys(ACTIONS);
16
21
 
17
- const FILES_DISABLED = ['layout', 'feedback'];
22
+ const BRANCH_ACTIONS = {
23
+ newBranch: ['n'],
24
+ };
25
+
26
+ const ACTION_HOT = {
27
+ prev: '←',
28
+ next: '→',
29
+ };
30
+
31
+ const ACTION_LABEL = {
32
+ revert: 'drop',
33
+ layout: 'mode',
34
+ code: 'edit',
35
+ newBranch: 'new',
36
+ quit: 'q',
37
+ };
38
+
39
+ const DIFF_DISABLED = ['reload', 'branch', 'pull', 'push'];
40
+ const FILES_DISABLED = ['layout', 'feedback', 'code'];
41
+ const TODO_DISABLED = [
42
+ 'add',
43
+ 'unstage',
44
+ 'revert',
45
+ 'layout',
46
+ 'feedback',
47
+ 'code',
48
+ 'reload',
49
+ 'branch',
50
+ 'pull',
51
+ 'push',
52
+ ];
53
+ const BRANCHES_DISABLED = [
54
+ 'add',
55
+ 'unstage',
56
+ 'revert',
57
+ 'commit',
58
+ 'layout',
59
+ 'feedback',
60
+ 'todo',
61
+ 'code',
62
+ 'reload',
63
+ 'branch',
64
+ 'pull',
65
+ 'push',
66
+ ];
67
+
68
+ const disabledActions = (pane, item) => {
69
+ if (pane === 'files') return FILES_DISABLED;
70
+ if (pane === 'branches') return BRANCHES_DISABLED;
71
+ if (item && item.origin === 'todo') return TODO_DISABLED;
72
+ return DIFF_DISABLED;
73
+ };
18
74
 
19
75
  const SCROLL = {
20
76
  up: 'scrollUp',
@@ -31,9 +87,20 @@ const SCROLL = {
31
87
  };
32
88
 
33
89
  const KEY_TO_ACTION = {};
90
+ const PANE_ONLY = ['branch', 'pull', 'push'];
91
+ const FILES_KEYS = {};
92
+ for (const id of PANE_ONLY) {
93
+ for (const key of ACTIONS[id]) FILES_KEYS[key] = id;
94
+ }
95
+ const BRANCH_KEYS = {};
96
+ for (const id of Object.keys(BRANCH_ACTIONS)) {
97
+ for (const key of BRANCH_ACTIONS[id]) BRANCH_KEYS[key] = id;
98
+ }
99
+ const PANE_KEYS = { files: FILES_KEYS, branches: BRANCH_KEYS };
34
100
 
35
101
  for (const id of ACTION_IDS) {
36
- for (const key of ACTIONS[id].keys) KEY_TO_ACTION[key] = id;
102
+ if (PANE_ONLY.includes(id)) continue;
103
+ for (const key of ACTIONS[id]) KEY_TO_ACTION[key] = id;
37
104
  }
38
105
 
39
106
  for (const key of Object.keys(SCROLL)) KEY_TO_ACTION[key] = SCROLL[key];
@@ -166,23 +233,23 @@ const decodeChunk = (text, carry = '') => {
166
233
  return { events, carry: '' };
167
234
  };
168
235
 
169
- const actionFromKey = (key) => KEY_TO_ACTION[key] ?? null;
236
+ const actionFromKey = (key, pane) => {
237
+ const paneKeys = PANE_KEYS[pane];
238
+ if (paneKeys && paneKeys[key]) return paneKeys[key];
239
+ return KEY_TO_ACTION[key] ?? null;
240
+ };
170
241
 
171
- const actionHot = (action) => action.hot ?? action.keys[0];
242
+ const actionKeys = (id) => ACTIONS[id] ?? BRANCH_ACTIONS[id] ?? [];
172
243
 
173
- const actionLetter = (action) => {
174
- if (action.hot) return action.hot;
175
- const label = (action.label ?? '').toLowerCase();
176
- for (const key of action.keys) {
177
- if (key.length !== 1) continue;
178
- if (label.includes(key)) return key;
179
- }
180
- return actionHot(action);
181
- };
244
+ const actionHot = (id) => ACTION_HOT[id] ?? actionKeys(id)[0];
245
+
246
+ const actionLabel = (id) => ACTION_HOT[id] ?? ACTION_LABEL[id] ?? id;
247
+
248
+ const actionLetter = actionHot;
182
249
 
183
- const buttonWord = (action) => {
184
- const word = (action.label ?? '').toLowerCase();
185
- const mark = actionLetter(action);
250
+ const buttonWord = (id) => {
251
+ const word = actionLabel(id);
252
+ const mark = actionLetter(id);
186
253
  if (word.includes(mark)) return word;
187
254
  return `${mark}${word}`;
188
255
  };
@@ -197,7 +264,12 @@ const hitAction = (hits, x) => {
197
264
  module.exports = {
198
265
  ACTIONS,
199
266
  ACTION_IDS,
267
+ BRANCH_ACTIONS,
268
+ DIFF_DISABLED,
200
269
  FILES_DISABLED,
270
+ TODO_DISABLED,
271
+ BRANCHES_DISABLED,
272
+ disabledActions,
201
273
  decodeChunk,
202
274
  actionFromKey,
203
275
  actionHot,