Skip to content

Commit

Permalink
added some major performance optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
salman-abedin committed Dec 6, 2020
1 parent df4f919 commit 8bed1be
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 32 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![](preview.gif)
![](https://gitlab.com/salman-abedin/assets/-/raw/master/tide.gif)

# tide: Minimal Transmission CLI client

Expand All @@ -17,6 +17,7 @@ tide is the successor to [tide.sh](https://github.com/salman-abedin/tide.sh)
## Libraries

- ncurses
- pthread

## Installation

Expand Down Expand Up @@ -58,11 +59,11 @@ git pull --no-rebase && sudo make install
sudo make uninstall
```

## Logs
## Major Revisions

- **27/07/20**:- Added scrolling support
- **15/08/20**:- Rewrote the shellscript in C
- **02/09/20**:- Added remote access patch
- 06/12/20**:- Added some major performancd optimizations

## TODOs

Expand Down
2 changes: 1 addition & 1 deletion config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ CC = cc
CFLAGS = -std=c11 -D_POSIX_C_SOURCE=200809L -Wall -Wextra -pedantic -O2
BIN = src/main

LDLIBS = -s -lncurses
LDLIBS = -s -lncurses -lpthread
NAME = tide
VERSION = 8.0
Binary file removed preview.gif
Binary file not shown.
7 changes: 5 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
* Minimal Transmission CLI client
*/

#include "pthread.h"
#include "ui.h"

int main(void) {
init_ui();
draw_ui();
handle_input();
housekeep();
pthread_t thread_1, thread_2;
pthread_create(&thread_1, NULL, get_torrents, NULL);
pthread_create(&thread_2, NULL, handle_input, NULL);
pthread_exit(NULL);
return 0;
}
57 changes: 35 additions & 22 deletions src/ui.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <ncurses.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "../config.h"
#include "_torrents.h"
Expand All @@ -12,6 +13,21 @@ char cmd_str[1024];
WINDOW* win;
Torrents torrents;

void _draw_torrents() {
torrents = init_cmd(cmd_str);
count = torrents.count - 2;

if (old_count != count) {
old_count = count;
end = count > LINES - 6 ? LINES - 6 : count;
}

if (count > 0)
items = ++torrents.list;
else
items = torrents.list;
}

void init_ui(void) {
initscr();
cbreak();
Expand All @@ -30,6 +46,8 @@ void init_ui(void) {

old_count = init_cmd(cmd_str).count - 2;
end = old_count > LINES - 6 ? LINES - 6 : old_count;

_draw_torrents();
}

void draw_ui(void) {
Expand All @@ -39,20 +57,7 @@ void draw_ui(void) {
keypad(win, true);
}

void _drawitems(void) {
torrents = init_cmd(cmd_str);
count = torrents.count - 2;

if (old_count != count) {
old_count = count;
end = count > LINES - 6 ? LINES - 6 : count;
}

if (count > 0)
items = ++torrents.list;
else
items = torrents.list;

void _draw_items(void) {
werase(win);
box(win, 0, 0);

Expand Down Expand Up @@ -82,6 +87,9 @@ void _drawitems(void) {
wmove(win, LINES - 3, 1);
whline(win, 0, COLS - 2);
mvwaddnstr(win, LINES - 2, 1, count == 0 ? "" : items[count], COLS - 2);

refresh();
wrefresh(win);
}

void _send_args(char* arg) {
Expand All @@ -95,13 +103,9 @@ void _send_args(char* arg) {
}
}

void handle_input(void) {
void* handle_input() {
int key;

halfdelay(10);
while (1) {
_drawitems();
key = wgetch(win);
while ((key = wgetch(win)) != TOR_QUIT) {
if (key == TOR_DOWN) {
if (mark < LINES - 7 && mark < end - 1) {
++mark;
Expand Down Expand Up @@ -134,9 +138,18 @@ void handle_input(void) {
mark = mark > 0 ? mark - 1 : 0;
} else if (key == KEY_RESIZE) {
draw_ui();
} else if (key == TOR_QUIT) {
break;
}
_draw_items();
}
housekeep();
exit(0);
}

void* get_torrents() {
while (1) {
_draw_torrents();
_draw_items();
sleep(1);
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/ui.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#ifndef UI_H
#define UI_H

#define HEADER \
" ID Done Have ETA Up Down Ratio Status " \
"Name"
#define HEADER \
" ID Done Have ETA Up Down Ratio Status " \
"Name"

enum Color_Pairs { Pair_Running = 1, Pair_Stopped, Pair_Completed };

void init_ui(void);
void draw_ui(void);
void handle_input(void);
void* handle_input();
void* get_torrents();
void housekeep(void);

#endif

0 comments on commit 8bed1be

Please sign in to comment.