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



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

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

#choose_issueObject



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

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


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/hustle_and_flow/io/shell.rb', line 44

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


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/hustle_and_flow/io/shell.rb', line 61

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


39
40
41
42
# File 'lib/hustle_and_flow/io/shell.rb', line 39

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



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/hustle_and_flow/io/shell.rb', line 82

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)


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

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

#reopen_issue?(issue) ⇒ Boolean

Returns:

  • (Boolean)


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

def reopen_issue?(issue)
  if issue.closed?
    yes?("This #{issue.class.name} is currenly closed. Would you like to reopen it?")
  end
end