prefixed all of rodo.rkt and args.rkt
parent
afaaf5094d
commit
d56570dcc2
42
LICENSE
42
LICENSE
|
@ -1,21 +1,21 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2018 m455
|
Copyright (c) 2018 m455
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|
222
README.md
222
README.md
|
@ -1,111 +1,111 @@
|
||||||
# rodo
|
# rodo
|
||||||
|
|
||||||
A simple to-do list tool for people who live on the command-line
|
A simple to-do list tool for people who live on the command-line
|
||||||
|
|
||||||
By: Jesse Laprade
|
By: Jesse Laprade
|
||||||
|
|
||||||
![](screenshot.png)
|
![](screenshot.png)
|
||||||
|
|
||||||
# Table of Contents
|
# Table of Contents
|
||||||
|
|
||||||
* [Legend](https://github.com/m455/rodo#legend)
|
* [Legend](https://github.com/m455/rodo#legend)
|
||||||
* [Platforms](https://github.com/m455/rodo#platforms)
|
* [Platforms](https://github.com/m455/rodo#platforms)
|
||||||
* [Requirements](https://github.com/m455/rodo#requirements)
|
* [Requirements](https://github.com/m455/rodo#requirements)
|
||||||
* [Download](https://github.com/m455/rodo#download)
|
* [Download](https://github.com/m455/rodo#download)
|
||||||
* [Via Browser](https://github.com/m455/rodo#via-browser)
|
* [Via Browser](https://github.com/m455/rodo#via-browser)
|
||||||
* [Via Git](https://github.com/m455/rodo#via-git)
|
* [Via Git](https://github.com/m455/rodo#via-git)
|
||||||
* [Setup](https://github.com/m455/rodo#setup)
|
* [Setup](https://github.com/m455/rodo#setup)
|
||||||
* [GNU/Linux](https://github.com/m455/rodo#gnulinux)
|
* [GNU/Linux](https://github.com/m455/rodo#gnulinux)
|
||||||
* [Setup a $PATH](https://github.com/m455/rodo#setup-a-path)
|
* [Setup a $PATH](https://github.com/m455/rodo#setup-a-path)
|
||||||
* [Using the binary](https://github.com/m455/rodo#using-the-binary)
|
* [Using the binary](https://github.com/m455/rodo#using-the-binary)
|
||||||
* [Creating a wrapper](https://github.com/m455/rodo#creating-a-wrapper)
|
* [Creating a wrapper](https://github.com/m455/rodo#creating-a-wrapper)
|
||||||
* [Usage](https://github.com/m455/rodo#usage)
|
* [Usage](https://github.com/m455/rodo#usage)
|
||||||
* [Examples](https://github.com/m455/rodo#examples)
|
* [Examples](https://github.com/m455/rodo#examples)
|
||||||
* [Configuration](https://github.com/m455/rodo#configuring-rodo)
|
* [Configuration](https://github.com/m455/rodo#configuring-rodo)
|
||||||
|
|
||||||
## Legend
|
## Legend
|
||||||
|
|
||||||
`Items marked like this` are either instructions for running on the command line or code. Do not include the initial `$` when running them.
|
`Items marked like this` are either instructions for running on the command line or code. Do not include the initial `$` when running them.
|
||||||
|
|
||||||
**Items marked like this** are important.
|
**Items marked like this** are important.
|
||||||
|
|
||||||
## Platforms
|
## Platforms
|
||||||
|
|
||||||
* GNU/Linux
|
* GNU/Linux
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* [Racket 6.x](https://racket-lang.org/)
|
* [Racket 6.x](https://racket-lang.org/)
|
||||||
* [Git (Optional)](https://git-scm.com/)
|
* [Git (Optional)](https://git-scm.com/)
|
||||||
|
|
||||||
## Download
|
## Download
|
||||||
|
|
||||||
### Via Browser
|
### Via Browser
|
||||||
|
|
||||||
Download this repository by clicking the **Clone or download** button at the top right and then choosing **Download ZIP** from the drop-down list
|
Download this repository by clicking the **Clone or download** button at the top right and then choosing **Download ZIP** from the drop-down list
|
||||||
|
|
||||||
### Via Git
|
### Via Git
|
||||||
|
|
||||||
Run `git clone https://github.com/m455/rodo` at the command line if you use Git
|
Run `git clone https://github.com/m455/rodo` at the command line if you use Git
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
### GNU/Linux
|
### GNU/Linux
|
||||||
|
|
||||||
#### Setup a $PATH
|
#### Setup a $PATH
|
||||||
|
|
||||||
1. Create a directory for your `$PATH` by running `mkdir ~/bin/`
|
1. Create a directory for your `$PATH` by running `mkdir ~/bin/`
|
||||||
|
|
||||||
2. Associate your `$PATH` with the ~/bin/ folder you created by running `echo "export PATH=~/bin:\$PATH" >> .bashrc`
|
2. Associate your `$PATH` with the ~/bin/ folder you created by running `echo "export PATH=~/bin:\$PATH" >> .bashrc`
|
||||||
|
|
||||||
#### Using the binary
|
#### Using the binary
|
||||||
|
|
||||||
1. Copy the rodo binary file to your `$PATH` folder by running `cp /path/to/rodo ~/bin/`
|
1. Copy the rodo binary file to your `$PATH` folder by running `cp /path/to/rodo ~/bin/`
|
||||||
|
|
||||||
2. Make the rodo binary file executable by running `chmod u+x ~/bin/rodo`
|
2. Make the rodo binary file executable by running `chmod u+x ~/bin/rodo`
|
||||||
|
|
||||||
#### Creating a wrapper
|
#### Creating a wrapper
|
||||||
|
|
||||||
1. Create an empty wrapper file by running `touch ~/bin/rodo`.
|
1. Create an empty wrapper file by running `touch ~/bin/rodo`.
|
||||||
|
|
||||||
2. Add the following contents show below to it
|
2. Add the following contents show below to it
|
||||||
|
|
||||||
```
|
```
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
racket ~/path/to/rodo.rkt "$@"
|
racket ~/path/to/rodo.rkt "$@"
|
||||||
```
|
```
|
||||||
3. Save the file
|
3. Save the file
|
||||||
|
|
||||||
For example, if you downloaded the project to your ~/downloads/ folder you would change the line `racket ~/path/to/rodo.rkt "$@"` to `racket ~/downloads/rodo/rodo.rkt "$@"`
|
For example, if you downloaded the project to your ~/downloads/ folder you would change the line `racket ~/path/to/rodo.rkt "$@"` to `racket ~/downloads/rodo/rodo.rkt "$@"`
|
||||||
|
|
||||||
2. Make the rodo wrapper file executable by running`chmod u+x ~/bin/rodo`
|
2. Make the rodo wrapper file executable by running`chmod u+x ~/bin/rodo`
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
init - Initializes a file in ~/.rodo/todo-list by default
|
init - Initializes a file in ~/.rodo/todo-list by default
|
||||||
|
|
||||||
ls - Lists items from the list
|
ls - Lists items from the list
|
||||||
|
|
||||||
add - Adds an entry to the list
|
add - Adds an entry to the list
|
||||||
|
|
||||||
rm - Removes an item from the list
|
rm - Removes an item from the list
|
||||||
|
|
||||||
**Note:** You may have to run `rodo ls` to see which number corresponds to which item when removing items.
|
**Note:** You may have to run `rodo ls` to see which number corresponds to which item when removing items.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
The examples below assume that you have rodo [set up](https://github.com/m455/rodo#setup-a-path) in your `$PATH`
|
The examples below assume that you have rodo [set up](https://github.com/m455/rodo#setup-a-path) in your `$PATH`
|
||||||
|
|
||||||
init - `rodo init`
|
init - `rodo init`
|
||||||
|
|
||||||
ls - `rodo ls`
|
ls - `rodo ls`
|
||||||
|
|
||||||
add (Single-word entry) - `rodo add bread`
|
add (Single-word entry) - `rodo add bread`
|
||||||
|
|
||||||
add (Multi-word entry) - `rodo add "go to the bank"`
|
add (Multi-word entry) - `rodo add "go to the bank"`
|
||||||
|
|
||||||
rm - `rodo rm 1`
|
rm - `rodo rm 1`
|
||||||
|
|
||||||
## Configuring rodo
|
## Configuring rodo
|
||||||
|
|
||||||
Right now, the configurations can be found in the config.rkt file. Settings such at program name, path and directory can be set here.
|
Right now, the configurations can be found in the config.rkt file. Settings such at program name, path and directory can be set here.
|
||||||
|
|
91
args.rkt
91
args.rkt
|
@ -1,47 +1,44 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
|
||||||
(require racket/vector
|
(require (prefix-in vector: racket/vector)
|
||||||
racket/list
|
(prefix-in list: racket/list)
|
||||||
"config.rkt"
|
(prefix-in config: "config.rkt")
|
||||||
"init.rkt"
|
(prefix-in init: "init.rkt")
|
||||||
"util.rkt"
|
(prefix-in util: "util.rkt")
|
||||||
"messages.rkt")
|
(prefix-in messages: "messages.rkt"))
|
||||||
|
|
||||||
(provide (all-defined-out))
|
(provide (all-defined-out))
|
||||||
|
|
||||||
(define (check-args args)
|
(define (check-args args)
|
||||||
(let
|
(let
|
||||||
([args-length (vector-length args)])
|
([args-length (vector-length args)])
|
||||||
(cond
|
(cond
|
||||||
[(equal? args-length 0)
|
[(equal? args-length 0)
|
||||||
(d-hash-ref messages 'show-usage)]
|
(util:display-hash-ref messages:messages 'show-usage)]
|
||||||
|
[(and
|
||||||
[(and
|
(equal? args-length 1)
|
||||||
(equal? args-length 1)
|
(equal? (vector:vector-member config:list-command args) 0))
|
||||||
(equal? (vector-member list-command args) 0))
|
(util:show-list)]
|
||||||
(show-list)]
|
[(and
|
||||||
|
(equal? args-length 2)
|
||||||
[(and
|
(equal? (vector-ref args 0) config:add-command))
|
||||||
(equal? args-length 2)
|
(util:add-item args)]
|
||||||
(equal? (vector-ref args 0) add-command))
|
[(and
|
||||||
(add-item args)]
|
(equal? args-length 2)
|
||||||
|
(equal? (vector:vector-member config:remove-command args) 0)
|
||||||
[(and
|
(not (equal? (vector:vector-member "0" args) 1))
|
||||||
(equal? args-length 2)
|
(vector:vector-member
|
||||||
(equal? (vector-member remove-command args) 0)
|
(vector-ref args 1)
|
||||||
(not (equal? (vector-member "0" args) 1))
|
(list->vector
|
||||||
(vector-member (vector-ref args 1) (list->vector (map number->string (rest (range (length (file->string-list path))))))))
|
(map number->string (list:rest (list:range (length (util:file->string-list config:path))))))))
|
||||||
(remove-item args)]
|
(util:remove-item args)]
|
||||||
|
[(and
|
||||||
[(and
|
(equal? args-length 1)
|
||||||
(equal? args-length 1)
|
(equal? (vector:vector-member config:initialize-command args) 0))
|
||||||
(equal? (vector-member initialize-command args) 0))
|
(init:initialize)]
|
||||||
(initialize)]
|
[(and
|
||||||
|
(equal? args-length 1)
|
||||||
[(and
|
(member (vector-ref args 0) config:help-command))
|
||||||
(equal? args-length 1)
|
(util:display-hash-ref messages:messages 'show-help)]
|
||||||
(member (vector-ref args 0) help-command))
|
[else
|
||||||
(d-hash-ref messages 'show-help)]
|
(util:display-hash-ref messages:messages 'show-usage)])))
|
||||||
|
|
||||||
[else
|
|
||||||
(d-hash-ref messages 'show-usage)])))
|
|
||||||
|
|
38
config.rkt
38
config.rkt
|
@ -1,19 +1,19 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
(require racket/file)
|
(require racket/file)
|
||||||
(provide (all-defined-out))
|
(provide (all-defined-out))
|
||||||
|
|
||||||
(define program-name "rodo")
|
(define program-name "rodo")
|
||||||
(define program-directory ".rodo/")
|
(define program-directory ".rodo/")
|
||||||
(define program-path "~/")
|
(define program-path "~/")
|
||||||
(define program-file "todo-list")
|
(define program-file "todo-list")
|
||||||
(define remove-command "rm")
|
(define remove-command "rm")
|
||||||
(define add-command "add")
|
(define add-command "add")
|
||||||
(define list-command "ls")
|
(define list-command "ls")
|
||||||
(define initialize-command "init")
|
(define initialize-command "init")
|
||||||
(define help-command '("-h" "--help"))
|
(define help-command '("-h" "--help"))
|
||||||
(define path
|
(define path
|
||||||
(expand-user-path
|
(expand-user-path
|
||||||
(string-append
|
(string-append
|
||||||
program-path
|
program-path
|
||||||
program-directory
|
program-directory
|
||||||
program-file)))
|
program-file)))
|
||||||
|
|
93
init.rkt
93
init.rkt
|
@ -1,47 +1,46 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
|
||||||
(require racket/file
|
(require racket/file
|
||||||
"config.rkt"
|
"config.rkt"
|
||||||
"util.rkt"
|
"util.rkt"
|
||||||
"messages.rkt"
|
"messages.rkt")
|
||||||
"io.rkt")
|
|
||||||
|
(provide (all-defined-out))
|
||||||
(provide (all-defined-out))
|
|
||||||
|
(define (initialize-file)
|
||||||
(define (initialize-file)
|
(display-to-file
|
||||||
(display-to-file
|
"--Do not edit this file--\n"
|
||||||
"--Do not edit this file--\n"
|
path
|
||||||
path
|
#:mode 'text
|
||||||
#:mode 'text
|
#:exists 'replace))
|
||||||
#:exists 'replace))
|
|
||||||
|
(define (init-prompt hash-list key)
|
||||||
(define (init-prompt hash-list key)
|
(display-hash-ref hash-list key)
|
||||||
(d-hash-ref hash-list key)
|
(display "> ")
|
||||||
(display "> ")
|
(let
|
||||||
(let
|
([user-input (read-line)])
|
||||||
([user-input (read-line)])
|
(cond
|
||||||
(cond
|
[(member user-input (hash-ref y/n 'yes))
|
||||||
[(member user-input (hash-ref y/n 'yes))
|
(display-hash-ref messages 'creating-folder)
|
||||||
(d-hash-ref messages 'creating-folder)
|
(display-hash-ref messages 'creating-file)
|
||||||
(d-hash-ref messages 'creating-file)
|
(create-folder)
|
||||||
(create-folder)
|
(create-file)
|
||||||
(create-file)
|
(initialize-file)
|
||||||
(initialize-file)
|
(if
|
||||||
(if
|
(and
|
||||||
(and
|
(check-for-folder)
|
||||||
(check-for-folder)
|
(check-for-file))
|
||||||
(check-for-file))
|
(display-hash-ref messages 'successfully-created)
|
||||||
(d-hash-ref messages 'successfully-created)
|
(display-hash-ref messages 'creation-error))]
|
||||||
(d-hash-ref messages 'creation-error))]
|
|
||||||
|
[(member user-input (hash-ref y/n 'no))
|
||||||
[(member user-input (hash-ref y/n 'no))
|
(display-hash-ref messages 'terminating)]
|
||||||
(d-hash-ref messages 'terminating)]
|
|
||||||
|
[else
|
||||||
[else
|
(init-prompt messages 'choose-y/n)])))
|
||||||
(init-prompt messages 'choose-y/n)])))
|
|
||||||
|
(define (initialize)
|
||||||
(define (initialize)
|
(if (check-for-file)
|
||||||
(if (check-for-file)
|
(display-hash-ref messages 'file-already-exists)
|
||||||
(d-hash-ref messages 'file-already-exists)
|
(begin
|
||||||
(begin
|
(init-prompt messages 'init-y/n))))
|
||||||
(init-prompt messages 'init-y/n))))
|
|
||||||
|
|
32
io.rkt
32
io.rkt
|
@ -1,32 +0,0 @@
|
||||||
#lang racket/base
|
|
||||||
|
|
||||||
(require racket/file
|
|
||||||
"config.rkt")
|
|
||||||
|
|
||||||
(provide (all-defined-out))
|
|
||||||
|
|
||||||
(define (check-for-file)
|
|
||||||
(file-exists? path))
|
|
||||||
|
|
||||||
(define (create-file)
|
|
||||||
(let
|
|
||||||
([opened-file
|
|
||||||
(open-output-file
|
|
||||||
path
|
|
||||||
#:mode 'text
|
|
||||||
#:exists 'can-update)])
|
|
||||||
(close-output-port opened-file)))
|
|
||||||
|
|
||||||
(define (check-for-folder)
|
|
||||||
(directory-exists?
|
|
||||||
(expand-user-path
|
|
||||||
(string-append
|
|
||||||
program-path
|
|
||||||
program-directory))))
|
|
||||||
|
|
||||||
(define (create-folder)
|
|
||||||
(make-directory
|
|
||||||
(expand-user-path
|
|
||||||
(string-append
|
|
||||||
program-path
|
|
||||||
program-directory))))
|
|
290
messages.rkt
290
messages.rkt
|
@ -1,145 +1,145 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
|
||||||
(require "config.rkt")
|
(require "config.rkt")
|
||||||
|
|
||||||
(provide (all-defined-out))
|
(provide (all-defined-out))
|
||||||
|
|
||||||
(define messages
|
(define messages
|
||||||
(hash
|
(hash
|
||||||
'show-help
|
'show-help
|
||||||
(string-append
|
(string-append
|
||||||
"* " initialize-command ": "
|
"* " initialize-command ": "
|
||||||
"initialize a file in "
|
"initialize a file in "
|
||||||
program-path
|
program-path
|
||||||
program-directory
|
program-directory
|
||||||
program-file
|
program-file
|
||||||
"\n"
|
"\n"
|
||||||
"\x09Example: "
|
"\x09Example: "
|
||||||
"rodo init\n\n"
|
"rodo init\n\n"
|
||||||
|
|
||||||
"* " list-command ": "
|
"* " list-command ": "
|
||||||
"lists items on the list"
|
"lists items on the list"
|
||||||
"\n"
|
"\n"
|
||||||
"\x09Example: "
|
"\x09Example: "
|
||||||
"rodo ls\n\n"
|
"rodo ls\n\n"
|
||||||
|
|
||||||
"* " add-command ": "
|
"* " add-command ": "
|
||||||
"adds an item to the list"
|
"adds an item to the list"
|
||||||
"\n"
|
"\n"
|
||||||
"\x09Example: "
|
"\x09Example: "
|
||||||
"rodo add bread\n\n"
|
"rodo add bread\n\n"
|
||||||
"\x09Note: For multi-word items you will need to\n"
|
"\x09Note: For multi-word items you will need to\n"
|
||||||
"\x09surround your item in double quotes as so:\n"
|
"\x09surround your item in double quotes as so:\n"
|
||||||
"\x09rodo add \"go to the bank\"\n"
|
"\x09rodo add \"go to the bank\"\n"
|
||||||
|
|
||||||
"* " remove-command ": "
|
"* " remove-command ": "
|
||||||
"removes an item from the list\n"
|
"removes an item from the list\n"
|
||||||
"\x09Example: "
|
"\x09Example: "
|
||||||
"rodo rm 1\n"
|
"rodo rm 1\n"
|
||||||
"\x09Note: You may have to run `rodo ls` to see which\n"
|
"\x09Note: You may have to run `rodo ls` to see which\n"
|
||||||
"\x09number corresponds to which item to remove it.\n")
|
"\x09number corresponds to which item to remove it.\n")
|
||||||
|
|
||||||
'empty-todo-list
|
'empty-todo-list
|
||||||
"> There is nothing in your list \n"
|
"> There is nothing in your list \n"
|
||||||
|
|
||||||
'show-usage
|
'show-usage
|
||||||
(string-append
|
(string-append
|
||||||
"> For usage type "
|
"> For usage type "
|
||||||
"`" program-name " -h`"
|
"`" program-name " -h`"
|
||||||
" or "
|
" or "
|
||||||
"`" program-name " --help`\n")
|
"`" program-name " --help`\n")
|
||||||
|
|
||||||
'creating-folder
|
'creating-folder
|
||||||
(string-append
|
(string-append
|
||||||
"> creating a "
|
"> creating a "
|
||||||
program-directory
|
program-directory
|
||||||
" folder in "
|
" folder in "
|
||||||
program-path " ...\n")
|
program-path " ...\n")
|
||||||
|
|
||||||
'creating-file
|
'creating-file
|
||||||
(string-append
|
(string-append
|
||||||
"> creating a "
|
"> creating a "
|
||||||
program-file
|
program-file
|
||||||
" file in "
|
" file in "
|
||||||
program-path
|
program-path
|
||||||
program-directory " ...\n")
|
program-directory " ...\n")
|
||||||
|
|
||||||
'creation-error
|
'creation-error
|
||||||
(string-append
|
(string-append
|
||||||
"> Error: Could not create "
|
"> Error: Could not create "
|
||||||
program-file
|
program-file
|
||||||
" in "
|
" in "
|
||||||
program-directory
|
program-directory
|
||||||
program-path ".\n"
|
program-path ".\n"
|
||||||
"> This may be due to directory permissions\n")
|
"> This may be due to directory permissions\n")
|
||||||
|
|
||||||
'file-already-exists
|
'file-already-exists
|
||||||
(string-append
|
(string-append
|
||||||
"> Error: "
|
"> Error: "
|
||||||
program-name
|
program-name
|
||||||
" already exists in "
|
" already exists in "
|
||||||
program-path
|
program-path
|
||||||
program-directory
|
program-directory
|
||||||
program-file "\n")
|
program-file "\n")
|
||||||
|
|
||||||
'successfully-created
|
'successfully-created
|
||||||
(string-append
|
(string-append
|
||||||
"> "
|
"> "
|
||||||
program-path
|
program-path
|
||||||
program-directory
|
program-directory
|
||||||
program-file
|
program-file
|
||||||
" has been successfully created\n")
|
" has been successfully created\n")
|
||||||
|
|
||||||
'file-not-found
|
'file-not-found
|
||||||
(string-append
|
(string-append
|
||||||
"> Error: Could not find "
|
"> Error: Could not find "
|
||||||
program-path
|
program-path
|
||||||
program-directory
|
program-directory
|
||||||
program-file "\n")
|
program-file "\n")
|
||||||
|
|
||||||
'init-y/n
|
'init-y/n
|
||||||
(string-append
|
(string-append
|
||||||
"> A "
|
"> A "
|
||||||
program-file
|
program-file
|
||||||
" file will be created in "
|
" file will be created in "
|
||||||
program-path
|
program-path
|
||||||
program-directory "\n"
|
program-directory "\n"
|
||||||
"> Are you sure you want to continue? [y/n]\n")
|
"> Are you sure you want to continue? [y/n]\n")
|
||||||
|
|
||||||
'try-init
|
'try-init
|
||||||
(string-append
|
(string-append
|
||||||
"> Try typing "
|
"> Try typing "
|
||||||
"`" program-name " init` "
|
"`" program-name " init` "
|
||||||
"to set it up\n")
|
"to set it up\n")
|
||||||
|
|
||||||
'terminating
|
'terminating
|
||||||
(string-append
|
(string-append
|
||||||
"> Exiting "
|
"> Exiting "
|
||||||
program-name
|
program-name
|
||||||
" ...\n")
|
" ...\n")
|
||||||
|
|
||||||
'choose-y/n
|
'choose-y/n
|
||||||
"> Error: Please choose y or n\n"
|
"> Error: Please choose y or n\n"
|
||||||
|
|
||||||
'not-in-list
|
'not-in-list
|
||||||
"> Error: Item does not exist\n"
|
"> Error: Item does not exist\n"
|
||||||
|
|
||||||
'item-added-prefix
|
'item-added-prefix
|
||||||
"> Added "
|
"> Added "
|
||||||
|
|
||||||
'item-added-suffix
|
'item-added-suffix
|
||||||
" to list\n"
|
" to list\n"
|
||||||
|
|
||||||
'item-removed-prefix
|
'item-removed-prefix
|
||||||
"> Removed "
|
"> Removed "
|
||||||
|
|
||||||
'item-removed-suffix
|
'item-removed-suffix
|
||||||
" from list\n"))
|
" from list\n"))
|
||||||
|
|
||||||
(define y/n
|
(define y/n
|
||||||
(hash
|
(hash
|
||||||
'yes
|
'yes
|
||||||
'("yes" "Yes" "y" "Y")
|
'("yes" "Yes" "y" "Y")
|
||||||
|
|
||||||
'no
|
'no
|
||||||
'("no" "No" "n" "N")))
|
'("no" "No" "n" "N")))
|
||||||
|
|
18
rodo.rkt
18
rodo.rkt
|
@ -1,9 +1,9 @@
|
||||||
#! /usr/bin/env racket
|
#! /usr/bin/env racket
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
|
||||||
(require "args.rkt")
|
(require (prefix-in args: "args.rkt"))
|
||||||
|
|
||||||
(define (main)
|
(define (main)
|
||||||
(check-args (current-command-line-arguments)))
|
(args:check-args (current-command-line-arguments)))
|
||||||
|
|
||||||
(main)
|
(main)
|
||||||
|
|
250
util.rkt
250
util.rkt
|
@ -1,116 +1,134 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
|
||||||
(require racket/list
|
(require racket/list
|
||||||
racket/file
|
racket/file
|
||||||
racket/string
|
racket/string
|
||||||
"config.rkt"
|
"config.rkt"
|
||||||
"io.rkt"
|
"messages.rkt")
|
||||||
"messages.rkt")
|
|
||||||
|
(provide (all-defined-out))
|
||||||
(provide (all-defined-out))
|
|
||||||
|
(define (check-for-file)
|
||||||
(define (d-hash-ref hash-list key)
|
(file-exists? path))
|
||||||
(display (hash-ref hash-list key)))
|
|
||||||
|
(define (create-file)
|
||||||
(define (d-vector-ref args key)
|
(let ([opened-file
|
||||||
(display (vector-ref args key)))
|
(open-output-file path
|
||||||
|
#:mode 'text
|
||||||
(define (file->string-list path-to-file)
|
#:exists 'can-update)])
|
||||||
(let
|
(close-output-port opened-file)))
|
||||||
([todo-list
|
|
||||||
(file->lines
|
(define (check-for-folder)
|
||||||
path-to-file
|
(directory-exists? (expand-user-path
|
||||||
#:mode 'text
|
(string-append
|
||||||
#:line-mode 'any)])
|
program-path
|
||||||
todo-list))
|
program-directory))))
|
||||||
|
|
||||||
(define (list-empty? lst)
|
(define (create-folder)
|
||||||
(empty? (rest (file->string-list lst))))
|
(make-directory (expand-user-path
|
||||||
|
(string-append
|
||||||
(define (get-removed-item lst args)
|
program-path
|
||||||
(list-ref lst (string->number args)))
|
program-directory))))
|
||||||
|
|
||||||
(define (quote-item args)
|
(define (display-hash-ref hash-list key)
|
||||||
(display
|
(display (hash-ref hash-list key)))
|
||||||
(string-append "\"" args "\"")))
|
|
||||||
|
(define (d-vector-ref args key)
|
||||||
(define (number-list lst)
|
(display (vector-ref args key)))
|
||||||
(map string-append
|
|
||||||
(map number->string (rest (range (length lst))))
|
(define (file->string-list path-to-file)
|
||||||
(rest lst)))
|
(let ([todo-list (file->lines path-to-file
|
||||||
|
#:mode 'text
|
||||||
(define (indent-list lst)
|
#:line-mode 'any)])
|
||||||
(string-append ". " lst))
|
todo-list))
|
||||||
|
|
||||||
(define (prettify-list)
|
(define (list-empty? lst)
|
||||||
(display
|
(empty? (rest (file->string-list lst))))
|
||||||
(string-join
|
|
||||||
(number-list (map indent-list (file->string-list path)))
|
(define (get-removed-item lst args)
|
||||||
"\n"
|
(list-ref lst (string->number args)))
|
||||||
#:after-last "\n")))
|
|
||||||
|
(define (quote-item args)
|
||||||
(define (show-list)
|
(display
|
||||||
(cond
|
(string-append "\"" args "\"")))
|
||||||
[(and
|
|
||||||
(check-for-folder)
|
(define (prefix-with-number lst)
|
||||||
(check-for-file))
|
(map string-append
|
||||||
(if
|
(map number->string (rest (range (length lst))))
|
||||||
(list-empty? path)
|
(rest lst)))
|
||||||
(d-hash-ref messages 'empty-todo-list)
|
|
||||||
(prettify-list))]
|
(define (prefix-with-period lst)
|
||||||
[else
|
(string-append ". " lst))
|
||||||
(d-hash-ref messages 'file-not-found)
|
|
||||||
(d-hash-ref messages 'try-init)]))
|
(define (prettify-list)
|
||||||
|
(display
|
||||||
(define (add-item-to-file args)
|
(string-join (prefix-with-number (map prefix-with-period (file->string-list path)))
|
||||||
(let ([new-list
|
"\n"
|
||||||
(reverse
|
#:after-last "\n")))
|
||||||
(cons args
|
|
||||||
(reverse (file->string-list path))))])
|
(define (append-to-end args lst)
|
||||||
(display-to-file
|
(reverse (cons args (reverse (file->string-list lst)))))
|
||||||
(string-join new-list "\n" #:after-last "\n")
|
|
||||||
path
|
(define (display-item-added args)
|
||||||
#:mode 'text
|
(display-hash-ref messages 'item-added-prefix)
|
||||||
#:exists 'replace)
|
(quote-item args)
|
||||||
(d-hash-ref messages 'item-added-prefix)
|
(display-hash-ref messages 'item-added-suffix))
|
||||||
(quote-item args)
|
|
||||||
(d-hash-ref messages 'item-added-suffix)))
|
(define (display-item-removed args)
|
||||||
|
(display-hash-ref messages 'item-removed-prefix)
|
||||||
(define (add-item args)
|
(quote-item args)
|
||||||
(if
|
(display-hash-ref messages 'item-removed-suffix))
|
||||||
(and
|
|
||||||
(check-for-folder)
|
(define (show-list)
|
||||||
(check-for-file))
|
(cond [(and
|
||||||
(add-item-to-file (vector-ref args 1))
|
(check-for-folder)
|
||||||
(begin
|
(check-for-file))
|
||||||
(d-hash-ref messages 'file-not-found)
|
(if
|
||||||
(d-hash-ref messages 'try-init))))
|
(list-empty? path)
|
||||||
|
(display-hash-ref messages 'empty-todo-list)
|
||||||
(define (remove-item-from-file args)
|
(prettify-list))]
|
||||||
(let ([removed-item
|
[else
|
||||||
(get-removed-item (file->string-list path) args)]
|
(display-hash-ref messages 'file-not-found)
|
||||||
[new-list
|
(display-hash-ref messages 'try-init)]))
|
||||||
(remove
|
|
||||||
(list-ref (file->string-list path) (string->number args))
|
(define (add-item-to-file args)
|
||||||
(file->string-list path))])
|
(let ([new-list (append-to-end args path)])
|
||||||
(display-to-file
|
(display-to-file
|
||||||
(string-join new-list "\n" #:after-last "\n")
|
(string-join new-list "\n" #:after-last "\n")
|
||||||
path
|
path
|
||||||
#:mode 'text
|
#:mode 'text
|
||||||
#:exists 'replace)
|
#:exists 'replace)
|
||||||
(d-hash-ref messages 'item-removed-prefix)
|
(display-item-added args)))
|
||||||
(quote-item removed-item)
|
|
||||||
(d-hash-ref messages 'item-removed-suffix)))
|
(define (add-item args)
|
||||||
|
(if (and
|
||||||
(define (remove-item args)
|
(check-for-folder)
|
||||||
(cond
|
(check-for-file))
|
||||||
[(list-empty? path)
|
(add-item-to-file (vector-ref args 1))
|
||||||
(d-hash-ref messages 'empty-todo-list)]
|
(begin
|
||||||
[(and
|
(display-hash-ref messages 'file-not-found)
|
||||||
(check-for-folder)
|
(display-hash-ref messages 'try-init))))
|
||||||
(check-for-file))
|
|
||||||
(remove-item-from-file (vector-ref args 1))]
|
(define (remove-item-from-file args)
|
||||||
[(and (not (check-for-folder)) (not (check-for-file)))
|
(let ([removed-item (get-removed-item (file->string-list path) args)]
|
||||||
(begin
|
[new-list (remove
|
||||||
(d-hash-ref messages 'file-not-found)
|
(list-ref (file->string-list path) (string->number args))
|
||||||
(d-hash-ref messages 'try-init))]))
|
(file->string-list path))])
|
||||||
|
(display-to-file
|
||||||
|
(string-join new-list "\n" #:after-last "\n")
|
||||||
|
path
|
||||||
|
#:mode 'text
|
||||||
|
#:exists 'replace)
|
||||||
|
(display-item-removed removed-item)))
|
||||||
|
|
||||||
|
(define (remove-item args)
|
||||||
|
(cond [(list-empty? path)
|
||||||
|
(display-hash-ref messages 'empty-todo-list)]
|
||||||
|
[(and
|
||||||
|
(check-for-folder)
|
||||||
|
(check-for-file))
|
||||||
|
(remove-item-from-file (vector-ref args 1))]
|
||||||
|
[(and (not (check-for-folder)) (not (check-for-file)))
|
||||||
|
(begin
|
||||||
|
(display-hash-ref messages 'file-not-found)
|
||||||
|
(display-hash-ref messages 'try-init))]))
|
||||||
|
|
Loading…
Reference in New Issue