planter.rb: Improve editor and options
- Editor: Enable trunk editing - General: Add value for Gardner debug mode - General: Improve visability of option chosen - General: Improve display
This commit is contained in:
parent
78f9837b5a
commit
1af5c9a53c
1 changed files with 28 additions and 12 deletions
|
@ -11,7 +11,17 @@ module Planter
|
||||||
|
|
||||||
# Edit the trunk of the tree
|
# Edit the trunk of the tree
|
||||||
def edit_trunk
|
def edit_trunk
|
||||||
puts "Edit trunk"
|
puts "Current Trunk:\n"
|
||||||
|
Gardner.display_trunk(@trunk, true)
|
||||||
|
print "[ =EDITING= ](CTRL-C to abort)> "
|
||||||
|
STDOUT.flush
|
||||||
|
begin
|
||||||
|
new_trunk = STDIN.gets.to_s
|
||||||
|
rescue Interrupt
|
||||||
|
puts "\n**Aborting edit**\n\n"
|
||||||
|
new_trunk = @trunk["trunk"]
|
||||||
|
end
|
||||||
|
@trunk["trunk"] = new_trunk
|
||||||
end
|
end
|
||||||
|
|
||||||
# Edit a branch on the tree
|
# Edit a branch on the tree
|
||||||
|
@ -64,7 +74,7 @@ module Planter
|
||||||
def dig(branch_no)
|
def dig(branch_no)
|
||||||
branch = @plot.branches[branch_no]
|
branch = @plot.branches[branch_no]
|
||||||
|
|
||||||
Gardner.display_trunk(@plot.trunk)
|
Gardner.display_trunk(@plot.trunk, true)
|
||||||
Gardner.display_branch(branch, branch_no, true)
|
Gardner.display_branch(branch, branch_no, true)
|
||||||
|
|
||||||
response = get_response(branch)
|
response = get_response(branch)
|
||||||
|
@ -102,28 +112,38 @@ module Planter
|
||||||
# @param branch_no [Integer] The currently-displayed branch
|
# @param branch_no [Integer] The currently-displayed branch
|
||||||
# @return [Integer] the branch to display
|
# @return [Integer] the branch to display
|
||||||
def parse_response(response, branch_no)
|
def parse_response(response, branch_no)
|
||||||
return response.to_i if response.to_i >= 1
|
10.times { print "*" }
|
||||||
|
print "\n(Your choice: "
|
||||||
|
|
||||||
|
if response.to_i >= 1
|
||||||
|
print "Change to branch #{response.to_i})\n\n"
|
||||||
|
return response.to_i
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
case response.to_s.downcase
|
case response.to_s.downcase
|
||||||
when "t"
|
when "t"
|
||||||
|
print "Edit the trunk.)\n\n"
|
||||||
@plot.edit_trunk
|
@plot.edit_trunk
|
||||||
return branch_no
|
return branch_no
|
||||||
when "a"
|
when "a"
|
||||||
puts "Add new branch"
|
print "Add a new branch.)\n\n"
|
||||||
return branch_no
|
return branch_no
|
||||||
when "b"
|
when "b"
|
||||||
|
print "Edit the current branch.)\n\n"
|
||||||
@plot.edit_branch(branch_no)
|
@plot.edit_branch(branch_no)
|
||||||
return branch_no
|
return branch_no
|
||||||
when "x"
|
when "x"
|
||||||
puts "Delete current branch"
|
print "Delete the current branch.)\n\n"
|
||||||
return branch_no
|
return branch_no
|
||||||
when "l"
|
when "l"
|
||||||
puts "Edit leaves"
|
print "Edit leaves of current branch.)\n\n"
|
||||||
return branch_no
|
return branch_no
|
||||||
when "s"
|
when "s"
|
||||||
puts "Save changes"
|
print "Save changes.)\n\n"
|
||||||
return branch_no
|
return branch_no
|
||||||
when "q"
|
when "q"
|
||||||
|
print "Quit without saving.)\n\n"
|
||||||
print "Unsaved changes will be lost. Still quit? [y/n]> "
|
print "Unsaved changes will be lost. Still quit? [y/n]> "
|
||||||
verify = STDIN.gets.chomp.to_s.downcase
|
verify = STDIN.gets.chomp.to_s.downcase
|
||||||
|
|
||||||
|
@ -131,14 +151,11 @@ module Planter
|
||||||
|
|
||||||
return branch_no
|
return branch_no
|
||||||
else
|
else
|
||||||
puts "Something else!"
|
print "Unknown option. Returning to current branch.)\n\n"
|
||||||
return branch_no
|
return branch_no
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
@ -169,7 +186,6 @@ Process:
|
||||||
- Example prompt:
|
- Example prompt:
|
||||||
[ 0-5,T,A,B,X,L,S,Q ]>
|
[ 0-5,T,A,B,X,L,S,Q ]>
|
||||||
- Leaf prompt:
|
- Leaf prompt:
|
||||||
[ Leaves:
|
|
||||||
|
|
||||||
Details:
|
Details:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue