Skip to content

Commit

Permalink
Page all output, and remove --limit options
Browse files Browse the repository at this point in the history
Fixes #156
  • Loading branch information
JacobEvelyn committed Sep 22, 2018
1 parent 95d07e1 commit 9931eda
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 461 deletions.
181 changes: 89 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,48 +30,49 @@ lots of help), and give feedback!**

## Table of Contents

* [Overview](#overview)
* [Installation](#installation)
* [Usage](#usage)
* [Core concepts](#core-concepts)
* [Global flags](#global-flags)
* [Syncing across multiple machines](#syncing-across-multiple-machines)
* [Setting reminders](#setting-reminders)
* [Command reference](#command-reference)
* `add`
* [`add activity`](#add-activity)
* [`add note`](#add-note)
* [`add friend`](#add-friend)
* [`add tag`](#add-tag)
* [`add location`](#add-location)
* [`add nickname`](#add-nickname)
* [`clean`](#clean)
* [`graph`](#graph)
* [`help`](#help)
* `list`
* [`list activities`](#list-activities)
* [`list notes`](#list-notes)
* `list favorite`
* [`list favorite friends`](#list-favorite-friends)
* [`list favorite locations`](#list-favorite-locations)
* [`list friends`](#list-friends)
* [`list tags`](#list-tags)
* [`list locations`](#list-locations)
* [Advanced searching](#advanced-searching)
* `remove`
* [`remove tag`](#remove-tag)
* [`remove nickname`](#remove-nickname)
* `rename`
* [`rename friend`](#rename-friend)
* [`rename location`](#rename-location)
* [`set location`](#set-location)
* [`stats`](#stats)
* [`suggest`](#suggest)
* [`update`](#update)
* [Other documentation](#other-documentation)
* [Contributing (it's encouraged!)](#contributing-its-encouraged)
* [Code of Conduct](#code-of-conduct)
* [License](#license)
- [Overview](#overview)
- [Installation](#installation)
- [A note on output](#a-note-on-output)
- [Usage](#usage)
- [Core concepts](#core-concepts)
- [Global flags](#global-flags)
- [Syncing across multiple machines](#syncing-across-multiple-machines)
- [Setting reminders](#setting-reminders)
- [Command reference](#command-reference)
- `add`
- [`add activity`](#add-activity)
- [`add note`](#add-note)
- [`add friend`](#add-friend)
- [`add tag`](#add-tag)
- [`add location`](#add-location)
- [`add nickname`](#add-nickname)
- [`clean`](#clean)
- [`graph`](#graph)
- [`help`](#help)
- `list`
- [`list activities`](#list-activities)
- [`list notes`](#list-notes)
- `list favorite`
- [`list favorite friends`](#list-favorite-friends)
- [`list favorite locations`](#list-favorite-locations)
- [`list friends`](#list-friends)
- [`list tags`](#list-tags)
- [`list locations`](#list-locations)
- [Advanced searching](#advanced-searching)
- `remove`
- [`remove tag`](#remove-tag)
- [`remove nickname`](#remove-nickname)
- `rename`
- [`rename friend`](#rename-friend)
- [`rename location`](#rename-location)
- [`set location`](#set-location)
- [`stats`](#stats)
- [`suggest`](#suggest)
- [`update`](#update)
- [Other documentation](#other-documentation)
- [Contributing (it's encouraged!)](#contributing-its-encouraged)
- [Code of Conduct](#code-of-conduct)
- [License](#license)

---

Expand All @@ -82,21 +83,21 @@ people you care about.

`friends` gives you:

* More organization around staying in touch with friends and
- More organization around staying in touch with friends and
family.
* A way to track the ebbs and flows of your relationships over
- A way to track the ebbs and flows of your relationships over
time.
* Suggestions for who to call or hang out with when you have free
- Suggestions for who to call or hang out with when you have free
time, whether it's fifteen minutes or an entire weekend.
* A low-cost way to record and remember big moments in your life.
- A low-cost way to record and remember big moments in your life.

Its philosophy emphasizes:

* **Simplicity**—it should be quick and easy to use.
* **Transparency**—all data is stored in a human-readable Markdown file. No
- **Simplicity**—it should be quick and easy to use.
- **Transparency**—all data is stored in a human-readable Markdown file. No
proprietary formats here! And in addition to being open-source, `friends` is
very much open to new ideas. Contribute!
* **Intelligence**—specify dates with English phrases like "yesterday." Specify
- **Intelligence**—specify dates with English phrases like "yesterday." Specify
friends with their first names, even when you're friends with many *Joanne*s. `friends` will figure it out.

## Installation
Expand All @@ -107,58 +108,80 @@ $ gem install friends

Easy, huh?

## A note on output

To make its output easier to view and work with, `friends` "pages" its output.
This means that when it has a lot to print it will let you scroll up or down
in your terminal to view all of it.

By default, `friends` tries to use the `less -RFX` command for paging, which should
be available on most systems, and if that is not available falls back to simply
printing the output. However, you can set a different pager by setting the `FRIENDS_PAGER`
environment variable. If you have `less`
[version 530](http://www.greenwoodsoftware.com/less/news.530.html) or later
[we recommend using](https://unix.stackexchange.com/a/432254/181957#comment784324_432254)
this instead:

```bash
FRIENDS_PAGER="less -RF"
```

## Usage

### Core concepts

`friends` is structured around several different types of things:

* **Activities**: The things you do. Each activity has a date associated with
- **Activities**: The things you do. Each activity has a date associated with
it. Activities may optionally contain any number of _friends_, _locations_,
and _tags_.
* **Friends**: The people you do _activities_ with. Each friend has a name and,
- **Friends**: The people you do _activities_ with. Each friend has a name and,
optionally, one or several nicknames. (Examples: `John`, `Grace Hopper`)
* **Locations**: The places in which _activities_ happen. (Examples: `Paris`,
- **Locations**: The places in which _activities_ happen. (Examples: `Paris`,
`Marie's Diner`)
* **Tags**: A way to categorize your _activities_ with tags of your
- **Tags**: A way to categorize your _activities_ with tags of your
choosing. Tags may contain colons and hyphens inside them. (Examples: `@exercise:running`, `@school`, `@science:indoors:agronomy-with-hydroponics`)
* **Notes**: Any additional information you want to record about a _friend_
- **Notes**: Any additional information you want to record about a _friend_
or _location_. (Example: `John and Jane got engaged.`)

The `friends.md` Markdown file that stores all of your data contains:

* an alphabetical list of all locations:
- an alphabetical list of all locations:

```markdown
### Locations:

- Atlantis
- Marie's Diner
- Paris
```

* an alphabetical list of all friends and their nicknames and locations:
- an alphabetical list of all friends and their nicknames and locations:

```markdown
### Friends:

- George Washington Carver
- Grace Hopper (a.k.a. The Admiral a.k.a. Amazing Grace) [Paris]
- Marie Curie [Atlantis]
```

* an ordered list of all activities:
- an ordered list of all activities:

```markdown
### Activities:

- 2018-11-01: **Grace Hopper** and I went to _Marie's Diner_. George had to cancel at the last minute.
- 2018-01-04: Got lunch with **Grace Hopper** and **George Washington Carver**.
- 2017-12-31: Celebrated the new year in _Paris_ with **Marie Curie**.
- 2017-11-15: Talked to **George Washington Carver** on the phone for an hour.
```

* and an ordered list of all notes:
- and an ordered list of all notes:

```markdown
### Notes:

- 2018-06-15: **Grace Hopper** found out she's getting a big Naval Academy building named after her. @navy
- 2017-06-06: **Marie Curie** just got accepted into a PhD program in _Paris_. @school
```
Expand All @@ -174,16 +197,16 @@ specified before the name of the command, like: `friends [flags] [command]`.

These flags are:

* `--colorless`: Disable output colorization and other effects.
* `--debug`: Debug error messages with a full backtrace.
* `--filename`: Set the location of the friends file to use (default: `./friends.md`).
- `--colorless`: Disable output colorization and other effects.
- `--debug`: Debug error messages with a full backtrace.
- `--filename`: Set the location of the friends file to use (default: `./friends.md`).

```bash
$ friends --filename ./test/tmp/friends.md clean
File cleaned: "./test/tmp/friends.md"
```

* `--quiet`: Quiet output messages.
- `--quiet`: Quiet output messages.

```bash
$ friends --quiet add activity Went rollerskating with George.
Expand All @@ -192,7 +215,7 @@ $ # No output!

In addition, these flags may be used without any command:

* `--help`: Show the help menu. This is equivalent to `friends help`.
- `--help`: Show the help menu. This is equivalent to `friends help`.
Help menus are available for all levels of commands:

```bash
Expand All @@ -207,7 +230,7 @@ $ friends list --help
$ friends list activities --help
```

* `--version`: Show the `friends` program version.
- `--version`: Show the `friends` program version.

### Syncing across multiple machines

Expand Down Expand Up @@ -582,23 +605,15 @@ $ friends list activities
2017-11-15: Talked to George Washington Carver on the phone for an hour.
```
You can adjust how many activities are shown:
```bash
$ friends list activities --limit 2
2018-01-04: Got lunch with Grace Hopper and George Washington Carver. @food
2017-12-31: Celebrated the new year with Marie Curie in New York City. @partying:ball-drop
```
Or only list the activities you did with a certain friend:
You can list the activities you did with a certain friend:
```bash
$ friends list activities --with George
2018-01-04: Got lunch with Grace Hopper and George Washington Carver. @food
2017-11-15: Talked to George Washington Carver on the phone for an hour.
```
Or only filter activities done with a group of friends:
Or only activities done with a group of friends:
```bash
$ friends list activities --with George --with Grace
Expand Down Expand Up @@ -669,15 +684,6 @@ Your favorite friends:
3. Marie Curie (0)
```
You can specify a number of favorites to show:
```bash
$ friends list favorite friends --limit 2
Your favorite friends:
1. George Washington Carver (2 activities)
2. Grace Hopper (1)
```
#### `list favorite locations`
Lists your "favorite" locations (by total number of activities):
Expand All @@ -690,15 +696,6 @@ Your favorite locations:
3. London (0)
```
You can specify a number of favorites to show:
```bash
$ friends list favorite locations --limit 2
Your favorite locations:
1. Atlantis (2 activities)
2. Paris (1)
```
#### `list friends`
Lists all of your friends in alphabetical order:
Expand Down
17 changes: 13 additions & 4 deletions bin/friends
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pre do |global_options, cmd|
# If the --colorless flag is passed, don't do any fancy painting.
Paint.mode = 0 if global_options[:colorless]

@quiet_mode = global_options[:quiet]
@debug_mode = global_options[:debug]

# If we're updating the friends program we don't need to read the friends file
Expand All @@ -84,10 +85,7 @@ pre do |global_options, cmd|
# @introvert until the command block when the system call has exited
# successfully.
unless [:update, :edit].include? cmd.name
@introvert = Friends::Introvert.new(
filename: global_options[:filename],
quiet: global_options[:quiet]
)
@introvert = Friends::Introvert.new(filename: global_options[:filename])
end

true # Continue executing the command.
Expand All @@ -96,6 +94,17 @@ end
post do
# After each command, clean the file if we have modifications to make.
@introvert.clean(clean_command: @clean_command) if @dirty

if @introvert && !@quiet_mode
begin
IO.popen(ENV["FRIENDS_PAGER"] || "less -RFX", "w") { |pipe| pipe.puts @introvert.output }
rescue Errno::ENOENT
# If the pager is not installed, just print the output.
puts @introvert.output
rescue Errno::EPIPE # rubocop:disable Lint/HandleExceptions
# Occurs when quitting the pager.
end
end
end

# If an error is raised, print the message to STDERR and exit the program.
Expand Down
22 changes: 12 additions & 10 deletions friends.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "friends/version"

Gem::Specification.new do |spec|
spec.name = "friends"
spec.version = Friends::VERSION
spec.authors = ["Jacob Evelyn"]
spec.email = ["[email protected]"]
spec.summary = "Spend time with the people you care about."
spec.description = "Spend time with the people you care about. "\
"Introvert-tested. Extrovert-approved."
spec.homepage = "https://github.com/JacobEvelyn/friends"
spec.license = "MIT"
spec.name = "friends"
spec.version = Friends::VERSION
spec.authors = ["Jacob Evelyn"]
spec.email = ["[email protected]"]
spec.summary = "Spend time with the people you care about."
spec.description = "Spend time with the people you care about. "\
"Introvert-tested. Extrovert-approved."
spec.homepage = "https://github.com/JacobEvelyn/friends"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0")
spec.executables = ["friends"]
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

# We need Ruby 2.0's keyword arguments and default UTF-8 encoding.
# We need Ruby 2.1's default-less keyword arguments and default UTF-8
# encoding.
spec.required_ruby_version = ">= 2.1"

spec.add_dependency "chronic", "~> 0.10"
spec.add_dependency "gli", "~> 2.14"
spec.add_dependency "paint", "~> 2.0"
spec.add_dependency "semverse", "~> 2.0"
spec.add_dependency "tty-pager", "~> 0.11"

spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "coveralls", "~> 0.8"
Expand Down
5 changes: 1 addition & 4 deletions lib/friends/commands/edit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

# Mark the file for cleaning once the editor was closed correctly.
if Kernel.system("#{editor} #{filename}")
@introvert = Friends::Introvert.new(
filename: global_options[:filename],
quiet: global_options[:quiet]
)
@introvert = Friends::Introvert.new(filename: global_options[:filename])
@clean_command = true
@dirty = true
elsif !global_options[:quiet]
Expand Down
Loading

0 comments on commit 9931eda

Please sign in to comment.