xp-command 1.0.3 → 1.2.0

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **Quick cockpit commands for X-Plane 12** - set your radios, altimeter, autopilot, and more from the terminal while flying.
4
4
 
5
- | ![Screenshot 1](https://private-user-images.githubusercontent.com/527049/508717737-406f9777-65fa-4e68-a567-0000ab0752ff.gif?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NjIwOTU0MTgsIm5iZiI6MTc2MjA5NTExOCwicGF0aCI6Ii81MjcwNDkvNTA4NzE3NzM3LTQwNmY5Nzc3LTY1ZmEtNGU2OC1hNTY3LTAwMDBhYjA3NTJmZi5naWY_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUxMTAyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MTEwMlQxNDUxNThaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT04NDBmMmE4NjhjNDYzZTM2NGZiNjE2MzcxNGEzY2U3MjkwMDZlMmI2OWIxNGZiZjdkM2Y2MzEyNzA4OWEwZmNmJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.Mfno_SxgF05_L4D9t7vQnmkRsPhkbkl-APGzOsH8CL8) | ![Screenshot 2](https://private-user-images.githubusercontent.com/527049/508717738-6fe80ed3-a30e-4b0d-b368-54061fb044ae.gif?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NjIwOTU0MTgsIm5iZiI6MTc2MjA5NTExOCwicGF0aCI6Ii81MjcwNDkvNTA4NzE3NzM4LTZmZTgwZWQzLWEzMGUtNGIwZC1iMzY4LTU0MDYxZmIwNDRhZS5naWY_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUxMTAyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MTEwMlQxNDUxNThaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kMGJhM2UyMzZmMDcxMTg4MmVhMDhiYzRmY2VjYTBmMzc1ZjQxZjI0NDQwYWViODZhZWM5MDIxNThiM2VjMzYzJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.zTG3-LCMrCInyRSHbkdWzARl4gpeTQtUM3oeRj9teQo) |
5
+ | ![screenshot1](https://github.com/user-attachments/assets/b07bda9e-6d45-430b-bbdb-26dad4c81c59) | ![screenshot2](https://github.com/user-attachments/assets/78d828c2-d838-4fcd-998d-1ac19ec2d5c8) |
6
6
  | ----------------- | ---------------- |
7
7
 
8
8
 
@@ -89,23 +89,30 @@ All pre-configured commands work well with most aircraft I currently fly, but yo
89
89
 
90
90
  ### Barometric pressure
91
91
 
92
- | Command | Action | Example |
93
- |---------|-----------------------------------------|--------------|
94
- | `q` | Get QNH in hPa/mb (copied to clipboard) | `q` → `1013` |
95
- | `l` | Get QNH in inHg (copied to clipboard) | `l` → `2992` |
96
- | `q####` | Set QNH in hPa/mb | `q1013` |
97
- | `l####` | Set QNH in inHg | `l2992` |
92
+ | Command | Action | Example |
93
+ |----------|-----------------------------------------|--------------|
94
+ | `q` | Get QNH in hPa/mb (copied to clipboard) | `q` → `1013` |
95
+ | `l` | Get QNH in inHg (copied to clipboard) | `l` → `2992` |
96
+ | `q####` | Set QNH in hPa/mb | `q1013` |
97
+ | `l####` | Set QNH in inHg | `l2992` |
98
+ | `m###` | Set BARO minimum in feet | `m200` |
99
+ | `mra###` | Set RA minimum in feet | `mra1451` |
100
+
101
+ **Minimums format:** Minimums take one to four digits and can range from 0 to 5000.
98
102
 
99
103
  ### Autopilot
100
104
 
101
- | Command | Action | Example |
102
- |----------|-----------------------------|---------------------------|
103
- | `h###` | Set heading | `h090` → 090° |
104
- | `a###` | Set altitude (flight level) | `a250` → FL250 (25000 ft) |
105
- | `a#####` | Set altitude (exact feet) | `a03500` → 3500 ft |
106
- | `s###` | Set speed in KIAS | `s180` → 180 knots |
107
- | `s##` | Set speed in Mach | `s78` → Mach 0.78 |
108
- | `v####` | Set vertical speed | `v1500` → 1500 ft/min |
105
+ | Command | Action | Example |
106
+ |----------|-----------------------------------------|---------------------------|
107
+ | `h###` | Set heading | `h090` → 090° |
108
+ | `a###` | Set altitude (flight level) | `a250` → FL250 (25000 ft) |
109
+ | `a#####` | Set altitude (exact feet) | `a03500` → 3500 ft |
110
+ | `s###` | Set speed in KIAS | `s180` → 180 knots |
111
+ | `s##` | Set speed in Mach | `s78` → Mach 0.78 |
112
+ | `v####` | Set vertical speed | `v1500` → 1500 ft/min |
113
+ | `fms` | Copy current FMS CDU1 text to clipboard | |
114
+
115
+ **The `fms` command:** This command can be very helpful, if you want to quickly paste the FMS screen content into a prompt. Note that only the first line will be shortly displayed in xp-command cli while the full text will be copied to clipboard.
109
116
 
110
117
  ### Radios
111
118
 
@@ -119,6 +126,8 @@ All pre-configured commands work well with most aircraft I currently fly, but yo
119
126
  | `ns1#####` | Set NAV1 standby | No decimal | `ns1116600` → 116.600 |
120
127
  | `n2#####` | Set NAV2 active | No decimal | `n2113900` → 113.900 |
121
128
  | `ns2#####` | Set NAV2 standby | No decimal | `ns2115700` → 115.700 |
129
+ | `adf1###` | Set ADF1 | No decimal | `adf1333` → 333.0 |
130
+ | `adf2###` | Set ADF2 | No decimal | `adf2444` → 444.0 |
122
131
 
123
132
  **Radio frequency format:** Remove the decimal point. For `118.900`, type `118900`. For COM1 and COM2 you can omit the last digit – the value will be padded with 0.
124
133
 
@@ -134,9 +143,8 @@ All pre-configured commands work well with most aircraft I currently fly, but yo
134
143
 
135
144
  The first time you run xp-command in a new aircraft, it automatically creates a configuration file at:
136
145
 
137
- ```
138
- ~/.xp-command/<Aircraft Name>.yml
139
- ```
146
+ - **macOS/Linux:** `~/.xp-command/<Aircraft Name>.yml`
147
+ - **Windows:** `%USERPROFILE%\.xp-command\<Aircraft Name>.yml`
140
148
 
141
149
  ### Customizing commands
142
150
 
@@ -154,11 +162,11 @@ You can edit these YAML files to add aircraft-specific commands or modify existi
154
162
 
155
163
  **Key components:**
156
164
  - `pattern`: Regular expression matching your command (`hdg18`)
157
- - `type`: Either `get` (read value) or `set` (write value)
165
+ - `type`: Either `get` (read value and copy to clipboard) or `set` (write value)
158
166
  - `dataref`: X-Plane dataref path (find these in X-Plane's DataRef Editor)
159
167
  - `transform`: Optional value conversions (multiply, divide, round, etc.)
160
168
 
161
- **Finding datarefs**: Use [the DataRefTool plugin](https://datareftool.com) or check [X-Plane datarefs documentation](https://developer.x-plane.com/datarefs/).
169
+ **Finding datarefs**: Use the [DataRefTool plugin](https://datareftool.com) or check [X-Plane datarefs documentation](https://developer.x-plane.com/datarefs/).
162
170
 
163
171
  #### Array Datarefs
164
172
 
@@ -179,8 +187,8 @@ If you've edited an aircraft configuration and xp-command crashes or stops worki
179
187
 
180
188
  Aircraft profiles are stored in:
181
189
 
182
- **macOS/Linux:** `~/.xp-command/`
183
- **Windows:** `%USERPROFILE%\.xp-command\`
190
+ - **macOS/Linux:** `~/.xp-command/`
191
+ - **Windows:** `%USERPROFILE%\.xp-command\`
184
192
 
185
193
  Each aircraft has its own `.yml` file named after the aircraft (e.g., `Cessna 172SP.yml`).
186
194
 
@@ -238,6 +246,16 @@ The tool will automatically recreate default configurations when you next fly ea
238
246
 
239
247
  ---
240
248
 
249
+ ## ⬆️️ Updating
250
+
251
+ Open Terminal and run:
252
+
253
+ ```bash
254
+ npm update -g xp-command
255
+ ```
256
+
257
+ ---
258
+
241
259
  ## 🗑️ Uninstalling
242
260
 
243
261
  ### Uninstall npm package
package/bin/index.js CHANGED
@@ -12,7 +12,7 @@ import chalk from "chalk";
12
12
  import { program } from "commander";
13
13
  import ora from "ora";
14
14
 
15
- import { getDatarefValue, initAPI, setDatarefValue } from "../src/api.js";
15
+ import { getDatarefValues, initAPI, setDatarefValue } from "../src/api.js";
16
16
  import { copyToClipboard } from "../src/clipboard.js";
17
17
  import { getConfig } from "../src/config.js";
18
18
  import { clearLine, hideCursor, showCursor } from "../src/console.js";
@@ -49,7 +49,7 @@ const processCommand = async (command) => {
49
49
  }
50
50
 
51
51
  /**
52
- * @param {number|Array<number>|string} value
52
+ * @param {number|string} value
53
53
  * @param {import('../src/config.js').Transform} transform
54
54
  */
55
55
  const getTransformedValue = (value, transform) => {
@@ -81,12 +81,15 @@ const processCommand = async (command) => {
81
81
  return [
82
82
  new RegExp(c.pattern),
83
83
  async () => {
84
- let value = await getDatarefValue(c.dataref);
84
+ let value = await getDatarefValues(c.dataref);
85
85
  c.transform?.forEach((t) => {
86
86
  value = getTransformedValue(value, t);
87
87
  });
88
- await copyToClipboard(JSON.stringify(value));
89
- spinner.succeed(chalk.green(`${PREFIX} ${value}`));
88
+ const asString = String(value)
89
+ await copyToClipboard(asString);
90
+ const lines = asString.split('\n')
91
+ const firstLine = lines[0]
92
+ spinner.succeed(chalk.green(`${PREFIX} ${lines.length > 1 ? firstLine + '...' : firstLine}`));
90
93
  hideCursor();
91
94
  await sleep(1500);
92
95
  clearLine();
@@ -96,12 +99,17 @@ const processCommand = async (command) => {
96
99
  return [
97
100
  new RegExp(c.pattern),
98
101
  async (regExpResult) => {
99
- let value = regExpResult[1];
100
- c.transform?.forEach((t) => {
101
- value = String(getTransformedValue(value, t));
102
- });
103
-
104
- await setDatarefValue(c.dataref, Number(value));
102
+ let value = String(regExpResult[1]);
103
+
104
+ if (isNaN(Number(value))) {
105
+ const base64 = Buffer.from(value, 'utf-8').toString('base64');
106
+ await setDatarefValue(c.dataref, base64);
107
+ } else {
108
+ c.transform?.forEach((t) => {
109
+ value = String(getTransformedValue(value, t));
110
+ });
111
+ await setDatarefValue(c.dataref, Number(value));
112
+ }
105
113
  spinner.succeed(chalk.green(`${PREFIX} ${command}`));
106
114
  hideCursor();
107
115
  await sleep(1500);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xp-command",
3
- "version": "1.0.3",
3
+ "version": "1.2.0",
4
4
  "description": "Quick cockpit commands for X-Plane 12 - set your radios, altimeter, autopilot, and more from the terminal while flying.",
5
5
  "keywords": [
6
6
  "xplane",
package/src/api.js CHANGED
@@ -67,7 +67,7 @@ export const initAPI = (options) => {
67
67
 
68
68
  /**
69
69
  * @param {string} datarefNameWithOptionalIndex
70
- * @return {Promise<number|Array<number>|string>}
70
+ * @return {Promise<number|string>}
71
71
  */
72
72
  export const getDatarefValue = async (datarefNameWithOptionalIndex) => {
73
73
  const [datarefName, index] = parseDataref(datarefNameWithOptionalIndex);
@@ -106,9 +106,23 @@ export const getDatarefValue = async (datarefNameWithOptionalIndex) => {
106
106
  return JSON.stringify(json.data);
107
107
  };
108
108
 
109
+ /**
110
+ * @param {string|Array<string>} datarefNamesWithOptionalIndex
111
+ * @return {Promise<number|string>}
112
+ */
113
+ export const getDatarefValues = async (datarefNamesWithOptionalIndex) => {
114
+ if (Array.isArray(datarefNamesWithOptionalIndex)) {
115
+ return Promise.all(datarefNamesWithOptionalIndex.map(dataref => getDatarefValue(dataref))).then(results => {
116
+ return results.map(v => String(v)).join('\n').trim()
117
+ })
118
+ }
119
+
120
+ return getDatarefValue(datarefNamesWithOptionalIndex)
121
+ }
122
+
109
123
  /**
110
124
  * @param {string} datarefNameWithOptionalIndex
111
- * @param {number|Array<number>} [value]
125
+ * @param {number|string} value
112
126
  */
113
127
  export const setDatarefValue = async (datarefNameWithOptionalIndex, value) => {
114
128
  const [datarefName, index] = parseDataref(datarefNameWithOptionalIndex);
@@ -126,7 +140,7 @@ export const setDatarefValue = async (datarefNameWithOptionalIndex, value) => {
126
140
  method: "PATCH",
127
141
  body: JSON.stringify({ data: value }),
128
142
  });
129
- const json = /** @type { {data: number|Array<number> } | APIError } */ (
143
+ const json = /** @type { {data: number|string } | APIError } */ (
130
144
  await response.json()
131
145
  );
132
146
 
package/src/config.yml CHANGED
@@ -72,7 +72,7 @@ commands:
72
72
  - mult100
73
73
  - round
74
74
 
75
- # set com1 frequency
75
+ # set COM1 frequency
76
76
  - pattern: "^c1(\\d{6})$"
77
77
  type: set
78
78
  dataref: sim/cockpit2/radios/actuators/com1_frequency_hz_833
@@ -83,7 +83,7 @@ commands:
83
83
  - mult10
84
84
  - round
85
85
 
86
- # set com1 standby frequency
86
+ # set COM1 standby frequency
87
87
  - pattern: "^cs1(\\d{6})$"
88
88
  type: set
89
89
  dataref: sim/cockpit2/radios/actuators/com1_standby_frequency_hz_833
@@ -94,7 +94,7 @@ commands:
94
94
  - mult10
95
95
  - round
96
96
 
97
- # set com2 frequency
97
+ # set COM2 frequency
98
98
  - pattern: "^c2(\\d{6})$"
99
99
  type: set
100
100
  dataref: sim/cockpit2/radios/actuators/com2_frequency_hz_833
@@ -105,7 +105,7 @@ commands:
105
105
  - mult10
106
106
  - round
107
107
 
108
- # set com2 standby frequency
108
+ # set COM2 standby frequency
109
109
  - pattern: "^cs2(\\d{6})$"
110
110
  type: set
111
111
  dataref: sim/cockpit2/radios/actuators/com2_standby_frequency_hz_833
@@ -116,22 +116,63 @@ commands:
116
116
  - mult10
117
117
  - round
118
118
 
119
- # set nav1 frequency
119
+ # set NAV1 frequency
120
120
  - pattern: "^n1(\\d{5})$"
121
121
  type: set
122
122
  dataref: sim/cockpit/radios/nav1_freq_hz
123
123
 
124
- # set nav1 standby frequency
124
+ # set NAV1 standby frequency
125
125
  - pattern: "^ns1(\\d{5})$"
126
126
  type: set
127
127
  dataref: sim/cockpit/radios/nav1_stdby_freq_hz
128
128
 
129
- # set nav2 frequency
129
+ # set NAV2 frequency
130
130
  - pattern: "^n2(\\d{5})$"
131
131
  type: set
132
132
  dataref: sim/cockpit/radios/nav2_freq_hz
133
133
 
134
- # set nav2 standby frequency
134
+ # set NAV2 standby frequency
135
135
  - pattern: "^ns2(\\d{5})$"
136
136
  type: set
137
137
  dataref: sim/cockpit/radios/nav2_stdby_freq_hz
138
+
139
+ # set ADF1
140
+ - pattern: "^adf1(\\d{3})$"
141
+ type: set
142
+ dataref: sim/cockpit/radios/adf1_freq_hz
143
+
144
+ # set ADF2
145
+ - pattern: "^adf2(\\d{3})$"
146
+ type: set
147
+ dataref: sim/cockpit/radios/adf2_freq_hz
148
+
149
+ # set BARO minimum
150
+ - pattern: "^m(\\d\\d?\\d?|[0-4]\\d\\d\\d|5000)$"
151
+ type: set
152
+ dataref: sim/cockpit2/gauges/actuators/baro_altimeter_bug_ft_pilot
153
+
154
+ # set RA minimum
155
+ - pattern: "^mra(\\d\\d?\\d?|[0-4]\\d\\d\\d|5000)$"
156
+ type: set
157
+ dataref: sim/cockpit/misc/radio_altimeter_minimum
158
+
159
+ # copy FMS to clipboard
160
+ - pattern: "^fm(s|c)$"
161
+ type: get
162
+ dataref:
163
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line0
164
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line1
165
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line2
166
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line3
167
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line4
168
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line5
169
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line6
170
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line7
171
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line8
172
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line9
173
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line10
174
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line11
175
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line12
176
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line13
177
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line14
178
+ - sim/cockpit2/radios/indicators/fms_cdu1_text_line15