🖨️ esc/pos implementation in gleam

fix: better naming

okk.moe 88e60dda 8abe1ded

verified
+18 -15
+18 -15
src/escpos/document.gleam
··· 59 59 Font(Font) 60 60 } 61 61 62 - type AST { 62 + type AbstractCommand { 63 63 Init 64 64 DoWrite(String) 65 65 DoLineFeed(Int) ··· 109 109 ) 110 110 } 111 111 112 - fn ensure_new_line(state: State, acc: List(AST)) -> #(List(AST), State) { 112 + fn ensure_new_line( 113 + state: State, 114 + acc: List(AbstractCommand), 115 + ) -> #(List(AbstractCommand), State) { 113 116 case state.new_line { 114 117 True -> #(acc, state) 115 118 False -> #([DoLineFeed(1), ..acc], State(..state, new_line: True)) ··· 291 294 } 292 295 } 293 296 294 - fn build_ast(commands: List(Command)) -> List(AST) { 297 + fn build_ast(commands: List(Command)) -> List(AbstractCommand) { 295 298 do_build_ast(commands, [Init], default_state()) 296 299 |> list.reverse 297 300 } 298 301 299 302 fn do_build_ast( 300 303 commands: List(Command), 301 - acc: List(AST), 304 + acc: List(AbstractCommand), 302 305 state: State, 303 - ) -> List(AST) { 306 + ) -> List(AbstractCommand) { 304 307 case commands { 305 308 [] -> acc 306 309 [cmd, ..rest] -> { ··· 361 364 fn revert_styles( 362 365 state: State, 363 366 nested_state: State, 364 - acc: List(AST), 365 - ) -> #(List(AST), State) { 367 + acc: List(AbstractCommand), 368 + ) -> #(List(AbstractCommand), State) { 366 369 let changes = 367 370 [ 368 371 changed(state.bold != nested_state.bold, SetBold(state.bold)), ··· 394 397 } 395 398 396 399 fn do_revert_styles( 397 - changes: List(AST), 398 - acc: List(AST), 400 + changes: List(AbstractCommand), 401 + acc: List(AbstractCommand), 399 402 state: State, 400 - ) -> #(List(AST), State) { 403 + ) -> #(List(AbstractCommand), State) { 401 404 case changes { 402 405 [] -> #(acc, state) 403 406 [style, ..rest] -> ··· 411 414 } 412 415 } 413 416 414 - fn changed(change: Bool, ast: AST) -> Option(AST) { 417 + fn changed(change: Bool, ast: AbstractCommand) -> Option(AbstractCommand) { 415 418 case change { 416 419 True -> Some(ast) 417 420 False -> None ··· 420 423 421 424 fn do_apply_modifiers( 422 425 modifiers: List(Modifier), 423 - acc: List(AST), 426 + acc: List(AbstractCommand), 424 427 state: State, 425 - ) -> #(List(AST), State) { 428 + ) -> #(List(AbstractCommand), State) { 426 429 case modifiers { 427 430 [] -> #(acc, state) 428 431 [mod, ..rest] -> { ··· 498 501 } 499 502 } 500 503 501 - fn compile_ast(ast: List(AST)) -> BitArray { 504 + fn compile_ast(ast: List(AbstractCommand)) -> BitArray { 502 505 do_compile_ast(ast, <<>>) 503 506 } 504 507 505 - fn do_compile_ast(ast: List(AST), acc: BitArray) -> BitArray { 508 + fn do_compile_ast(ast: List(AbstractCommand), acc: BitArray) -> BitArray { 506 509 case ast { 507 510 [] -> acc 508 511 [cmd, ..rest] ->