From 7b1b0541c16aaa7bbfbd2f9107d8e1f253fc5488 Mon Sep 17 00:00:00 2001 From: Bill Niblock Date: Sun, 21 May 2017 15:56:12 -0400 Subject: [PATCH] planter.rb: Implement branch desc. editing --- lib/sapling/planter.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/sapling/planter.rb b/lib/sapling/planter.rb index e24f681..abaeb64 100644 --- a/lib/sapling/planter.rb +++ b/lib/sapling/planter.rb @@ -13,7 +13,7 @@ module Planter def edit_trunk puts "Current Trunk:\n" Gardner.display_trunk(@trunk, true) - print "[ =EDITING= ](CTRL-C to abort)> " + print "\n[ =EDITING= ](CTRL-C to abort)> " STDOUT.flush begin new_trunk = STDIN.gets.to_s @@ -27,8 +27,18 @@ module Planter # Edit a branch on the tree # # @param branch [Integer] The number of the branch to be edited. - def edit_branch(branch) - puts "Edit current branch" + def edit_branch(branch_no) + puts "Current Branch:\n" + Gardner.display_branch(@branches[branch_no], branch_no, true) + print "\n[ =EDITING= ](CTRL-C to abort)> " + STDOUT.flush + begin + new_branch = STDIN.gets.to_s + rescue Interrupt + puts "\n**Aborting edit**\n\n" + new_branch = @branches[branch_no]["desc"] + end + @branches[branch_no]["desc"] = new_branch end # Edit a leaf on a branch, grasshopper @@ -46,7 +56,7 @@ module Planter attr_writer :file def initialize(file) - @file=file + @file = file end # Establish and populate a new Plot (in-memory tree), then control the flow