Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 0 additions & 55 deletions README

This file was deleted.

72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#CLI FRAMEWORK

CLI Framework is a basic command line interface framework containing methods for layout.

###instant_gets()
* 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.
```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)
```ruby
indent("Main Menu", 20)
blank_indent(21)
instant_gets
```

###centre()
* 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
```ruby
indent("Main Menu", 20)
br(2)
blank_indent(21)
instant_gets
```

###hr()
* Horizontal rule
* Optional: pass in "=" for double line instead of single
```ruby
hr(=)
indent("Main Menu", 20)
br(2)
blank_indent(21)
instant_gets
```

###invalid_command()
* 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
when "1"
some_action
when "2"
some_other_action
when "q"
menu_choice
else
invalid_command
end
end
```
33 changes: 21 additions & 12 deletions cli_framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
print "#{" "*spaces}"
end

def br(breaks = 1)
Expand All @@ -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
end