@effect-tui/react 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/jsx-runtime.d.ts +4 -1
  2. package/dist/jsx-runtime.d.ts.map +1 -1
  3. package/dist/src/components/ListView.d.ts +9 -1
  4. package/dist/src/components/ListView.d.ts.map +1 -1
  5. package/dist/src/components/ListView.js +46 -11
  6. package/dist/src/components/ListView.js.map +1 -1
  7. package/dist/src/hooks/use-scroll.d.ts +9 -1
  8. package/dist/src/hooks/use-scroll.d.ts.map +1 -1
  9. package/dist/src/hooks/use-scroll.js +11 -5
  10. package/dist/src/hooks/use-scroll.js.map +1 -1
  11. package/dist/src/hosts/index.d.ts +1 -1
  12. package/dist/src/hosts/index.d.ts.map +1 -1
  13. package/dist/src/hosts/index.js +3 -2
  14. package/dist/src/hosts/index.js.map +1 -1
  15. package/dist/src/hosts/scroll.d.ts +5 -0
  16. package/dist/src/hosts/scroll.d.ts.map +1 -1
  17. package/dist/src/hosts/scroll.js +10 -0
  18. package/dist/src/hosts/scroll.js.map +1 -1
  19. package/dist/src/hosts/text.d.ts +48 -1
  20. package/dist/src/hosts/text.d.ts.map +1 -1
  21. package/dist/src/hosts/text.js +200 -5
  22. package/dist/src/hosts/text.js.map +1 -1
  23. package/dist/src/index.d.ts +1 -1
  24. package/dist/src/index.d.ts.map +1 -1
  25. package/dist/src/remote/Procedures.d.ts +11 -0
  26. package/dist/src/remote/Procedures.d.ts.map +1 -1
  27. package/dist/src/remote/Procedures.js +17 -1
  28. package/dist/src/remote/Procedures.js.map +1 -1
  29. package/dist/src/remote/Router.d.ts +12 -1
  30. package/dist/src/remote/Router.d.ts.map +1 -1
  31. package/dist/src/remote/Router.js +1 -0
  32. package/dist/src/remote/Router.js.map +1 -1
  33. package/dist/src/remote/index.d.ts.map +1 -1
  34. package/dist/src/remote/index.js +14 -0
  35. package/dist/src/remote/index.js.map +1 -1
  36. package/dist/src/test/render-tui.d.ts +1 -1
  37. package/dist/src/test/render-tui.d.ts.map +1 -1
  38. package/dist/src/test/render-tui.js +20 -2
  39. package/dist/src/test/render-tui.js.map +1 -1
  40. package/dist/tsconfig.tsbuildinfo +1 -1
  41. package/jsx-runtime.ts +2 -1
  42. package/package.json +2 -2
  43. package/src/components/ListView.tsx +67 -13
  44. package/src/hooks/use-scroll.ts +21 -5
  45. package/src/hosts/index.ts +13 -2
  46. package/src/hosts/scroll.ts +13 -0
  47. package/src/hosts/text.ts +242 -5
  48. package/src/index.ts +1 -1
  49. package/src/remote/Procedures.ts +19 -1
  50. package/src/remote/Router.ts +14 -1
  51. package/src/remote/index.ts +15 -1
  52. package/src/test/render-tui.ts +21 -3
@@ -4,6 +4,15 @@ import type { KeyMsg } from "@effect-tui/core"
4
4
  import { Context, Effect, type Layer } from "effect"
5
5
  import { TuiRpcs } from "./Procedures.js"
6
6
 
7
+ // Log entry result type
8
+ export interface LogEntryResult {
9
+ timestamp: string
10
+ level: string
11
+ message: string
12
+ file?: string
13
+ line?: number
14
+ }
15
+
7
16
  // Service interface for the TUI session
8
17
  export interface TuiSessionImpl {
9
18
  readonly getScreenshot: () => string
@@ -17,6 +26,7 @@ export interface TuiSessionImpl {
17
26
  entryPath?: string
18
27
  name?: string
19
28
  }
29
+ readonly getLogEntries: (limit?: number) => { entries: LogEntryResult[]; total: number }
20
30
  }
21
31
 
22
32
  export class TuiSession extends Context.Tag("TuiSession")<TuiSession, TuiSessionImpl>() {}
@@ -27,7 +37,8 @@ export const HandlersLive: Layer.Layer<
27
37
  | Rpc.Handler<"SendKey">
