Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Add Terminal to NodeContext and BunContext (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
IMax153 authored Nov 17, 2023
1 parent d8e2234 commit 534cb34
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-crabs-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/platform-node": patch
---

add Terminal to NodeContext and BunContext
5 changes: 5 additions & 0 deletions .changeset/rare-badgers-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/platform-node": patch
---

fix bug where keypress could still be emit after terminal was quit
8 changes: 7 additions & 1 deletion packages/platform-bun/src/BunContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import * as Layer from "effect/Layer"
import * as CommandExecutor from "./CommandExecutor.js"
import * as FileSystem from "./FileSystem.js"
import * as Path from "./Path.js"
import * as Terminal from "./Terminal.js"

/**
* @since 1.0.0
* @category models
*/
export type BunContext = CommandExecutor.CommandExecutor | FileSystem.FileSystem | Path.Path
export type BunContext =
| CommandExecutor.CommandExecutor
| FileSystem.FileSystem
| Path.Path
| Terminal.Terminal

/**
* @since 1.0.0
Expand All @@ -20,5 +25,6 @@ export type BunContext = CommandExecutor.CommandExecutor | FileSystem.FileSystem
export const layer: Layer.Layer<never, never, BunContext> = pipe(
FileSystem.layer,
Layer.merge(Path.layer),
Layer.merge(Terminal.layer),
Layer.merge(Layer.provideMerge(FileSystem.layer, CommandExecutor.layer))
)
8 changes: 7 additions & 1 deletion packages/platform-node/src/NodeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import * as Layer from "effect/Layer"
import * as CommandExecutor from "./CommandExecutor.js"
import * as FileSystem from "./FileSystem.js"
import * as Path from "./Path.js"
import * as Terminal from "./Terminal.js"

/**
* @since 1.0.0
* @category models
*/
export type NodeContext = CommandExecutor.CommandExecutor | FileSystem.FileSystem | Path.Path
export type NodeContext =
| CommandExecutor.CommandExecutor
| FileSystem.FileSystem
| Path.Path
| Terminal.Terminal

/**
* @since 1.0.0
Expand All @@ -20,5 +25,6 @@ export type NodeContext = CommandExecutor.CommandExecutor | FileSystem.FileSyste
export const layer: Layer.Layer<never, never, NodeContext> = pipe(
FileSystem.layer,
Layer.merge(Path.layer),
Layer.merge(Terminal.layer),
Layer.merge(Layer.provideMerge(FileSystem.layer, CommandExecutor.layer))
)
6 changes: 4 additions & 2 deletions packages/platform-node/src/internal/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ export const make = (
}
if (shouldQuit(userInput)) {
resume(Effect.fail(new Terminal.QuitException()))
} else {
resume(Effect.succeed(userInput))
}
resume(Effect.succeed(userInput))
}
input.once("keypress", handleKeypress)
return Effect.sync(() => {
Expand All @@ -74,7 +75,8 @@ export const make = (
)

return Terminal.Terminal.of({
columns: output.columns,
// The columns property can be undefined if stdout was redirected
columns: output.columns || 0,
readInput,
display
})
Expand Down

0 comments on commit 534cb34

Please sign in to comment.