lib/colsole.rb
Ruby dynamically invokes a method with sendANSI erase-line/erase-screen sequence
SHA-256233051b8e45616f87be0195431d897fe066084b3933581c78760a79c1841ccf2
MaleculeH₂(DbU)
Evidence
1require 'io/console'
2
3# Utility functions for colorful console applications.
4module Colsole
5 ANSI_COLORS = {
6 'n' => '', # no color …
⋯5 lines
26 # Output a string with optional color markers to stdout.
27 # If text is ended with a white space, you can call again with replace: true
28 # to replace that line
29 def say(text, replace: false)
30 internal_say text, $stdout, replace: replace
31 end
32
33 …
45:6… stream.tty?
46 end
47 end
48
49 # Returns true if the command exists in the path
50 def command_exist?(command)
51 ENV['PATH'].split(File::PATH_SEPAR …
124:5… d
125
126 def internal_say(text, stream, replace: false)
127 text = "\033[2K\r#{text}" if replace && terminal?
128 last = text[-1, 1]
129 handler = use_colors?(stream) ? :colorize : :strip_colors
130
131 if …
131:10… rminal? && ((last == ' ') || (last == '\t'))
132 stream.print send(handler, text)
133 else
134 stream.print send(handler, "#{text}\n")
⋯4 lines