console.cr v0.1.0
console.cr
Easy to use output control allowing redirection and buffering.
Installation
Add this to your application's shard.yml:
dependencies:
  console:
    github: chris-huxtable/console.cr
Usage
require "console"
Printing to the Console:
Console.print("This will print without a newline")
Console.line("This will print with a newline")
Console.line("This will", "print separate strings, with", "a newline", separator: ' ')
Console.words("This", "will", "print", "words", "or strings", "separated by single spaces", "and without a newline")
Console.print("All also feature", separator: "with different defaults", terminator: '.')
Printing lists to the Console:
Console.item("This is a list label")
#=> " - This is a list label\n"
Console.item("This is a list label", "with extras", justify: 30)
#=> " - This is a list label       with extras\n"
Console.item("This is a red list label", "with extras", justify: 30, style: Console::Style::Red)
#=> " - This is a red list label   with extras\n"
Console.status("This is a list label")
#=> " - This is a list label\n"
Console.status("This is a list label", "with a status", justify: 30)
#=> " - This is a list label       with a status\n"
Console.status("This is a red list label", "with a red status", justify: 30, style: Console::Style::Red)
#=> " - This is a list label       with a red status\n"
Printing to a buffer:
buffer = Console.buffer() {
	Console.line("This will be printed to the buffer")
	Console.line("Which will return a string")
	Console.repeat('=', 50)
	Console.newline()
	Console.line("You could then print it to the actual console if needed")
}
Console << buffer if something.went_wrong?
Notes
- 'Monkey patches' IO::Memory.truncate
- Currently not forkor thread/fiber safe.
Contributing
- Fork it (https://github.com/chris-huxtable/console.cr/fork)
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- Chris Huxtable - creator, maintainer
Repository
  console.cr
Owner
  
  Statistic
  - 2
- 0
- 0
- 1
- 0
- almost 5 years ago
- July 17, 2018
License
  ISC License
Links
  
  Synced at
  Thu, 30 Oct 2025 17:50:32 GMT
Languages