Skip to content

Commit

Permalink
Merge pull request #2 from freyamade/fixes/v0.31
Browse files Browse the repository at this point in the history
Fixes/v0.31
  • Loading branch information
freyamade authored Oct 15, 2019
2 parents 09a0776 + 7086ed1 commit 4a127bd
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 63 deletions.
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

One stop shop for the updates made to the project with each version, and to check master's status against the latest release

## 0.6.0 - Latest Release
## 0.7.0 - Latest Release
- Updated to Crystal 0.31
- Crcophony now requires the multithreading preview to be enabled to work properly
- Notifications are back in master

## 0.6.0
- Added multi line input that expands the prompt box accordingly (Ctrl+N to add a new line)
- Fixed bug where characters always get added to the end of a prompt even when the cursor is moved elsewhere (requires `shards update`)

### without-notifs
The `without-notifs` branch is a saved version of the project without the DBUS notifications.
This is the branch that the latest static release has been made from

## 0.5.0
- Changed loading messages to use a progress bar
- Added parsing of code blocks
Expand Down
6 changes: 3 additions & 3 deletions PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Maintainer: freyamade <contact@freyama.de>

pkgname=crcophony-git
pkgver=0.6.0
pkgver=0.7.0
pkgrel=1
pkgdesc='Fast, neat discord TUI written in Crystal'
arch=('x86_64')
url='https://github.com/freyamade/crcophony'
license=('MIT')
md5sums=('SKIP')
depends=('dbus' 'termbox-git')
makedepends=('git' 'crystal' 'shards')
makedepends=('git' 'crystal>=0.31.0' 'shards')
source=("$pkgname::git+https://github.com/freyamade/crcophony.git")
provides=('crcophony')

