| 140 | }) |
| 141 | |
| 142 | export class CUPS extends Context.Service<CUPS>()("effect-app/CUPS", { |
| 143 | make: Effect.gen(function*() { |
| 144 | const config = yield* CUPSConfig |
| 145 | const serverUrl = Option.getOrUndefined(config.server) |
| 146 | function print(buffer: ArrayBuffer, printerId: PrinterId, ...options: string[]) { |
| 147 | const _print = printBuffer({ |
| 148 | id: printerId, |
| 149 | url: serverUrl |
| 150 | }, options) |
| 151 | return _print(buffer) |
| 152 | } |
| 153 | return { |
| 154 | print, |
| 155 | printFile: (filePath: string, printerId: PrinterId, ...options: string[]) => |
| 156 | printFile({ |
| 157 | id: printerId, |
| 158 | url: serverUrl |
| 159 | }, options)(filePath), |
| 160 | getAvailablePrinters: getAvailablePrinters(serverUrl?.host) |
| 161 | } |
| 162 | }) |
| 163 | }) { |
| 164 | static readonly Fake = Layer.effect( |
| 165 | this, |
| 166 | Effect.sync(() => |
| 167 | CUPS.of({ |
| 168 | print: (buffer: ArrayBuffer, printerId: PrinterId, ...options: string[]) => |
| 169 | InfraLogger |
| 170 | .logInfo("Printing to fake printer") |
| 171 | .pipe( |
| 172 | Effect.andThen(Effect.sync(() => ({ stdout: "fake", stderr: "" }))), |
| 173 | Effect |
| 174 | .annotateLogs({ |
| 175 | printerId, |
| 176 | "options": pretty(options), |
| 177 | "bufferSize": buffer.byteLength.toString() |
| 178 | }) |
| 179 | ), |
| 180 | printFile: (filePath: string, printerId: PrinterId, ...options: string[]) => |
| 181 | InfraLogger |
| 182 | .logInfo("Printing to fake printer") |
| 183 | .pipe( |
| 184 | Effect.andThen(Effect.sync(() => ({ stdout: "fake", stderr: "" }))), |
| 185 | Effect |
| 186 | .annotateLogs({ |
| 187 | printerId, |
| 188 | filePath, |
| 189 | "options": pretty(options) |
| 190 | }) |
| 191 | ), |
| 192 | getAvailablePrinters: Effect.sync(() => []) |
| 193 | }) |
| 194 | ) |
| 195 | ) |
| 196 | } |