Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
----

### 下载

* [Latest release](https://github.com/Eugeny/tabby/releases/latest)
* [Repositories](https://packagecloud.io/eugeny/tabby): [Debian/Ubuntu-based](https://packagecloud.io/eugeny/tabby/install#bash-deb), [RPM-based](https://packagecloud.io/eugeny/tabby/install#bash-rpm)
* [Latest nightly build](https://nightly.link/Eugeny/tabby/workflows/build/master)
Expand Down
85 changes: 83 additions & 2 deletions app/lib/pty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { Application } from './app'
import { UTF8Splitter } from './utfSplitter'
import { Subject, debounceTime } from 'rxjs'
import { execSync } from 'child_process'

class PTYDataQueue {
private buffers: Buffer[] = []
Expand Down Expand Up @@ -92,7 +93,25 @@
private outputQueue: PTYDataQueue
exited = false

constructor (private id: string, private app: Application, ...args: any[]) {
constructor(private id: string, private app: Application, ...args: any[])

Check failure on line 96 in app/lib/pty.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing space before function parentheses
{

Check failure on line 97 in app/lib/pty.ts

View workflow job for this annotation

GitHub Actions / Lint

Opening curly brace does not appear on the same line as controlling statement

const env = process.platform === 'win32' ? refreshenvFromRegistery() : args["2"].env

Check failure on line 99 in app/lib/pty.ts

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote

Check failure on line 99 in app/lib/pty.ts

View workflow job for this annotation

GitHub Actions / Lint

'refreshenvFromRegistery' was used before it was defined
const origin_env = args["2"].env;

Check failure on line 100 in app/lib/pty.ts

View workflow job for this annotation

GitHub Actions / Lint

Extra semicolon

Check failure on line 100 in app/lib/pty.ts

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote
if (process.env.NODE_ENV === 'development')
{

Check failure on line 102 in app/lib/pty.ts

View workflow job for this annotation

GitHub Actions / Lint

Opening curly brace does not appear on the same line as controlling statement
console.dir("origin_env", origin_env)

Check failure on line 103 in app/lib/pty.ts

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote
}
const newEnv = Object.assign(origin_env, env)
if (process.env.NODE_ENV === 'development')
{

Check failure on line 107 in app/lib/pty.ts

View workflow job for this annotation

GitHub Actions / Lint

Opening curly brace does not appear on the same line as controlling statement
console.dir("newEnv", newEnv)

Check failure on line 108 in app/lib/pty.ts

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote
}
if (process.platform === 'win32')
{
args["2"].env = newEnv
}

this.pty = (nodePTY as any).spawn(...args)
for (const key of ['close', 'exit']) {
(this.pty as any).on(key, (...eventArgs) => this.emit(key, ...eventArgs))
Expand Down Expand Up @@ -137,8 +156,70 @@
}
}


function refreshenvFromRegistery()
{

function getUserEnvFromRegistry(): Record<string, string>
{
const env: Record<string, string> = {}
try
{
const output = execSync('reg query "HKCU\\Environment"', { encoding: 'utf-8' })
const lines = output.split(/\r?\n/)
for (const line of lines)
{
const match = line.match(/^\s*(\w+)\s+REG_\w+\s+(.*)$/)
if (match)
{
const [, key, value] = match
env[key] = value
}
}
} catch (err)
{
console.error('读取注册表失败', err)
}
return env
}

/**
* 从注册表中读取系统环境变量(HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment)
*/
function getSystemEnvFromRegistry(): Record<string, string>
{
const env: Record<string, string> = {}
try
{
const output = execSync(
'reg query "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"',
{ encoding: 'utf-8' }
)
const lines = output.split(/\r?\n/)
for (const line of lines)
{
const match = line.match(/^\s*(\w+)\s+REG_\w+\s+(.*)$/)
if (match)
{
const [, key, value] = match
env[key] = value
}
}
} catch (err)
{
console.error('读取系统注册表失败', err)
}
return env
}

const userEnv = getUserEnvFromRegistry()
const systemEnv = getSystemEnvFromRegistry()
const env = { ...userEnv, ...systemEnv }

return env;
}
export class PTYManager {
private ptys: Record<string, PTY|undefined> = {}
private ptys: Record<string, PTY | undefined> = {}

init (app: Application): void {
ipcMain.on('pty:spawn', (event, ...options) => {
Expand Down
34 changes: 28 additions & 6 deletions app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3939,8 +3939,7 @@ strict-uri-encode@^2.0.0:
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
integrity sha1-ucczDHBChi9rFC3CdLvMWGbONUY=

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
name string-width-cjs
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -3975,6 +3974,15 @@ string-width@^3.0.0, string-width@^3.1.0:
is-fullwidth-code-point "^2.0.0"
strip-ansi "^5.1.0"

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^5.0.1, string-width@^5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794"
Expand Down Expand Up @@ -4017,8 +4025,7 @@ stringify-package@^1.0.0, stringify-package@^1.0.1:
resolved "https://registry.yarnpkg.com/stringify-package/-/stringify-package-1.0.1.tgz#e5aa3643e7f74d0f28628b72f3dad5cecfc3ba85"
integrity sha512-sa4DUQsYciMP1xhKWGuFM04fB0LG/9DlluZoSVywUMRNvzid6XucHK0/90xGxRoHrAaROrcHK1aPKaijCtSrhg==

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.1:
name strip-ansi-cjs
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -4053,6 +4060,13 @@ strip-ansi@^6.0.0:
dependencies:
ansi-regex "^5.0.0"

strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1:
version "7.1.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
Expand Down Expand Up @@ -4457,8 +4471,7 @@ worker-farm@^1.6.0, worker-farm@^1.7.0:
dependencies:
errno "~0.1.7"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
name wrap-ansi-cjs
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -4484,6 +4497,15 @@ wrap-ansi@^5.1.0:
string-width "^3.0.0"
strip-ansi "^5.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down
3 changes: 3 additions & 0 deletions fs-write-stream-atomic/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
coverage/
.nyc_output/
11 changes: 11 additions & 0 deletions fs-write-stream-atomic/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: node_js
sudo: false
before_install:
- "npm -g install npm"
node_js:
- "0.8"
- "0.10"
- "0.12"
- "iojs"
- "4"
- "5"
15 changes: 15 additions & 0 deletions fs-write-stream-atomic/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
The ISC License

Copyright (c) Isaac Z. Schlueter and Contributors

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
35 changes: 35 additions & 0 deletions fs-write-stream-atomic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# fs-write-stream-atomic

Like `fs.createWriteStream(...)`, but atomic.

Writes to a tmp file and does an atomic `fs.rename` to move it into
place when it's done.

First rule of debugging: **It's always a race condition.**

## USAGE

```javascript
var fsWriteStreamAtomic = require('fs-write-stream-atomic')
// options are optional.
var write = fsWriteStreamAtomic('output.txt', options)
var read = fs.createReadStream('input.txt')
read.pipe(write)

// When the write stream emits a 'finish' or 'close' event,
// you can be sure that it is moved into place, and contains
// all the bytes that were written to it, even if something else
// was writing to `output.txt` at the same time.
```

### `fsWriteStreamAtomic(filename, [options])`

* `filename` {String} The file we want to write to
* `options` {Object}
* `chown` {Object} User and group to set ownership after write
* `uid` {Number}
* `gid` {Number}
* `encoding` {String} default = 'utf8'
* `mode` {Number} default = `0666`
* `flags` {String} default = `'w'`

Loading
Loading