From b71f415e2469552035223fd50793587da23638b7 Mon Sep 17 00:00:00 2001 From: kohrVid Date: Sun, 5 Jun 2016 01:35:56 +0100 Subject: [PATCH 1/4] Added the centre() method and made a few tweaks Have added the centre() method which can be used in conjunction with the indent() method or puts() to centre text. Have updated the indent method as I didn't understand how it worked and changed the default "spaces" value to 30 as I felt the 44 was too wide for the screen. I've also saved the README as a .md file as that's the format typically used in repos. --- README => README.md | 13 +++++++++---- cli_framework.rb | 33 +++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 16 deletions(-) rename README => README.md (88%) diff --git a/README b/README.md similarity index 88% rename from README rename to README.md index a249966..aef7700 100644 --- a/README +++ b/README.md @@ -1,4 +1,4 @@ -CLI FRAMEWORK +#CLI FRAMEWORK CLI Framework is a basic command line interface framework containing methods for layout. @@ -17,9 +17,14 @@ blank_indent() Indent line without line break Useful in conjunction with instant_gets (needs to be 1 space more than regular indent for this) ----- indent("Main Menu", 20) - ----- blanck_indent(21) + ----- blank_indent(21) ----- instant_gets +centre() + Centre content in a line. + Default screen width is 80 but this is optional + ---- centre("Main Menu", 80) + br() Line break Optional: pass in number of line breaks @@ -27,7 +32,7 @@ br() ----- br(2) ----- blanck_indent(21) ----- instant_gets - + hr() Horizontal rule Optional: pass in "=" for double line instead of single @@ -52,4 +57,4 @@ invalid_command() ----- else ----- invalid_command ----- end - ----- end \ No newline at end of file + ----- end diff --git a/cli_framework.rb b/cli_framework.rb index 8e66c50..5bf130f 100644 --- a/cli_framework.rb +++ b/cli_framework.rb @@ -7,12 +7,12 @@ def instant_gets end end -def indent(content, spaces = "43") - printf "%#{spaces}s %s\n", " ", "#{content}" +def indent(content, spaces = 30) + print "#{" "*spaces} #{content}" end -def blank_indent(spaces = "44") - printf "%#{spaces}s", " " +def blank_indent(spaces = 44) + puts "#{" "*spaces}\n" end def br(breaks = 1) @@ -21,20 +21,29 @@ def br(breaks = 1) end end +def centre(content, width = 80) + if content.length < width + indent_length = (width / 2.0) - (content.length / 2.0) + else + indent_length = width + end + " "*indent_length + content +end + def hr(type = "-") if type == "=" - indent("============================================================================================== ") + ("="*80)+"\n" else - indent("---------------------------------------------------------------------------------------------- ") + ("-"*80)+"\n" end end def invalid_command br - indent("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") - indent("!! !!") - indent("!! INVALID COMMAND! !!") - indent("!! !!") - indent("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") + indent("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",10) + indent("!! !!",10) + indent("!! INVALID COMMAND! !!", 10) + indent("!! !!", 10) + indent("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", 10) br(2) -end \ No newline at end of file +end From 2e161fd5861159a0f9dc13ec130314987c6496b7 Mon Sep 17 00:00:00 2001 From: kohrVid Date: Sun, 5 Jun 2016 01:55:50 +0100 Subject: [PATCH 2/4] Fixed the README file. --- README.md | 86 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index aef7700..5d10079 100644 --- a/README.md +++ b/README.md @@ -2,59 +2,71 @@ CLI Framework is a basic command line interface framework containing methods for layout. -instant_gets() +##instant_gets() Take one key as feedback without pressing Enter - ----- @menu_choice = instant_gets +```ruby +@menu_choice = instant_gets +``` -indent() +##indent() Indent content x number of spaces - Pass in your line of content as the first argument - Optional: pass in number of space to indent by - Change 43 to something else to change default - ----- indent("Main Menu", 20) + Pass in your line of content as the first argument and the number of spaces that you would like to indent by as your second argument. Note that the default number of spaces is set to 30 making the second argument optional. +```ruby +indent("Main Menu", 20) +``` -blank_indent() +##blank_indent() Indent line without line break Useful in conjunction with instant_gets (needs to be 1 space more than regular indent for this) - ----- indent("Main Menu", 20) - ----- blank_indent(21) - ----- instant_gets +```ruby +indent("Main Menu", 20) +blank_indent(21) +instant_gets +``` -centre() +##centre() Centre content in a line. Default screen width is 80 but this is optional - ---- centre("Main Menu", 80) +```ruby +centre("Main Menu", 80) +``` -br() +##br() Line break Optional: pass in number of line breaks - ----- indent("Main Menu", 20) - ----- br(2) - ----- blanck_indent(21) - ----- instant_gets +```ruby +indent("Main Menu", 20) +br(2) +blank_indent(21) +instant_gets +``` -hr() +##hr() Horizontal rule Optional: pass in "=" for double line instead of single - ----- hr(=) - ----- indent("Main Menu", 20) - ----- br(2) - ----- blanck_indent(21) - ----- instant_gets +```ruby +hr(=) +indent("Main Menu", 20) +br(2) +blank_indent(21) +instant_gets +``` -invalid_command() +##invalid_command() Invalid command warning Uses br and indent to format Useful for menus in conjunction with case statements/until loops - ----- until menu_choice = "q" - ----- case menu_choice - ----- when "1" - ----- some_action - ----- when "2" - ----- some_other_action - ----- when "q" - ----- menu_choice - ----- else - ----- invalid_command - ----- end - ----- end +```ruby + until menu_choice = "q" + case menu_choice + when "1" + some_action + when "2" + some_other_action + when "q" + menu_choice + else + invalid_command + end + end +``` From 46f41910a304fed1b4425987a9178d6df1c1b761 Mon Sep 17 00:00:00 2001 From: kohrVid Date: Sun, 5 Jun 2016 02:00:29 +0100 Subject: [PATCH 3/4] Fixed the blank_indent method and changed font sizes in the README file. --- README.md | 14 +++++++------- cli_framework.rb | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5d10079..caff06a 100644 --- a/README.md +++ b/README.md @@ -2,20 +2,20 @@ CLI Framework is a basic command line interface framework containing methods for layout. -##instant_gets() +###instant_gets() Take one key as feedback without pressing Enter ```ruby @menu_choice = instant_gets ``` -##indent() +###indent() Indent content x number of spaces Pass in your line of content as the first argument and the number of spaces that you would like to indent by as your second argument. Note that the default number of spaces is set to 30 making the second argument optional. ```ruby indent("Main Menu", 20) ``` -##blank_indent() +###blank_indent() Indent line without line break Useful in conjunction with instant_gets (needs to be 1 space more than regular indent for this) ```ruby @@ -24,14 +24,14 @@ blank_indent(21) instant_gets ``` -##centre() +###centre() Centre content in a line. Default screen width is 80 but this is optional ```ruby centre("Main Menu", 80) ``` -##br() +###br() Line break Optional: pass in number of line breaks ```ruby @@ -41,7 +41,7 @@ blank_indent(21) instant_gets ``` -##hr() +###hr() Horizontal rule Optional: pass in "=" for double line instead of single ```ruby @@ -52,7 +52,7 @@ blank_indent(21) instant_gets ``` -##invalid_command() +###invalid_command() Invalid command warning Uses br and indent to format Useful for menus in conjunction with case statements/until loops diff --git a/cli_framework.rb b/cli_framework.rb index 5bf130f..ce8f840 100644 --- a/cli_framework.rb +++ b/cli_framework.rb @@ -12,7 +12,7 @@ def indent(content, spaces = 30) end def blank_indent(spaces = 44) - puts "#{" "*spaces}\n" + print "#{" "*spaces}" end def br(breaks = 1) From 174ecb3fc6e4e0a7be6763f0b5ed444b6a6e7be5 Mon Sep 17 00:00:00 2001 From: kohrVid Date: Sun, 5 Jun 2016 02:15:48 +0100 Subject: [PATCH 4/4] Fixed the README again --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index caff06a..347007e 100644 --- a/README.md +++ b/README.md @@ -3,21 +3,21 @@ CLI Framework is a basic command line interface framework containing methods for layout. ###instant_gets() - Take one key as feedback without pressing Enter +* Take one key as feedback without pressing Enter ```ruby @menu_choice = instant_gets ``` ###indent() - Indent content x number of spaces - Pass in your line of content as the first argument and the number of spaces that you would like to indent by as your second argument. Note that the default number of spaces is set to 30 making the second argument optional. +* Indent content x number of spaces +* Pass in your line of content as the first argument and the number of spaces that you would like to indent by as your second argument. Note that the default number of spaces is set to 30 making the second argument optional. ```ruby indent("Main Menu", 20) ``` ###blank_indent() - Indent line without line break - Useful in conjunction with instant_gets (needs to be 1 space more than regular indent for this) +* Indent line without line break +* Useful in conjunction with instant_gets (needs to be 1 space more than regular indent for this) ```ruby indent("Main Menu", 20) blank_indent(21) @@ -25,15 +25,15 @@ instant_gets ``` ###centre() - Centre content in a line. - Default screen width is 80 but this is optional +* Centre content in a line. +* Default screen width is 80 but this is optional ```ruby centre("Main Menu", 80) ``` ###br() - Line break - Optional: pass in number of line breaks +* Line break +* Optional: pass in number of line breaks ```ruby indent("Main Menu", 20) br(2) @@ -42,8 +42,8 @@ instant_gets ``` ###hr() - Horizontal rule - Optional: pass in "=" for double line instead of single +* Horizontal rule +* Optional: pass in "=" for double line instead of single ```ruby hr(=) indent("Main Menu", 20) @@ -53,9 +53,9 @@ instant_gets ``` ###invalid_command() - Invalid command warning - Uses br and indent to format - Useful for menus in conjunction with case statements/until loops +* Invalid command warning +* Uses br and indent to format +* Useful for menus in conjunction with case statements/until loops ```ruby until menu_choice = "q" case menu_choice