Skip to content

Commit 118e7a4

Browse files
authored
Add rows and isTTY to Terminal (#5977)
1 parent 4725a7e commit 118e7a4

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

.changeset/large-cobras-jump.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@effect/platform-node-shared": patch
3+
"@effect/platform": patch
4+
"@effect/platform-bun": patch
5+
"@effect/platform-node": patch
6+
---
7+
8+
Added `rows` and `isTTY` properties to `Terminal`

packages/cli/test/services/MockTerminal.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export const make = Effect.gen(function*() {
6464

6565
return MockTerminal.of({
6666
columns: Effect.succeed(80),
67+
rows: Effect.succeed(24),
68+
isTTY: Effect.succeed(true),
6769
display,
6870
readInput,
6971
readLine: Effect.succeed(""),

packages/platform-node-shared/src/internal/terminal.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export const make = Effect.fnUntraced(function*(
4141
})
4242

4343
const columns = Effect.sync(() => stdout.columns ?? 0)
44+
const rows = Effect.sync(() => stdout.rows ?? 0)
45+
const isTTY = Effect.sync(() => Boolean(stdout.isTTY))
4446

4547
const readInput = Effect.gen(function*() {
4648
yield* RcRef.get(rlRef)
@@ -90,6 +92,8 @@ export const make = Effect.fnUntraced(function*(
9092

9193
return Terminal.Terminal.of({
9294
columns,
95+
rows,
96+
isTTY,
9397
readInput,
9498
readLine,
9599
display
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as NodeTerminal from "@effect/platform-node-shared/NodeTerminal"
2+
import * as Terminal from "@effect/platform/Terminal"
3+
import { describe, expect, it } from "@effect/vitest"
4+
import * as Effect from "effect/Effect"
5+
6+
const runPromise = <E, A>(self: Effect.Effect<A, E, Terminal.Terminal>) =>
7+
Effect.runPromise(
8+
Effect.provide(self, NodeTerminal.layer)
9+
)
10+
11+
describe("Terminal", () => {
12+
it("columns", () =>
13+
runPromise(Effect.gen(function*() {
14+
const terminal = yield* Terminal.Terminal
15+
const columns = yield* terminal.columns
16+
expect(typeof columns).toEqual("number")
17+
})))
18+
19+
it("rows", () =>
20+
runPromise(Effect.gen(function*() {
21+
const terminal = yield* Terminal.Terminal
22+
const rows = yield* terminal.rows
23+
expect(typeof rows).toEqual("number")
24+
})))
25+
26+
it("isTTY", () =>
27+
runPromise(Effect.gen(function*() {
28+
const terminal = yield* Terminal.Terminal
29+
const isTTY = yield* terminal.isTTY
30+
expect(typeof isTTY).toEqual("boolean")
31+
})))
32+
})

packages/platform/src/Terminal.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ export interface Terminal {
2222
* The number of columns available on the platform's terminal interface.
2323
*/
2424
readonly columns: Effect<number>
25+
/**
26+
* The number of rows available on the platform's terminal interface.
27+
*/
28+
readonly rows: Effect<number>
29+
/**
30+
* Determines if the current terminal interface is interactive.
31+
*/
32+
readonly isTTY: Effect<boolean>
2533
/**
2634
* Reads input events from the default standard input.
2735
*/

0 commit comments

Comments
 (0)