Class: Console::Terminal::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/console/terminal/text.rb

Direct Known Subclasses

XTerm

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Text

Returns a new instance of Text.



29
30
31
32
# File 'lib/console/terminal/text.rb', line 29

def initialize(output)
	@output = output
	@styles = {reset: self.reset}
end

Instance Method Details

#[](key) ⇒ Object



34
35
36
# File 'lib/console/terminal/text.rb', line 34

def [] key
	@styles[key]
end

#[]=(key, value) ⇒ Object



38
39
40
# File 'lib/console/terminal/text.rb', line 38

def []= key, value
	@styles[key] = value
end

#colors?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/console/terminal/text.rb', line 42

def colors?
	false
end

Print out the given arguments. When the argument is a symbol, look up the style and inject it into the output stream. When the argument is a proc/lambda, call it with self as the argument. When the argument is anything else, write it directly to the output.



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/console/terminal/text.rb', line 76

def print(*arguments)
	arguments.each do |argument|
		case argument
		when Symbol
			@output.write(self[argument])
		when Proc
			argument.call(self)
		else
			@output.write(argument)
		end
	end
end

Print out the arguments as per #print, followed by the reset sequence and a newline.



90
91
92
93
# File 'lib/console/terminal/text.rb', line 90

def print_line(*arguments)
	print(*arguments)
	@output.puts(self.reset)
end

#puts(*arguments, style: nil) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/console/terminal/text.rb', line 62

def puts(*arguments, style: nil)
	if style and prefix = self[style]
		@output.write(prefix)
		@output.puts(*arguments)
		@output.write(self.reset)
	else
		@output.puts(*arguments)
	end
end

#resetObject



49
50
# File 'lib/console/terminal/text.rb', line 49

def reset
end

#style(foreground, background = nil, *attributes) ⇒ Object



46
47
# File 'lib/console/terminal/text.rb', line 46

def style(foreground, background = nil, *attributes)
end

#write(*arguments, style: nil) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/console/terminal/text.rb', line 52

def write(*arguments, style: nil)
	if style and prefix = self[style]
		@output.write(prefix)
		@output.write(*arguments)
		@output.write(self.reset)
	else
		@output.write(*arguments)
	end
end