Skip to content

Errors when using README example for custom printer #71

@ldoo22

Description

@ldoo22

Describe the problem

Using the code provided in the current README documentation for a custom printer results in errors.

Steps to reproduce the problem

Following the README’s custom printer example, such as creating a Ruby project that uses tty-command and pasting the code exactly as shown, will cause an error.

Code example provided in the README

CustomPrinter < TTY::Command::Printers::Abstract
  def write(cmd, message)
    puts cmd.to_command + message
  end
end

cmd = TTY::Command.new(printer: CustomPrinter)
# .../tty-command/README.md:609-617

Actual behaviour

Issues:

  • The first error occurs because the provided snippet is not valid Ruby syntax. It is missing the class keyword before CustomPrinter.
  • After fixing that, invoking cmd produces an error (wrong number of arguments (given 1, expected 2)) because methods like print_command_start, which are defined in the abstract printer, call write with a single argument, causing a mismatch with the expected method signature.

Expected behaviour

The code in the documentation should work as provided, without raising any errors. It would also be helpful for the Abstract printer class to more closely match the structure and method signatures of the other printer classes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions