forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4865d4
commit f22a938
Showing
8 changed files
with
184 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { File } from "./files.ts"; | ||
import { sendSync } from "./dispatch_json.ts"; | ||
import * as dispatch from "./dispatch.ts"; | ||
|
||
/** Check if a given resource is TTY. */ | ||
export function isatty(rid: number): boolean { | ||
return sendSync(dispatch.OP_ISATTY, { rid }); | ||
} | ||
|
||
/** Extended file abstraction for TTY input */ | ||
export class TTYInput extends File { | ||
constructor(rid: number) { | ||
super(rid); | ||
if (rid !== 0 && !isatty(rid)) { | ||
throw new Error("Given resource is not a TTY"); | ||
} | ||
} | ||
|
||
/** Is TTY under raw mode. */ | ||
get isRaw(): boolean { | ||
return this._isRaw; | ||
} | ||
private _isRaw = false; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
private _restoreInfo: { [key: string]: any } = {}; | ||
|
||
/** Set TTY to be under raw mode. */ | ||
setRaw(mode: boolean): void { | ||
if (this._isRaw === mode) { | ||
return; | ||
} | ||
if (mode) { | ||
this._restoreInfo = sendSync(dispatch.OP_SET_RAW, { | ||
rid: this.rid, | ||
raw: true | ||
}); | ||
this._isRaw = true; | ||
} else { | ||
sendSync(dispatch.OP_SET_RAW, { | ||
rid: this.rid, | ||
raw: false, | ||
...this._restoreInfo | ||
}); | ||
this._isRaw = false; | ||
} | ||
} | ||
} | ||
|
||
/** An instance of `TTYInput` for stdin. */ | ||
export const stdin = new TTYInput(0); | ||
/** An instance of `File` for stdout. */ | ||
export const stdout = new File(1); | ||
/** An instance of `File` for stderr. */ | ||
export const stderr = new File(2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters