@electerm/electerm-react 1.38.8 → 1.38.11

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.
@@ -126,7 +126,6 @@
126
126
  display inline-block
127
127
  vertical-align middle
128
128
  margin 0 3px 0 3px
129
- -webkit-app-region no-drag
130
129
  color text
131
130
  &.empty
132
131
  font-size 20px
@@ -136,12 +135,11 @@
136
135
  color text-light
137
136
  .tabs-extra
138
137
  position absolute
139
- height 20px
140
- top 14px
138
+ height 40px
139
+ top 0
141
140
  right 96px
142
- line-height 20px
141
+ line-height 40px
143
142
  z-index 20
144
- -webkit-app-region no-drag
145
143
 
146
144
  .tabs-dd-icon
147
145
  color text
@@ -152,7 +150,6 @@
152
150
  .window-controls
153
151
  position absolute
154
152
  right 0
155
- -webkit-app-region no-drag
156
153
  top 0
157
154
  z-index 200
158
155
  border-radius 0 0 3px 3px
@@ -163,7 +160,6 @@
163
160
  display inline-block
164
161
  padding 5px 10px
165
162
  color text
166
- -webkit-app-region no-drag
167
163
  &:hover
168
164
  color primary
169
165
  cursor pointer
@@ -5,100 +5,102 @@ import { AttachAddon } from 'xterm-addon-attach'
5
5
  import strip from '@electerm/strip-ansi'
6
6
 
