Class: HustleAndFlow::Io::Shell

Inherits:
Thor::Shell::Color
  • Object
show all
Defined in:
lib/hustle_and_flow/io/shell.rb

Instance Method Summary collapse

Instance Method Details

#choose_branchObject



28
29
30
31
# File 'lib/hustle_and_flow/io/shell.rb', line 28

def choose_branch
  stdout.puts
  ask 'Enter the number of the branch you would like to work on:'
end

#choose_issueObject



22
23
24
25
26
# File 'lib/hustle_and_flow/io/shell.rb', line 22

def choose_issue
  stdout.puts

  ask 'Enter the number of the issue you would like to work on:'
end

#correct_issue?(issue) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
# File 'lib/hustle_and_flow/io/shell.rb', line 7

def correct_issue?(issue)
  if issue.new?
    Kernel.system("open #{issue.url}")
  else
    stdout.puts
    print_issue Formatters::IssueDetailFormatter.new(issue).to_hash

    yes?('Does this issue look correct?')
  end
end


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/hustle_and_flow/io/shell.rb', line 38

def print_formatted_table(data:, title: nil)
  data = data.map do |row|
    row.map do |column|
      set_color(column[:value], *column[:format])
    end
  end

  stdout.puts

  if title
    stdout.puts title.center(terminal_width)
    stdout.puts '-' * terminal_width
  end

  print_table(data, truncate: true)
end


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/hustle_and_flow/io/shell.rb', line 55

def print_issue(data)
  data[:header][:format].each do |format|
    stdout.print lookup_color(format)
  end

  print_wrapped(data[:header][:value])

  stdout.puts set_color('-' * terminal_width,   *data[:divider][:format])
  stdout.puts set_color(data[:contact][:value], *data[:contact][:format])

  data[:body][:format].each do |format|
    stdout.print lookup_color(format)
  end

  if data[:body][:value]
    stdout.puts
    print_wrapped(data[:body][:value])
  end
end


33
34
35
36
# File 'lib/hustle_and_flow/io/shell.rb', line 33

def print_new_branch_prompt(new_branch_name)
  stdout.puts
  say "Entering 'c' creates a new branch named '#{GREEN}#{new_branch_name}#{CLEAR}'"
end

To be removed once our PR lands



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/hustle_and_flow/io/shell.rb', line 76

def print_wrapped(message, options = {})
  indent = options[:indent] || 0
  width = 80
  paras = message.split("\n\n")

  paras.map! do |unwrapped|
    unwrapped.
    strip.
    gsub(/\n/, ' ').
    squeeze(' ').
    gsub(/.{1,#{width}}(?:\s|\Z)/) do
      ($& + 5.chr).
      gsub(/\n\005/, "\n").
      gsub(/\005/, "\n")
    end
  end

  paras.each do |para|
    para.split("\n").each do |line|
      stdout.puts line.insert(0, ' ' * indent)
    end
    stdout.puts unless para == paras.last
  end
end

#reassign_issue?(from:) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/hustle_and_flow/io/shell.rb', line 18

def reassign_issue?(from:)
  yes?("Do you want to reassign this issue from #{from} to yourself?")
end