Class: GithubCLI::Terminal
- Inherits:
-
Object
- Object
- GithubCLI::Terminal
- Defined in:
- lib/github_cli/terminal.rb
Overview
Responsible for display and size detection.
Constant Summary collapse
- DEFAULT_WIDTH =
80
- DEFAULT_HEIGHT =
40
Class Method Summary collapse
- .build_command_output(cmd, indent = 3) ⇒ Object
- .default_width ⇒ Object
- .find_commands(pattern = nil) ⇒ Object
- .line(text) ⇒ Object
- .newline ⇒ Object
- .paged_output ⇒ Object
- .pager ⇒ Object
- .print_command_not_found(cmd) ⇒ Object
- .print_commands(pattern = nil) ⇒ Object
- .print_config(pattern = nil) ⇒ Object
- .print_usage(flags, command) ⇒ Object
- .width ⇒ Object
Class Method Details
.build_command_output(cmd, indent = 3) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/github_cli/terminal.rb', line 48 def build_command_output(cmd, indent=3) prefix = " " * indent if cmd.namespace.empty? ["#{prefix + cmd.usage}", cmd.desc] else ["#{prefix + cmd.namespace} #{cmd.usage}", cmd.desc] end end |
.default_width ⇒ Object
12 13 14 |
# File 'lib/github_cli/terminal.rb', line 12 def default_width DEFAULT_WIDTH end |
.find_commands(pattern = nil) ⇒ Object
42 43 44 45 46 |
# File 'lib/github_cli/terminal.rb', line 42 def find_commands(pattern=nil) Command.all.select do |cmd| cmd if pattern && cmd.namespace =~ pattern end end |
.line(text) ⇒ Object
20 21 22 |
# File 'lib/github_cli/terminal.rb', line 20 def line(text) $stdout.print text end |
.newline ⇒ Object
24 25 26 27 |
# File 'lib/github_cli/terminal.rb', line 24 def newline $stdout.print "\n" nil end |
.paged_output ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/github_cli/terminal.rb', line 29 def paged_output if Pager.enabled? pager.page true else false end end |
.pager ⇒ Object
38 39 40 |
# File 'lib/github_cli/terminal.rb', line 38 def pager @pager ||= Pager.new end |
.print_command_not_found(cmd) ⇒ Object
70 71 72 73 |
# File 'lib/github_cli/terminal.rb', line 70 def print_command_not_found(cmd) exec_name = GithubCLI.executable_name GithubCLI.ui.info "#{exec_name}: '#{cmd}' is not a #{exec_name} command. See '#{exec_name} --help'." end |
.print_commands(pattern = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/github_cli/terminal.rb', line 57 def print_commands(pattern=nil) Terminal.line "\n" + GithubCLI.program_name + "\n\n" commands = find_commands(pattern).map { |cmd| build_command_output cmd } if !commands.empty? GithubCLI.ui.info "Commands:" GithubCLI.ui.print_table commands, :truncate => true else print_command_not_found pattern.to_s.gsub(/\W|/, '')[3..-1] end end |
.print_config(pattern = nil) ⇒ Object
85 86 87 88 |
# File 'lib/github_cli/terminal.rb', line 85 def print_config(pattern=nil) GithubCLI.ui.info "Configuration options:" GithubCLI.ui.print_table GithubCLI.config.pretty(pattern) end |
.print_usage(flags, command) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/github_cli/terminal.rb', line 75 def print_usage(flags, command) GithubCLI.ui.info <<-TEXT #{GithubCLI.program_name} Usage: #{GithubCLI.executable_name} #{GithubCLI::Command::Usage.new(command, flags).format_usage } TEXT end |