7
7
  export default class AttachAddonCustom extends AttachAddon {
8
- constructor (term, options, encode, isWindowsShell) {
9
- super(term, options)
8
+ constructor (term, socket, isWindowsShell) {
9
+ super(socket)
10
10
  this.term = term
11
- this.decoder = new TextDecoder(encode)
11
+ this.socket = socket
12
12
  this.isWindowsShell = isWindowsShell
13
13
  }
14
14
 
15
15
  activate (terminal = this.term) {
16
- const writeToTerminal = (data) => {
17
- if (terminal.parent?.onZmodem) {
18
- return
19
- }
20
- if (typeof data === 'string') {
21
- return terminal.write(data)
22
- }
23
- data = new Uint8Array(data)
24
- if (!this.decoder) {
25
- return terminal.write(data)
26
- }
27
- const fileReader = new FileReader()
28
- fileReader.addEventListener('load', () => {
29
- const str = this.decoder.decode(fileReader.result)
30
- if (terminal.parent.props.sftpPathFollowSsh && terminal.buffer.active.type !== 'alternate') {
31
- const {
32
- cwdId
33
- } = terminal
34
- const nss = str.split('\r')
35
- const nnss = []
36
- for (const str1 of nss) {
37
- const ns = strip(str1).trim()
38
- if (ns.includes(cwdId) && ns.includes('$PWD')) {
39
- nnss.push(str1.replace(`echo "${cwdId}$PWD"`, ''))
40
- } else if (
41
- (cwdId && ns.startsWith(cwdId))
42
- ) {
43
- delete terminal.cwdId
44
- const cwd = ns.replace(cwdId, '').trim()
45
- terminal.parent.setCwd(cwd)
46
- nnss.push('\x1b[2A\x1b[0J')
47
- } else {
48
- nnss.push(str1)
49
- }
50
- }
51
- terminal.write(nnss.join('\r'))
52
- } else {
53
- terminal.write(str)
54
- }
55
- })
56
- fileReader.readAsArrayBuffer(new window.Blob([data]))
57
- }
58
-
59
- const sendToServer = (data) => {
60
- this._sendData(data)
61
- }
62
-
63
- const trzsz = window.newTrzsz(
64
- writeToTerminal,
65
- sendToServer,
16
+ this.trzsz = window.newTrzsz(
17
+ this.writeToTerminal,
18
+ this.sendToServer,
66
19
  terminal.cols,
67
20
  this.isWindowsShell
68
21
  )
69
22
 
70
- this._disposables.push(
71
- addSocketListener(this._socket, 'message', (ev) =>
72
- trzsz.processServerOutput(ev.data)
73
- )
74
- )
23
+ this.addSocketListener(this._socket, 'message', this.onMsg)
75
24
 
76
25
  if (this._bidirectional) {
77
- this._disposables.push(terminal.onData((data) => trzsz.processTerminalInput(data)))
78
- this._disposables.push(terminal.onBinary((data) => trzsz.processBinaryInput(data)))
26
+ this._disposables.push(terminal.onData((data) => this.trzsz.processTerminalInput(data)))
27
+ this._disposables.push(terminal.onBinary((data) => this.trzsz.processBinaryInput(data)))
79
28
  }
80
29
 
81
- this._disposables.push(terminal.onResize((size) => trzsz.setTerminalColumns(size.cols)))
30
+ this._disposables.push(terminal.onResize((size) => this.trzsz.setTerminalColumns(size.cols)))
82
31
 
83
- this._disposables.push(addSocketListener(this._socket, 'close', () => this.dispose()))
84
- this._disposables.push(addSocketListener(this._socket, 'error', () => this.dispose()))
32
+ this._disposables.push(this.addSocketListener(this._socket, 'close', () => this.dispose()))
33
+ this._disposables.push(this.addSocketListener(this._socket, 'error', () => this.dispose()))
85
34
  }
86
35
 
87
- dispose () {
88
- this.term = null
89
- this._disposables.forEach(d => d.dispose())
90
- this._disposables.length = 0
36
+ onMsg = (ev) => {
37
+ this.trzsz.processServerOutput(ev.data)
38
+ }
39
+
40
+ writeToTerminal = (data) => {
41
+ const { term } = this
42
+ if (term.parent?.onZmodem) {
43
+ return
44
+ }
45
+ if (typeof data === 'string') {
46
+ return term.write(data)
47
+ }
48
+ data = new Uint8Array(data)
49
+ const fileReader = new FileReader()
50
+ fileReader.addEventListener('load', this.onRead)
51
+ fileReader.readAsArrayBuffer(new window.Blob([data]))
52
+ }
53
+
54
+ onRead = (ev) => {
55
+ const data = ev.target.result
56
+ const { term } = this
57
+ const str = this.decoder.decode(data)
58
+ if (term.parent.props.sftpPathFollowSsh && term.buffer.active.type !== 'alternate') {
59
+ const {
60
+ cwdId
61
+ } = term
62
+ const nss = str.split('\r')
63
+ const nnss = []
64
+ for (const str1 of nss) {
65
+ const ns = strip(str1).trim()
66
+ if (ns.includes(cwdId) && ns.includes('$PWD')) {
67
+ nnss.push(str1.replace(`echo "${cwdId}$PWD"`, ''))
68
+ } else if (
69
+ (cwdId && ns.startsWith(cwdId))
70
+ ) {
71
+ delete term.cwdId
72
+ const cwd = ns.replace(cwdId, '').trim()
73
+ term.parent.setCwd(cwd)
74
+ nnss.push('\x1b[2A\x1b[0J')
75
+ } else {
76
+ nnss.push(str1)
77
+ }
78
+ }
79
+ term.write(nnss.join('\r'))
80
+ } else {
81
+ term.write(str)
82
+ }
91
83
  }
92
- }
93
84
 
94
- function addSocketListener (socket, type, handler) {
95
- socket.addEventListener(type, handler)
96
- return {
97
- dispose: () => {
98
- if (!handler) {
99
- return
85
+ sendToServer = (data) => {
86
+ this._sendData(data)
87
+ }
88
+
89
+ addSocketListener = (socket, type, handler) => {
90
+ socket.addEventListener(type, handler)
91
+ return {
92
+ dispose: () => {
93
+ if (!handler) {
94
+ return
95
+ }
96
+ socket.removeEventListener(type, handler)
100
97
  }
101
- socket.removeEventListener(type, handler)
102
98
  }
103
99
  }
100
+
101
+ dispose = () => {
102
+ this.term = null
103
+ this._disposables.forEach(d => d.dispose())
104
+ this._disposables.length = 0
105
+ }
104
106
  }
@@ -62,5 +62,7 @@ export class KeywordHighlighterAddon {
62
62
  dispose () {
63
63
  // Restore the original write method when disposing the addon
64
64
  this.terminal.write = this.originalWrite
65
+ this.originalWrite = null
66
+ this.term = null
65
67
  }
66
68
  }
@@ -166,18 +166,15 @@ class Term extends Component {
166
166
  }
167
167
  ]
168
168
 
169
- initAttachAddon = (encode) => {
169
+ initAttachAddon = () => {
170
170
  this.attachAddon = new AttachAddon(
171
+ this.term,
171
172
  this.socket,
172
- undefined,
173
- this.props.tab.encode,
174
173
  isWin && !this.isRemote()
175
174
  )
176
- if (encode || this.decode) {
177
- this.attachAddon.decoder = encode
178
- ? new TextDecoder(encode)
179
- : this.decode
180
- }
175
+ this.attachAddon.decoder = new TextDecoder(
176
+ this.encode || this.props.tab.encode || 'utf-8'
177
+ )
181
178
  this.term.loadAddon(this.attachAddon)
182
179
  }
183
180
 
@@ -688,6 +685,7 @@ class Term extends Component {
688
685
  delete this.zsession
689
686
  this.term.focus()
690
687
  this.term.write('\r\n')
688
+ this.onZmodem = false
691
689
  delete this.downloadFd
692
690
  delete this.downloadPath
693
691
  delete this.downloadCount
@@ -1078,7 +1076,6 @@ class Term extends Component {
1078
1076
  const {
1079
1077
  srcId, from = 'bookmarks',
1080
1078
  type,
1081
- encode,
1082
1079
  term: terminalType,
1083
1080
  displayRaw
1084
1081
  } = tab
@@ -1155,19 +1152,13 @@ class Term extends Component {
1155
1152
  const socket = new WebSocket(wsUrl)
1156
1153
  socket.onclose = this.oncloseSocket
1157
1154
  socket.onerror = this.onerrorSocket
1155
+ this.socket = socket
1156
+ this.term = term
1158
1157
  socket.onopen = () => {
1159
- this.attachAddon = new AttachAddon(
1160
- socket,
1161
- undefined,
1162
- encode,
1163
- isWin && !this.isRemote()
1164
- )
1165
- term.loadAddon(this.attachAddon)
1166
- // socket.addEventListener('message', this.onSocketData)
1158
+ this.initAttachAddon()
1167
1159
  this.runInitScript()
1168
1160
  term._initialized = true
1169
1161
  }
1170
- this.socket = socket
1171
1162
  // term.onRrefresh(this.onRefresh)
1172
1163
  term.onResize(this.onResizeTerminal)
1173
1164
  if (pick(term, 'buffer._onBufferChange._listeners')) {
@@ -1187,7 +1178,6 @@ class Term extends Component {
1187
1178
  term.loadAddon(
1188
1179
  new KeywordHighlighterAddon(keywords)
1189
1180
  )
1190
- this.term = term
1191
1181
  window.store.triggerResize()
1192
1182
  }
1193
1183
 
@@ -1303,8 +1293,8 @@ class Term extends Component {
1303
1293
  // }
1304
1294
 
1305
1295
  switchEncoding = encode => {
1306
- this.decode = new TextDecoder(encode)
1307
- this.attachAddon.decoder = this.decode
1296
+ this.encode = encode
1297
+ this.attachAddon.decoder = new TextDecoder(encode)
1308
1298
  }
1309
1299
 
1310
1300
  render () {
@@ -4,10 +4,10 @@ export class AddonZmodem {
4
4
  _disposables = []
5
5
 
6
6
  activate (terminal) {
7
- terminal.zmodemAttach = this.zmodemAttach.bind(this)
7
+ terminal.zmodemAttach = this.zmodemAttach
8
8
  }
9
9
 
10
- sendWebSocket (octets) {
10
+ sendWebSocket = (octets) => {
11
11
  const { socket } = this
12
12
  if (socket && socket.readyState === WebSocket.OPEN) {
13
13
  return socket.send(new Uint8Array(octets))
@@ -16,7 +16,7 @@ export class AddonZmodem {
16
16
  }
17
17
  }
18
18
 
19
- zmodemAttach (ctx) {
19
+ zmodemAttach = (ctx) => {
20
20
  this.socket = ctx.socket
21
21
  this.term = ctx.term
22
22
  this.ctx = ctx
@@ -26,15 +26,15 @@ export class AddonZmodem {
26
26
  this.term.write(String.fromCharCode.apply(String, octets))
27
27
  }
28
28
  },
29
- sender: this.sendWebSocket.bind(this),
29
+ sender: this.sendWebSocket,
30
30
  on_retract: ctx.onzmodemRetract,
31
31
  on_detect: ctx.onZmodemDetect
32
32
  })
33
33
  this.socket.binaryType = 'arraybuffer'
34
- this.socket.addEventListener('message', this.handleWSMessage.bind(this))
34
+ this.socket.addEventListener('message', this.handleWSMessage)
35
35
  }
36
36
 
37
- handleWSMessage (evt) {
37
+ handleWSMessage = (evt) => {
38
38
  if (typeof evt.data === 'string') {
39
39
  if (this.ctx.onZmodem) {
40
40
  this.term.write(evt.data)
@@ -44,7 +44,7 @@ export class AddonZmodem {
44
44
  }
45
45
  }
46
46
 
47
- dispose () {
47
+ dispose = () => {
48
48
  this.socket && this.socket.removeEventListener('message', this.handleWSMessage)
49
49
  this._disposables.forEach(d => d.dispose())
50
50
  this._disposables.length = 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@electerm/electerm-react",
3
- "version": "1.38.8",
3
+ "version": "1.38.11",
4
4
  "description": "react components src for electerm",
5
5
  "main": "./client/components/main/main.jsx",
6
6
  "license": "MIT",