Skip to content

Commit

Permalink
Set default streams in StdinContext, StdoutContext and `StderrCon…
Browse files Browse the repository at this point in the history
…text`
  • Loading branch information
vadimdemedes committed Mar 1, 2023
1 parent f968aa4 commit ceb00f1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/components/StderrContext.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import process from 'node:process';
import {createContext} from 'react';

export type Props = {
/**
* Stderr stream passed to `render()` in `options.stderr` or `process.stderr` by default.
*/
readonly stderr?: NodeJS.WriteStream;
readonly stderr: NodeJS.WriteStream;

/**
* Write any string to stderr, while preserving Ink's output.
Expand All @@ -19,7 +20,7 @@ export type Props = {
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
const StderrContext = createContext<Props>({
stderr: undefined,
stderr: process.stderr,
write() {}
});

Expand Down
5 changes: 3 additions & 2 deletions src/components/StdinContext.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import process from 'node:process';
import {createContext} from 'react';

export type Props = {
/**
* Stdin stream passed to `render()` in `options.stdin` or `process.stdin` by default. Useful if your app needs to handle user input.
*/
readonly stdin?: NodeJS.ReadStream;
readonly stdin: NodeJS.ReadStream;

/**
* Ink exposes this function via own `<StdinContext>` to be able to handle Ctrl+C, that's why you should use Ink's `setRawMode` instead of `process.stdin.setRawMode`.
Expand All @@ -25,7 +26,7 @@ export type Props = {
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
const StdinContext = createContext<Props>({
stdin: undefined,
stdin: process.stdin,
setRawMode() {},
isRawModeSupported: false,
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down
5 changes: 3 additions & 2 deletions src/components/StdoutContext.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import process from 'node:process';
import {createContext} from 'react';

export type Props = {
/**
* Stdout stream passed to `render()` in `options.stdout` or `process.stdout` by default.
*/
readonly stdout?: NodeJS.WriteStream;
readonly stdout: NodeJS.WriteStream;

/**
* Write any string to stdout, while preserving Ink's output.
Expand All @@ -19,7 +20,7 @@ export type Props = {
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
const StdoutContext = createContext<Props>({
stdout: undefined,
stdout: process.stdout,
write() {}
});

Expand Down

0 comments on commit ceb00f1

Please sign in to comment.