Expand All @@ -20,7 +20,7 @@ pkgver() {

build() {
cd "$srcdir/$pkgname"
shards build crcophony --release --progress
shards build crcophony --release --progress -Dpreview_mt
}

package() {
Expand Down
72 changes: 27 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,8 @@
*read: cacophony*

[![release badge](https://img.shields.io/github/tag-date/freyamade/crcophony.svg?label=version&style=flat-square)](https://github.com/freyamade/crcophony/releases/latest)
![I am not currently actively developing this project, but I will fix issues that arise](https://img.shields.io/badge/status-fixes--only-blue.svg)

A simple Discord terminal ui written in Crystal.

## Notice about notifications
I originally had the system set up to use `dbus` for a notification service.
However, according to the `dbus` project;
```
NOTE ABOUT STATIC LINKING
We are not yet firmly freezing all runtime dependencies of the libdbus
library. For example, the library may read certain files as part of
its implementation, and these files may move around between versions.
As a result, we don't yet recommend statically linking to
libdbus. Also, reimplementations of the protocol from scratch might
have to work to stay in sync with how libdbus behaves.
To lock things down and declare static linking and reimplementation to
be safe, we'd like to see all the internal dependencies of libdbus
(for example, files read) well-documented in the specification, and
we'd like to have a high degree of confidence that these dependencies
are supportable over the long term and extensible where required.
```

As a result, I will be unable to compile a static binary that uses dbus for notifications.
I will be removing the notification system from `master` and hosting it on a separate branch named `with-notifs` until a solution can be reached for this issue.

I apologise for this, and will continue looking for a way to remedy the situation.
A simple Discord Terminal UI written in Crystal.

## WARNING
Self-bots are not allowed by Discord's Terms of Service.
Expand All @@ -57,29 +30,30 @@ Bottom line: ***Use at your own risk***
- <kbd>Ctrl</kbd>+<kbd>S</kbd> / <kbd>Down</kbd>: Scroll Selection Down
- <kbd>ESC</kbd>: Alternative Close Button

## Usage
## Installation

### Using pre-built binary
Since the 0.1.0 release I have been including a static binary attached to releases. Here are instructions for running the application using these binaries;
### PKGBUILD
If you use Arch Linux or any similar variant, then there's a PKGBUILD in the repo.
I haven't published this project to the AUR yet but I intend to at some stage.

1. Go to the [latest release](https://github.com/freyamade/crcophony/releases/latest) and download the binary.
2. Follow the steps in [Gathering Data](#gathering-data) to set up your environment.
3. Run `./crcophony` from the directory you downloaded the binary to and it should run.
### From source
If you're not on Arch, currently the only way is to install from source.

If the pre-built binary doesn't work, open an issue with as much information as possible (from log files and application error trace and such) and then maybe also try installing from source!
#### Install requirements
The requirements for the application are as follows;
- [`crystal>=0.31.0`](https://crystal-lang.org/reference/installation/)
- [`termbox`](https://github.com/nsf/termbox)
- 'libdbus'

### From source
If the pre-built binary didn't work for you, or you want to install from source by choice, here are the instructions;
#### Build
1. Clone this repo
2. Run `shards install` and then `shards build --release -Dpreview_mt` to install all the requirements and build the application.
- This will create an executable in the `bin` folder local to the cloned repo, which can then be moved wherever it needs to be moved.

1. Install [Crystal](https://crystal-lang.org/reference/installation/)
2. Install [termbox](https://github.com/nsf/termbox) following the instructions in their README.
3. Clone this repo.
4. Run `shards install` to install requirements.
5. Follow the steps in [Gathering Data](#gathering-data) to set up your environment.
6. Run `shards build` to build the system, or use `shards build --release` to build with optimisations (slower build but potential speedups over non release mode).
7. Run `bin/crcophony` to open the application.
## Usage
Before you can run Crcophony, you need to gather a bit of data.

## Gathering Data
### Gathering Data
To use the system, you must gather the following information and export the data as environment variables.
These variables are as follows;

Expand All @@ -94,6 +68,14 @@ Here are the instructions for you to get these bits of data;
If you use the `fish` or `bash` shells, a sample `.env` file has been included in this project (`.env.sample.fish` and `env.sample.bash` respectively).
Simply rename the appropriate file to `.env`, populate the strings inside with your gathered data and run `source .env` in the directory to get the correct environment variables created.

### Running the Application
After the environment variables are defined, simply run the crcophony executable.

### NOTE
As far as I am currently aware, placing `crcophony` in a bin folder and running it as `crcophony` does not work when attempting to spawn threads.
This is because Crystal tries to spawn by reading the file passed in as the command following it like a path from your current directory.
The workaround I currently use is creating a small bash script that runs crcophony using an absolute path, and placing this executable script in your bin folder.

## Contributing

1. Fork it (https://github.com/freyamade/crcophony/fork)
Expand Down
6 changes: 5 additions & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ shards:

hydra:
github: freyamade/hydra
commit: bfc73ea3282515c97b5cff75202e419ba98120df
commit: df8a6b0578eae16cd78aea32e733266aa320d008

noir:
github: freyamade/noir
commit: 87e77d739d3bbcc42cd7570366010988cf4e16a7

notify:
github: woodruffw/notify.cr
commit: c1902634ce60acbd13cb445d441b3ca32631021e

termbox:
github: andrewsuzuki/termbox-crystal
commit: 9471d1f1852dec251d6bcb6f8a583e7abdf04f68
Expand Down
7 changes: 5 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: crcophony
version: 0.6.0
version: 0.7.0

authors:
- freyamade <frybrdrck@gmail.com>
Expand All @@ -18,7 +18,10 @@ dependencies:
noir:
github: freyamade/noir
branch: master
notify:
github: woodruffw/notify.cr
branch: master

crystal: 0.27.2
crystal: 0.31.0

license: MIT
18 changes: 13 additions & 5 deletions src/application.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Crcophony
@channel_prompt : Crcophony::Searcher
@client : Discord::Client
@messages : Hydra::Logbox
@notifier : Notify
@parser : Crcophony::MessageParser
@prompt : Crcophony::MessagePrompt
@screen : Hydra::TerminalScreen
Expand All @@ -28,6 +29,9 @@ module Crcophony
@screen = Hydra::TerminalScreen.new
@app = Hydra::Application.setup screen: @screen, logger: Logger.new(nil)

# Create a notifier for notifying received messages
@notifier = Notify.new

# Create a parser instance
@parser = Crcophony::MessageParser.new @client.client_id.to_u64, @client.cache.not_nil!, @screen.width

Expand All @@ -52,7 +56,7 @@ module Crcophony
channel_y = (@screen.width.to_f / 2 - (@screen.width / 4 * 3).to_f / 2).floor.to_i
@channel_list = Crcophony::ChannelList.new(@client, "channels", {
:position => "#{channel_x}:#{channel_y}",
:width => "#{@screen.width / 4 * 3}",
:width => "#{@screen.width // 4 * 3}",
:height => "13", # "#{@screen.height / 4 * 3}",
:z_index => "1",
:visible => "false",
Expand All @@ -75,7 +79,7 @@ module Crcophony
# Channel Searching Prompt
@channel_prompt = Crcophony::Searcher.new(@channel_list, "channel_prompt", {
:position => "#{channel_x - 2}:#{channel_y}",
:width => "#{@screen.width / 4 * 3}",
:width => "#{@screen.width // 4 * 3}",
:height => "2",
:z_index => "1",
:visible => "false",
Expand Down Expand Up @@ -133,8 +137,10 @@ module Crcophony
# Handler for receiving a message via the Discord client
# Update the screen if update is true (this flag is used to not update until all messages are loaded in case of changing channel)
def handle_message(message : Discord::Message, update : Bool = true)
# Basic Notification
if message.channel_id == @channel.id
# Notification
@notifier.notify("#{@channel.to_s}", body: "#{message.author.username}: #{message.content}") if (update && message.author.id != @client.client_id)

# First do the various parsing and escaping we need to do
# Then add the message to the logbox
# Get the role for the username colours
Expand All @@ -143,6 +149,8 @@ module Crcophony
@messages.add_message line
end
else
# Notification
@notifier.notify("#{@channel_list.get_channel_name message.channel_id}", body: "#{message.author.username}: #{message.content}") if (update && message.author.id != @client.client_id)
@channel_list.add_unread message.channel_id
# Update the label with the current number of unreads
@channel_name.value = generate_label @channel
Expand Down Expand Up @@ -321,12 +329,12 @@ module Crcophony
# Generate a centered channel name given a server and a channel
private def generate_label(channel : Crcophony::Channel) : String
label = channel.to_s
left_padding = (@screen.width - label.size) / 2
left_padding = (@screen.width - label.size) // 2
right_string = ""
if @channel_list.unread_messages > 0
# Add on a notifications display at the top right
notif_string = "[#{@channel_list.unread_messages}]"
right_padding = (@screen.width - label.size - notif_string.size - 8) / 2
right_padding = (@screen.width - label.size - notif_string.size - 8) // 2
right_string = "#{" " * right_padding}#{notif_string}"
end
return "#{" " * left_padding}#{label}#{right_string}"
Expand Down
6 changes: 4 additions & 2 deletions src/crcophony.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require "logger"
require "./*"

module Crcophony
VERSION = "0.6.0"
VERSION = "0.7.0"

# Load config from the environment
config = Crcophony::Config.new
Expand Down Expand Up @@ -68,7 +68,9 @@ module Crcophony
begin
app.run # => Screen is cleared and the application is displayed
# The application will loop until ctrl-c is pressed or an exception is raised
ensure
app.teardown # => Reset the screen
rescue ex
app.teardown # Teardown first to print stuff after
puts ex.inspect_with_backtrace
end
end

0 comments on commit 4a127bd

Please sign in to comment.