diff --git a/README.md b/README.md index 3bf6fd0..b91f897 100644 --- a/README.md +++ b/README.md @@ -2,24 +2,6 @@ another lisp dialect > Also available on https://git.ablecorp.us/azur/bobbylisp -```lisp -; example/s.blsp -(fun factorial (x) - (if (<= x 1) - 1 - (* x (factorial (- x 1))))) -(do - (print (factorial 7))) -``` - -Compliation flow: -``` -Input(file) -> Parser -> Compile(Bytecode) -> Interpret - String SExprs Bytecode IO - |-> Compile - Assembly(?) -``` - ## Installation ```bash $ make diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..4d8445c --- /dev/null +++ b/install.sh @@ -0,0 +1,92 @@ +#!/bin/bash +tput sc + +function clear_print() { + tput rc +} + +function print_menu() { + local function_arguments=($@) + + local selected_item="$1" + local menu_items=(${function_arguments[@]:1}) + local menu_size="${#menu_items[@]}" + + for (( i = 0; i < $menu_size; ++i )) + do + if [ "$i" = "$selected_item" ] + then + echo "* ${menu_items[i]}" + else + echo " ${menu_items[i]}" + fi + done +} + +function run_menu() { + local function_arguments=($@) + + local selected_item="$1" + local menu_items=(${function_arguments[@]:1}) + local menu_size="${#menu_items[@]}" + local menu_limit=$((menu_size - 1)) + + clear_print + print_menu "$selected_item" "${menu_items[@]}" + + while read -rsn1 input + do + case "$input" + in + $'\x1B') + read -rsn1 -t 0.1 input + if [ "$input" = "[" ] + then + read -rsn1 -t 0.1 input + case "$input" + in + A) # Arrow up + if [ "$selected_item" -ge 1 ] + then + selected_item=$((selected_item - 1)) + clear_print + print_menu "$selected_item" "${menu_items[@]}" + fi + ;; + B) # Arrow down + if [ "$selected_item" -lt "$menu_limit" ] + then + selected_item=$((selected_item + 1)) + clear_print + print_menu "$selected_item" "${menu_items[@]}" + fi + ;; + esac + fi + read -rsn5 -t 0.1 # stdin flush + ;; + "") # Enter + return "$selected_item" + ;; + esac + done +} + +selected_item=0 +menu_items=("Install" "Uninstall" "Exit") + +run_menu "$selected_item" "${menu_items[@]}" +menu_result="$?" + +case "$menu_result" +in + 0) + echo "Install selected" + ;; + 1) + echo "Uninstall selected" + ;; + 2) + echo "Goodbye" + ;; +esac \ No newline at end of file diff --git a/trolley/.editorconfig b/trolley/.editorconfig new file mode 100644 index 0000000..163eb75 --- /dev/null +++ b/trolley/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*.cr] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true diff --git a/trolley/.gitignore b/trolley/.gitignore new file mode 100644 index 0000000..0bb75ea --- /dev/null +++ b/trolley/.gitignore @@ -0,0 +1,5 @@ +/docs/ +/lib/ +/bin/ +/.shards/ +*.dwarf diff --git a/trolley/shard.yml b/trolley/shard.yml new file mode 100644 index 0000000..649d4c4 --- /dev/null +++ b/trolley/shard.yml @@ -0,0 +1,13 @@ +name: trolley +version: 0.1.0 + +authors: + - Natapat Samutpong + +targets: + trolley: + main: src/trolley.cr + +crystal: 1.3.2 + +license: MIT diff --git a/trolley/spec/spec_helper.cr b/trolley/spec/spec_helper.cr new file mode 100644 index 0000000..6ea484a --- /dev/null +++ b/trolley/spec/spec_helper.cr @@ -0,0 +1,2 @@ +require "spec" +require "../src/trolley" diff --git a/trolley/spec/trolley_spec.cr b/trolley/spec/trolley_spec.cr new file mode 100644 index 0000000..4497898 --- /dev/null +++ b/trolley/spec/trolley_spec.cr @@ -0,0 +1,9 @@ +require "./spec_helper" + +describe Trolley do + # TODO: Write tests + + it "works" do + false.should eq(true) + end +end diff --git a/trolley/src/trolley.cr b/trolley/src/trolley.cr new file mode 100644 index 0000000..674d8de --- /dev/null +++ b/trolley/src/trolley.cr @@ -0,0 +1,35 @@ +require "option_parser" + +module Trolley + VERSION = "0.1.0" + + def self.display_help + puts "trolley " + VERSION + puts <<-HELP + USAGE: + trolley [COMMAND] [OPTION] + + COMMANDS: + -h, --help Display this help message + -v, --version Display version + HELP + exit + end + + def self.run + OptionParser.parse do |parser| + parser.on("-h", "--help") do + display_help + end + + parser.on("-v", "--version") do + puts "trolley " + VERSION + exit + end + end + end +end + +begin + Trolley.run +end