28
38
  | Rpc.Handler<"Paste">
29
39
  | Rpc.Handler<"Resize">
30
- | Rpc.Handler<"Info">,
40
+ | Rpc.Handler<"Info">
41
+ | Rpc.Handler<"GetLogs">,
31
42
  never,
32
43
  TuiSession
33
44
  > = TuiRpcs.toLayer(
@@ -55,6 +66,8 @@ export const HandlersLive: Layer.Layer<
55
66
  Resize: ({ width, height }) => Effect.sync(() => session.dispatchResize(width, height)),
56
67
 
57
68
  Info: () => Effect.sync(() => session.getInfo()),
69
+
70
+ GetLogs: ({ limit }) => Effect.sync(() => session.getLogEntries(limit)),
58
71
  }
59
72
  }),
60
73
  )
@@ -13,8 +13,9 @@ export { getSocketPath, makeServerLayer } from "./Server.js"
13
13
 
14
14
  import * as fs from "node:fs"
15
15
  import { Effect, Exit, Layer, Scope } from "effect"
16
+ import { getConsoleCapture } from "../console/ConsoleCapture.js"
16
17
  import type { TuiRenderer } from "../renderer-types.js"
17
- import type { TuiSessionImpl } from "./Router.js"
18
+ import type { LogEntryResult, TuiSessionImpl } from "./Router.js"
18
19
  import { getSocketPath, makeServerLayer } from "./Server.js"
19
20
 
20
21
  export interface EnableRemoteOptions {
@@ -76,6 +77,19 @@ export function enableRemote(renderer: TuiRenderer, options?: EnableRemoteOption
76
77
  entryPath: opts.entryPath,
77
78
  name,
78
79
  }),
80
+ getLogEntries: (limit?: number): { entries: LogEntryResult[]; total: number } => {
81
+ const all = getConsoleCapture().getEntries()
82
+ const total = all.length
83
+ const sliced = limit ? all.slice(-limit) : all
84
+ const entries: LogEntryResult[] = sliced.map((e) => ({
85
+ timestamp: e.timestamp.toISOString(),
86
+ level: e.level,
87
+ message: e.message,
88
+ file: e.location?.file,
89
+ line: e.location?.line,
90
+ }))
91
+ return { entries, total }
92
+ },
79
93
  }
80
94
 
81
95
  // Build and run the server layer
@@ -1,5 +1,5 @@
1
1
  import type { KeyMsg } from "@effect-tui/core"
2
- import type { ReactElement } from "react"
2
+ import React, { type ReactElement, useState } from "react"
3
3
  import { flushPassiveEffects, flushSync } from "../reconciler/host-config.js"
4
4
  import { createRenderer, createRoot } from "../renderer.js"
5
5
  import { getVisibleLines, MockStdin, MockStdout, stripAnsi } from "./mock-streams.js"
@@ -69,7 +69,15 @@ export function renderTUI(element: ReactElement, options?: RenderTUIOptions): Re
69
69
  })
70
70
 
71
71
  const root = createRoot(renderer)
72
- root.render(element, true) // sync mode
72
+ let bump: (() => void) | null = null
73
+ const Harness = ({ children }: { children: ReactElement }) => {
74
+ const [tick, setTick] = useState(0)
75
+ bump = () => setTick((value) => value + 1)
76
+ return React.cloneElement(children, { __renderTick: tick } as Record<string, unknown>)
77
+ }
78
+
79
+ const harnessed = React.createElement(Harness, null, element)
80
+ root.render(harnessed, true) // sync mode
73
81
 
74
82
  // Flush effects
75
83
  flushPassiveEffects()
@@ -79,12 +87,22 @@ export function renderTUI(element: ReactElement, options?: RenderTUIOptions): Re
79
87
 
80
88
  const flush = () => {
81
89
  // Flush React updates synchronously
82
- flushSync(() => {})
90
+ flushSync(() => {
91
+ bump?.()
92
+ })
83
93
  flushPassiveEffects()
84
94
  // Clear buffer before re-render to get clean frame
85
95
  stdout.clear()
86
96
  renderer.requestRender()
87
97
  renderer.flush()
98
+ // Flush updates scheduled during layout (e.g., viewport/content size callbacks)
99
+ flushSync(() => {
100
+ bump?.()
101
+ })
102
+ flushPassiveEffects()
103
+ stdout.clear()
104
+ renderer.requestRender()
105
+ renderer.flush()
88
106
  }
89
107
 
90
108
  return {