xshell 1.2.49 → 1.2.52

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.
@@ -16,6 +16,10 @@ export declare function unique<TObj>(iterable: TObj[] | Iterable<TObj>, mapper?:
16
16
  export declare function seq<T = number>(n: number, generator?: (index: number) => T): T[];
17
17
  /** 将 keys, values 数组按对应的顺序组合成一个对象 */
18
18
  export declare function zip_object<TValue>(keys: (string | number)[], values: TValue[]): Record<string, TValue>;
19
+ /** 映射对象中的 keys, 返回新对象
20
+ - obj: 对象
21
+ - mapper?: `to_snake_case` (key: string) => string 或者 Record<string, string> */
22
+ export declare function map_keys<TReturn>(obj: any, mapper?: (key: string) => string | Record<string, string>): TReturn;
19
23
  /** 过滤对象中的 values, 返回新对象
20
24
  - obj
21
25
  - filter?: `not_empty` */
package/utils.browser.js CHANGED
@@ -1,4 +1,4 @@
1
- import { is_key_type, select, not_empty, ident } from "./prototype.browser.js";
1
+ import { is_key_type, select, not_empty, ident, to_snake_case } from "./prototype.browser.js";
2
2
  import { t } from "./i18n/instance.js";
3
3
  export function assert(assertion, message) {
4
4
  if (!assertion) {
@@ -54,6 +54,16 @@ export function zip_object(keys, values) {
54
54
  return obj;
55
55
  }, {});
56
56
  }
57
+ /** 映射对象中的 keys, 返回新对象
58
+ - obj: 对象
59
+ - mapper?: `to_snake_case` (key: string) => string 或者 Record<string, string> */
60
+ export function map_keys(obj, mapper = to_snake_case) {
61
+ return Object.fromEntries(Object.entries(obj)
62
+ .map(typeof mapper === 'function' ?
63
+ ([key, value]) => [mapper(key), value]
64
+ :
65
+ ([key, value]) => [mapper[key] || key, value]));
66
+ }
57
67
  /** 过滤对象中的 values, 返回新对象
58
68
  - obj
59
69
  - filter?: `not_empty` */
package/utils.d.ts CHANGED
@@ -25,8 +25,10 @@ export declare function seq<T = number>(n: number, generator?: (index: number) =
25
25
  export declare function sort_keys<TObj>(obj: TObj): TObj;
26
26
  /** 将 keys, values 数组按对应的顺序组合成一个对象 */
27
27
  export declare function zip_object<TValue>(keys: (string | number)[], values: TValue[]): Record<string, TValue>;
28
- /** 映射对象中的 keys, 返回新对象 */
29
- export declare function map_keys<TObj>(obj: TObj, mapper: (key: string) => string): TObj;
28
+ /** 映射对象中的 keys, 返回新对象
29
+ - obj: 对象
30
+ - mapper?: `to_snake_case` (key: string) => string 或者 Record<string, string> */
31
+ export declare function map_keys<TReturn>(obj: any, mapper?: (key: string) => string | Record<string, string>): TReturn;
30
32
  /** 映射对象中的 values, 返回新对象 */
31
33
  export declare function map_values<TValue, TNewValue>(obj: {
32
34
  [key: string]: TValue;
package/utils.js CHANGED
@@ -2,7 +2,7 @@ import { Stream, Writable, Transform } from 'stream';
2
2
  import util from 'util';
3
3
  import timers from 'timers/promises';
4
4
  import { t } from "./i18n/instance.js";
5
- import { select, not_empty, is_key_type, noop, ident } from "./prototype.js";
5
+ import { select, not_empty, is_key_type, noop, ident, to_snake_case } from "./prototype.js";
6
6
  /** `180` 输出字符宽度 */
7
7
  export const output_width = 180;
8
8
  export const url_width = 52;
@@ -81,10 +81,15 @@ export function zip_object(keys, values) {
81
81
  return obj;
82
82
  }, {});
83
83
  }
84
- /** 映射对象中的 keys, 返回新对象 */
85
- export function map_keys(obj, mapper) {
84
+ /** 映射对象中的 keys, 返回新对象
85
+ - obj: 对象
86
+ - mapper?: `to_snake_case` (key: string) => string 或者 Record<string, string> */
87
+ export function map_keys(obj, mapper = to_snake_case) {
86
88
  return Object.fromEntries(Object.entries(obj)
87
- .map(([key, value]) => [mapper(key), value]));
89
+ .map(typeof mapper === 'function' ?
90
+ ([key, value]) => [mapper(key), value]
91
+ :
92
+ ([key, value]) => [mapper[key] || key, value]));
88
93
  }
89
94
  /** 映射对象中的 values, 返回新对象 */
90
95
  export function map_values(obj, mapper) {
package/Terminal.d.ts DELETED
@@ -1,19 +0,0 @@
1
- import '@xterm/xterm/css/xterm.css';
2
- import { Terminal as XTerminal } from '@xterm/xterm';
3
- import { FitAddon } from '@xterm/addon-fit';
4
- import { Model } from 'react-object-model';
5
- import type { Remote } from './net.browser.ts';
6
- export declare function Terminal({ font }: {
7
- font: string;
8
- }): import("react/jsx-runtime").JSX.Element;
9
- declare class TerminalModel extends Model<TerminalModel> {
10
- pterm: import("./utils.browser.ts").Deferred<XTerminal>;
11
- term: XTerminal;
12
- fit_addon: FitAddon;
13
- stdio_id: number;
14
- fit(): void;
15
- subscribe_stdio(remote: Remote): Promise<void>;
16
- unsubscribe_stdio(remote: Remote): Promise<void>;
17
- }
18
- export declare let terminal: TerminalModel;
19
- export {};
package/Terminal.js DELETED
@@ -1,98 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import '@xterm/xterm/css/xterm.css';
3
- import { useEffect, useRef } from 'react';
4
- import { Terminal as XTerminal } from '@xterm/xterm';
5
- import { FitAddon } from '@xterm/addon-fit';
6
- import { WebglAddon } from '@xterm/addon-webgl';
7
- import { WebLinksAddon } from '@xterm/addon-web-links';
8
- // 没有 ui
9
- // import { SearchAddon } from '@xterm/addon-search'
10
- import { Model } from 'react-object-model';
11
- import { assert, defer, genid } from "./utils.browser.js";
12
- export function Terminal({ font }) {
13
- let rterminal = useRef(undefined);
14
- useEffect(() => {
15
- (async () => {
16
- await document.fonts.ready;
17
- let term = new XTerminal({
18
- fontFamily: font,
19
- fontSize: 16,
20
- cursorStyle: 'bar',
21
- disableStdin: true,
22
- convertEol: true,
23
- allowProposedApi: true,
24
- theme: {
25
- ...myscheme,
26
- magenta: myscheme.purple,
27
- brightMagenta: myscheme.brightPurple,
28
- }
29
- });
30
- const fit_addon = new FitAddon();
31
- const link_addon = new WebLinksAddon();
32
- // const search_addon = new SearchAddon()
33
- term.loadAddon(fit_addon);
34
- term.loadAddon(link_addon);
35
- // term.loadAddon(search_addon)
36
- term.open(rterminal.current);
37
- if (document.createElement('canvas').getContext('webgl2'))
38
- term.loadAddon(new WebglAddon());
39
- fit_addon.fit();
40
- terminal.pterm.resolve(term);
41
- terminal.set({ term, fit_addon });
42
- })();
43
- }, []);
44
- return _jsx("div", { className: 'term', ref: rterminal });
45
- }
46
- class TerminalModel extends Model {
47
- pterm = defer();
48
- term;
49
- fit_addon;
50
- stdio_id = 0;
51
- fit() {
52
- this.fit_addon?.fit();
53
- }
54
- async subscribe_stdio(remote) {
55
- assert(!this.stdio_id);
56
- const id = this.stdio_id = genid();
57
- remote.handlers.set(id, ({ data, error }) => {
58
- if (error)
59
- throw error;
60
- else
61
- this.term.write(data[0]);
62
- });
63
- await remote.send({ id, func: 'subscribe_stdio' });
64
- }
65
- async unsubscribe_stdio(remote) {
66
- let { stdio_id } = this;
67
- assert(stdio_id);
68
- await remote.call('unsubscribe_stdio', [stdio_id]);
69
- remote.handlers.delete(stdio_id);
70
- this.stdio_id = 0;
71
- }
72
- }
73
- export let terminal = new TerminalModel();
74
- /** winterm.json */
75
- const myscheme = {
76
- background: '#FFFFFF',
77
- black: '#000000',
78
- blue: '#0070C0',
79
- brightBlack: '#444444',
80
- brightBlue: '#0000FF',
81
- brightCyan: '#008080',
82
- brightGreen: '#718C00',
83
- brightPurple: '#8959A8',
84
- brightRed: '#DF0000',
85
- brightWhite: '#AAAAAA',
86
- brightYellow: '#FF81FF',
87
- cursorColor: '#000000',
88
- cyan: '#821717',
89
- foreground: '#000000',
90
- green: '#008000',
91
- name: 'myscheme',
92
- purple: '#800080',
93
- red: '#C82829',
94
- selectionBackground: '#ADD6FF',
95
- white: '#888888',
96
- yellow: '#EC7600'
97
- };
98
- //# sourceMappingURL=Terminal.js.map